Need this code explained

Pages: 12
I already did and it gave me a bunch of Visual Basic stuff. How is it this effing hard to put a check in a box? I dont get it. I asked on another forum and i get these long huge complicated codes to do god knows what. Its a check... in a box, i already have the box, just need the check. I cant grasp how its this difficult. It should be something like BST_Checked or something I dont know. or BM_SETCHECK. I tried both but they dont work. Or maybe they do and im doing it wrong. someone PLEASE help me im so frustrated right now.
The link I gave you has all you need to know!

//create the checkbox


1
2
HWND txt = CreateWindowEx( 0,"BUTTON","Check and uncheck me",BS_AUTOCHECKBOX | WS_VISIBLE | S_CHILD,
		          10,50,170,25,myDialog,(HMENU)checkbox_id,NULL,NULL );


Is shows you how to create the checkbox with BS_AUTOCHECKBOX, I presume this makes it so that you can check and uncheck it.

It also shows you have to perform actions on whether or not the box is checked.
Is there a simpler way to do it than that line of code you just gave me?

Now i get errors, what am i doing wrong?

Errors:

C:\Users\Chay Hawk\Desktop\Project Manager\main.cpp||In function 'BOOL DialogProc(HWND__*, UINT, WPARAM, LPARAM)':|
C:\Users\Chay Hawk\Desktop\Project Manager\main.cpp|50|error: 'S_CHILD' was not declared in this scope|
C:\Users\Chay Hawk\Desktop\Project Manager\main.cpp|50|error: 'myDialog' was not declared in this scope|
C:\Users\Chay Hawk\Desktop\Project Manager\main.cpp|50|error: 'checkbox_id' was not declared in this scope|
C:\Users\Chay Hawk\Desktop\Project Manager\main.cpp|50|warning: unused variable 'txt'|
||=== Build finished: 3 errors, 1 warnings ===|


Code:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
#define WIN32_LEAN_AND_MEAN
#define _WIN32_WINNT 0x0500
#include <windows.h>
#include "resource.h"


HINSTANCE hInst;

BOOL CALLBACK DialogProc(HWND hwndDlg, UINT uMsg, WPARAM wParam, LPARAM lParam)
{

    switch(uMsg)
    {
        case WM_INITDIALOG:
            //Blank
            return TRUE;

        case WM_CLOSE: // If the user clicks the X to close the dialog box
            EndDialog(hwndDlg, 0);
            return TRUE;

        case WM_COMMAND:
            switch(LOWORD(wParam))
            {
                case IDC_BTN_QUIT:
                    EndDialog(hwndDlg, 0);
                    return TRUE;

                ////////////////////////////////////////////////////////////////////////////////////////////////////////////////
                //MB_ICONINFORMATION is the type of icon displayed in the window that pops up. There is also//
                //MB_ICONHAND, MB_ICONSTOP, or MB_ICONERROR - Error Icon                                           //
                //MB_ICONQUESTION - Question mark Icon                                                                          //
                //MB_ICONEXCLAMATION or MB_ICONWARNING - Exclamation Icon                                       //
                //MB_ICONASTERISK or MB_ICONINFORMATION - Asterisk Icon                                            //
                /////////////////////////////////////////////////////////////////////////////////////////////////////////////

                case IDC_BTN_TEST:
                    MessageBox(hwndDlg, "Your computer will now crash because you suck.", "Information", MB_ICONERROR);
                    return TRUE;

                case IDC_BTN_TESTBTN2:
                    MessageBox(hwndDlg, "Rated Argh for pirates fuck you.", "Information", MB_ICONWARNING);
                    return TRUE;

                case Button:
                    MessageBox(hwndDlg, "Test Button 2", "Information", MB_ICONINFORMATION);
                    return TRUE;

                case CheckB:
                        HWND txt = CreateWindowEx( 0,"BUTTON","Check and uncheck me",BS_AUTOCHECKBOX | WS_VISIBLE | S_CHILD, 10,50,170,25, myDialog,(HMENU)checkbox_id,NULL,NULL );

                        return TRUE;
            }
    }

    return FALSE;
}


int APIENTRY WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nShowCmd)
{
    hInst = hInstance;

    // The user interface is a modal dialog box
    return DialogBox(hInstance, MAKEINTRESOURCE(DLG_MAIN), NULL, (DLGPROC)DialogProc);
}
Last edited on
1. you didn't register dialog class
2. you didn't set getMessage function as well as dispatchMeassage and others...

http://msdn.microsoft.com/en-us/library/ff381409(v=vs.85).aspx
screw it then. I dont care anymore. :(
Last edited on
Yeah, COM is hard to learn.

aniway I won't give up as you did :D
Im not giving up im just pissed off. I mean what the hell, it was one word to create the damn thing and now its 40 to make it check and uncheck, WTF.
Can someone just edit my code and make it work, if i see it working i'll understand it better. This program really isnt supposed to be a useable program, im just putting all this stuff in there and learning it, then making comments on everything so i dont forgt and to help me learn.
Last edited on
Ch1156,
sorry but I thnk you have wrong approach to learn COM, that way you just harassing your self :/

I've started learning on this link step by step:
http://msdn.microsoft.com/en-us/library/ff381398(v=vs.85).aspx

it could take some while to learn all that stuff but I found it usefol, hope you will to! :D
Thats how i have been doing it since i started programming and its worked for me so far. Can you please make the code work with the checkbox and put comments next to the edited code? I know you might think that having me find it and do it myself would help me learn but that isnt the case, If i see the code in the program and its working, what i do is i write programs over and over again using that code, and while i do that i learn the syntax. Thats the easiest way to learn for me. So if i have buttons and radio buttons and checkboxes in my program here, i will write a different program using just checkboxes, and one with just radio buttons, and one with just buttons, and one with all of them. I will look over that tutorial you gave me but this checkbox thing is really getting to me and i cant concentrate on other things when something like that is getting to me.
Last edited on
Post Bump Please help.
Friend of mine is in the process of writing a tutorial on all this. He's very good with C++ and generally will answer any question you have if you're polite :D
learnwinapi.wordpress.com
I book marked the site but as i stated in my last post that doesnt help me all that much. I need to see MY code working, seeing all this other code only confuses me, seeing it structured in there program is confusing because im used to my structure so seeing theirs only makes my confusion worse. So to re-instate my question:

Can someone please make the code work with the checkbox and put comments next to the edited code? I know you might think that having me find it and do it myself would help me learn but that isnt the case, If i see the code in the program and its working, what i do is i write programs over and over again using that code, and while i do that i learn the syntax. Thats the easiest way to learn for me. So if i have buttons and radio buttons and checkboxes in my program here, i will write a different program using just checkboxes, and one with just radio buttons, and one with just buttons, and one with all of them. I will look over that tutorial you gave me but this checkbox thing is really getting to me and i cant concentrate on other things when something like that is getting to me.
Last edited on
Can someone please help me this is really getting to me now.
Please help
Please Help!!!!
Topic archived. No new replies allowed.
Pages: 12