Checkboxs wont check

Mar 1, 2012 at 5:10pm
Hello I am testing out how to tell when a checkbox is checked.
I have figured out a little bit but what I have isn't working fully
I got it so that when I check one box it checks the others... but when I try to check one of the other boxes it stays the same... anyways here's my code. if you have any other ways of doing this of have an explanation I would be glad for it.

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
LRESULT CALLBACK WindowProcedure (HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
{

    switch (message)                  /* handle the messages */
    {
    case WM_COMMAND :
        if(SendMessage(checkBoxButton[0],BM_GETCHECK,0,0)==BST_CHECKED)
        {
                SendMessage(checkBoxButton[2],BM_SETCHECK,BST_CHECKED,0);
                SendMessage(checkBoxButton[1],BM_SETCHECK,BST_CHECKED,0);
        }
        if(SendMessage(checkBoxButton[0],BM_GETCHECK,0,0)==BST_UNCHECKED)
        {
                SendMessage(checkBoxButton[2],BM_SETCHECK,BST_UNCHECKED,0);
                SendMessage(checkBoxButton[1],BM_SETCHECK,BST_UNCHECKED,0);
        }
    break;
    case WM_CREATE :
            checkBoxButton[0] = CreateWindowEx (WS_EX_TRANSPARENT, TEXT("button"),
                                                __TEXT("Hook Jump"),
                                                WS_CHILD | WS_VISIBLE | BS_AUTOCHECKBOX,
                                                0, 0, 125, 20,
                                                hwnd, NULL,
                                                ((LPCREATESTRUCT) lParam)->hInstance, NULL) ;
            checkBoxButton[1] = CreateWindowEx (WS_EX_TRANSPARENT, TEXT("button"),
                                                __TEXT("Hook Jump 1x1"),
                                                WS_CHILD | WS_VISIBLE | BS_AUTOCHECKBOX,
                                                0, 30, 125, 20,
                                                hwnd, NULL,
                                                ((LPCREATESTRUCT) lParam)->hInstance, NULL);
            checkBoxButton[2] = CreateWindowEx (WS_EX_TRANSPARENT, TEXT("button"),
                                                __TEXT("Dots"),
                                                WS_CHILD | WS_VISIBLE | BS_AUTOCHECKBOX,
                                                0, 60, 125, 20,
                                                hwnd, NULL,
                                                ((LPCREATESTRUCT) lParam)->hInstance, NULL);
            break;
        case WM_DESTROY:
                PostQuitMessage (0);       /* send a WM_QUIT to the message queue */
                break;
            default:                      /* for messages that we don't deal with */
                    return DefWindowProc (hwnd, message, wParam, lParam);
                }

    return 0;
}


Thanks!
Mar 1, 2012 at 5:57pm
My usual disclaimer: I don't do much UI in C++, so I might not be 100% on the money.

I think that your setting of the checkboxes via SendMessage() is triggering WM_COMMAND messages for the other checkboxes. Since your processing of WM_COMMAND doesn't check the control ID, you may be experiencing advese effects.

1
2
3
4
5
6
7
8
case WM_COMMAND:
    if (LOWORD(wParam) == <the control id of the controlling checkbox>)
    {
        DWORD state = SendMessage(checkBoxButton[0], BM_GETCHECK, 0, 0);
        SendMessage(checkBoxButton[2], BM_SETCHECK, state, 0);
        SendMessage(checkBoxButton[1], BM_SETCHECK, state, 0);
    }
    break;

Mar 1, 2012 at 7:59pm
Where do you find the control id or how would you make one?
Mar 1, 2012 at 8:58pm
The first thing I noticed you are doing wrong is not setting the control id of your check box controls. The control id is very important, and is the third parameter from the end of your CreateWindowEx() calls. In your code you are setting them all to NULL.

What you should be doing is specifying at global scope #defines or consts something like this...

#define IDC_CHECKBOX1 1500
#define IDC_CHECKBOX2 1501
#define IDC_CHECKBOX3 1502
etc.

Then, since you will know the parent, i.e., hParent, you can easily get the hWnd of any check box like so...

hWnd = GetDlgItem(hParent,IDC_CHECKBOX2);

To set the check mark to IDC_CHECKBOX2 one would then do this...

SendMessage(hWnd, BM_SETCHECK, BST_CHECKED, 0);

Note in the above, hWnd is the HWND of the check box, as obtained from GetDlgItem() above, not the HWND of the parent or main program window.

To set the check state one sends the BST_CHECKED message as follows...

SendMessage(hWnd,BST_CHECKED,0,0);

Note its not necessary to create an array of HWNDs of the return value for CreateWindowEx() for the check boxes because you can always retrieve their HWNDS from GetDlgItem() as I've shown. This completely eliminates the need for global variables. Under no circumstances is it necessary to have any global variables in GUI Windows programs.

Mar 1, 2012 at 9:02pm
But looking at your code again, what webjose told you is right. Doing what you are doing in the WM_COMMAND is a mistake.

What I'd recommend is putting your code to retrieve the checked/unchecked state of a check box in some other handler such as WM_LBUTTONDOWN or something.
Mar 1, 2012 at 11:09pm
Okay can you explain more on how to set up my checkboxs differently so that I don't have to make a global array.
would I just put them in wm_create so that they are created every time that message is sent?

and also how to check if the checkbox is checked.
Last edited on Mar 1, 2012 at 11:18pm
Mar 1, 2012 at 11:24pm
Here is all my code... I dont know what how to make the if statment... :/

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
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
#include <windows.h>


#define IDC_CHECKBOX1 1500
#define IDC_CHECKBOX2 1501
#define IDC_CHECKBOX3 1502
/*  Declare Windows procedure  */
LRESULT CALLBACK WindowProcedure (HWND, UINT, WPARAM, LPARAM);

/*  Make the class name into a global variable  */
char szClassName[ ] = "EEbot V2";

HWND checkBoxButton[2];
int WINAPI WinMain (HINSTANCE hThisInstance,
                    HINSTANCE hPrevInstance,
                    LPSTR lpszArgument,
                    int nCmdShow)
{
    HWND hwnd;               /* This is the handle for our window */
    MSG messages;            /* Here messages to the application are saved */
    WNDCLASSEX wincl;        /* Data structure for the windowclass */

    /* The Window structure */
    wincl.hInstance = hThisInstance;
    wincl.lpszClassName = szClassName;
    wincl.lpfnWndProc = WindowProcedure;      /* This function is called by windows */
    wincl.style = CS_DBLCLKS;                 /* Catch double-clicks */
    wincl.cbSize = sizeof (WNDCLASSEX);

    /* Use default icon and mouse-pointer */
    wincl.hIcon = LoadIcon (NULL, IDI_APPLICATION);
    wincl.hIconSm = LoadIcon (NULL, IDI_APPLICATION);
    wincl.hCursor = LoadCursor (NULL, IDC_ARROW);
    wincl.lpszMenuName = NULL;                 /* No menu */
    wincl.cbClsExtra = 0;                      /* No extra bytes after the window class */
    wincl.cbWndExtra = 0;                      /* structure or the window instance */
    /* Use Windows's default colour as the background of the window */
    wincl.hbrBackground = (HBRUSH) COLOR_BACKGROUND;

    /* Register the window class, and if it fails quit the program */
    if (!RegisterClassEx (&wincl))
        return 0;

    /* The class is registered, let's create the program*/
    hwnd = CreateWindowEx (
               0,                   /* Extended possibilites for variation */
               szClassName,         /* Classname */
               "EEbot V2",       /* Title Text */
               WS_OVERLAPPEDWINDOW, /* default window */
               CW_USEDEFAULT,       /* Windows decides the position */
               CW_USEDEFAULT,       /* where the window ends up on the screen */
               350,                 /* The programs width */
               250,                 /* and height in pixels */
               HWND_DESKTOP,        /* The window is a child-window to desktop */
               NULL,                /* No menu */
               hThisInstance,       /* Program Instance handler */
               NULL                 /* No Window Creation data */
           );

    /* Make the window visible on the screen */
    ShowWindow (hwnd, nCmdShow);

    /* Run the message loop. It will run until GetMessage() returns 0 */
    while (GetMessage (&messages, NULL, 0, 0))
    {
        /* Translate virtual-key messages into character messages */
        TranslateMessage(&messages);
        /* Send message to WindowProcedure */
        DispatchMessage(&messages);
    }

    /* The program return-value is 0 - The value that PostQuitMessage() gave */
    return messages.wParam;
}


/*  This function is called by the Windows function DispatchMessage()  */

LRESULT CALLBACK WindowProcedure (HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
{

    switch (message)                  /* handle the messages */
    {
    case WM_LBUTTONDOWN :
     HWND hWnd = GetDlgItem(hwnd,IDC_CHECKBOX1);
        if(hWnd==BST_CHECKED)
        {

        }

        break;
    case WM_CREATE :
        checkBoxButton[0] = CreateWindowEx (WS_EX_TRANSPARENT, TEXT("button"),
                                            __TEXT("Hook Jump"),
                                            WS_CHILD | WS_VISIBLE | BS_AUTOCHECKBOX,
                                            0, 0, 125, 20,
                                            hwnd, IDC_CHECKBOX1,
                                            ((LPCREATESTRUCT) lParam)->hInstance, NULL) ;
        checkBoxButton[1] = CreateWindowEx (WS_EX_TRANSPARENT, TEXT("button"),
                                            __TEXT("Hook Jump 1x1"),
                                            WS_CHILD | WS_VISIBLE | BS_AUTOCHECKBOX,
                                            0, 30, 125, 20,
                                            hwnd, IDC_CHECKBOX2,
                                            ((LPCREATESTRUCT) lParam)->hInstance, NULL);
        checkBoxButton[2] = CreateWindowEx (WS_EX_TRANSPARENT, TEXT("button"),
                                            __TEXT("Dots"),
                                            WS_CHILD | WS_VISIBLE | BS_AUTOCHECKBOX,
                                            0, 60, 125, 20,
                                            hwnd, IDC_CHECKBOX3,
                                            ((LPCREATESTRUCT) lParam)->hInstance, NULL);
        break;
    case WM_DESTROY:
        PostQuitMessage (0);       /* send a WM_QUIT to the message queue */
        break;
    default:                      /* for messages that we don't deal with */
        return DefWindowProc (hwnd, message, wParam, lParam);
    }

    return 0;
}
Last edited on Mar 1, 2012 at 11:37pm
Mar 2, 2012 at 12:53pm
I don't think you can get a WM_LBUTTONDOWN message generated FOR the child control (the checkbox) in the parent's window procedure, so I would revert back to handling WM_COMMAND as you originally had it. Assuming your controller checkbox is the one identified by IDC_CHECKBOX1:

1
2
3
4
5
6
7
8
case WM_COMMAND:
    if (LOWORD(wParam) == IDC_CHECKBOX1)
    {
        DWORD state = SendMessage(checkBoxButton[0], BM_GETCHECK, 0, 0);
        SendMessage(checkBoxButton[2], BM_SETCHECK, state, 0);
        SendMessage(checkBoxButton[1], BM_SETCHECK, state, 0);
    }
    break;


It should work OK. Oh, and you can change the checkBoxButton[X] bits with GetDlgItem() as suggested above.
Last edited on Mar 2, 2012 at 12:55pm
Mar 2, 2012 at 3:24pm
Here is an example of what I *think* you need to know:

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
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
#include <windows.h>

#define IDC_CHECKBOX1 1500 // *** these are your control ID's but we will have to assign them to the checkbox windows below... ***
#define IDC_CHECKBOX2 1501 // *** these are your control ID's but we will have to assign them to the checkbox windows below... ***
#define IDC_CHECKBOX3 1502 // *** these are your control ID's but we will have to assign them to the checkbox windows below... ***

LRESULT CALLBACK WindowProcedure (HWND, UINT, WPARAM, LPARAM);

char szClassName[ ] = "EEbot V2";

HINSTANCE hInst;
HWND hCheckBox1, hCheckBox2, hCheckBox3; // *** You could use an array but it's easier to keep track of controls with unique identifiers ***

int WINAPI WinMain (HINSTANCE hThisInstance,
                    HINSTANCE hPrevInstance,
                    LPSTR lpszArgument,
                    int nCmdShow)
{
    hInst = hThisInstance;
    HWND hwnd;
    MSG messages;
    WNDCLASSEX wincl;

    wincl.hInstance = hThisInstance;
    wincl.lpszClassName = szClassName;
    wincl.lpfnWndProc = WindowProcedure;
    wincl.style = CS_DBLCLKS;
    wincl.cbSize = sizeof (WNDCLASSEX);

    wincl.hIcon = LoadIcon (NULL, IDI_APPLICATION);
    wincl.hIconSm = LoadIcon (NULL, IDI_APPLICATION);
    wincl.hCursor = LoadCursor (NULL, IDC_ARROW);
    wincl.lpszMenuName = NULL;
    wincl.cbClsExtra = 0;
    wincl.cbWndExtra = 0;
    wincl.hbrBackground = (HBRUSH) COLOR_BACKGROUND;

    if (!RegisterClassEx (&wincl))
        return 0;

    hwnd = CreateWindowEx (
               0,
               szClassName,
               "EEbot V2",
               WS_OVERLAPPEDWINDOW,
               CW_USEDEFAULT,
               CW_USEDEFAULT,
               350,
               250,
               HWND_DESKTOP,
               NULL,
               hThisInstance,
               NULL
           );

    ShowWindow (hwnd, nCmdShow);

    while (GetMessage (&messages, NULL, 0, 0))
    {
        TranslateMessage(&messages);
        DispatchMessage(&messages);
    }

    return messages.wParam;
}

LRESULT CALLBACK WindowProcedure (HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
{
    switch (message)
    {
    case WM_CREATE :
        hCheckBox1 = CreateWindowEx (WS_EX_TRANSPARENT, TEXT("button"),
                                            __TEXT("Hook Jump"),
                                            WS_CHILD | WS_VISIBLE | BS_AUTOCHECKBOX,
                                            0, 0, 125, 20,
                                            hwnd, 0,
                                            hInst, NULL) ;
        if(hCheckBox1)
        {
          // *** control was created ok, now we set the ID to match our predefined ones ***
          ::SetWindowLong(hCheckBox1,GWL_ID,IDC_CHECKBOX1); // *** set the control ID for CheckBox1 to IDC_CHECKBOX1 ***
        } else {
          // *** control creation failed, deal with it however you need to ***
        }
        hCheckBox2 = CreateWindowEx (WS_EX_TRANSPARENT, TEXT("button"),
                                            __TEXT("Hook Jump 1x1"),
                                            WS_CHILD | WS_VISIBLE | BS_AUTOCHECKBOX,
                                            0, 30, 125, 20,
                                            hwnd, 0,
                                            hInst, NULL);
        if(hCheckBox2)
        {
          // *** control was created ok, now we set the ID to match our predefined ones ***
          ::SetWindowLong(hCheckBox2,GWL_ID,IDC_CHECKBOX2); // *** set the control ID for CheckBox1 to IDC_CHECKBOX1 ***
        } else {
          // *** control creation failed, deal with it however you need to ***
        }
        hCheckBox3 = CreateWindowEx (WS_EX_TRANSPARENT, TEXT("button"),
                                            __TEXT("Dots"),
                                            WS_CHILD | WS_VISIBLE | BS_AUTOCHECKBOX,
                                            0, 60, 125, 20,
                                            hwnd, 0,
                                            hInst, NULL);
        if(hCheckBox3)
        {
          // *** control was created ok, now we set the ID to match our predefined ones ***
          ::SetWindowLong(hCheckBox3,GWL_ID,IDC_CHECKBOX3); // *** set the control ID for CheckBox1 to IDC_CHECKBOX1 ***
        } else {
          // *** control creation failed, deal with it however you need to ***
        }
        break;
    case WM_COMMAND:
    {
      switch(LOWORD(wParam)) // *** Tells us which control ID sent a message ***
      {
        case IDC_CHECKBOX1: // *** user clicked box 1 ***
        {
          if(SendMessage(GetDlgItem(hwnd,IDC_CHECKBOX1),BM_GETCHECK,0,0) == BST_CHECKED)
          {
            MessageBox(hwnd,"Box is checked","You clicked CheckBox \"Hook Jump\"",0);
          } else {
            MessageBox(hwnd,"Box is unchecked","You clicked CheckBox \"Hook Jump\"",0);
          }
        } break;
        case IDC_CHECKBOX2: // *** user clicked box 2 ***
        {
          if(SendMessage(GetDlgItem(hwnd,IDC_CHECKBOX2),BM_GETCHECK,0,0) == BST_CHECKED)
          {
            MessageBox(hwnd,"Box is checked","You clicked CheckBox \"Hook Jump 1x1\"",0);
          } else {
            MessageBox(hwnd,"Box is unchecked","You clicked CheckBox \"Hook Jump 1x1\"",0);
          }
        } break;
        case IDC_CHECKBOX3: // *** user clicked box 3 ***
        {
          if(SendMessage(GetDlgItem(hwnd,IDC_CHECKBOX3),BM_GETCHECK,0,0) == BST_CHECKED)
          {
            MessageBox(hwnd,"Box is checked","You clicked CheckBox \"Dots\"",0);
          } else {
            MessageBox(hwnd,"Box is unchecked","You clicked CheckBox \"Dots\"",0);
          }
        } break;
      }
    } break;
    case WM_DESTROY:
        PostQuitMessage (0);
        break;
    default:
        return DefWindowProc (hwnd, message, wParam, lParam);
    }
    return 0;
}
Mar 2, 2012 at 4:26pm
Here's a program for you that creates three check boxes and a button on the form. In the lower part of the form is displayed the check box state of each individual check box. When you check or uncheck a box push the button to the right to retrieve and display each check box state. Note there are no global variables.

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
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
//Main.cpp
#include <windows.h>
#include <tchar.h>
#include <cstdio>
#include "Form1.h"


long fnWndProc_OnCreate(lpWndEventArgs Wea)
{
 HWND hCtl;

 Wea->hIns=((LPCREATESTRUCT)Wea->lParam)->hInstance;
 hCtl=CreateWindow(_T("button"),_T("Check Box #1"),WS_CHILD|WS_VISIBLE|BS_AUTOCHECKBOX,50,25,150,25,Wea->hWnd,(HMENU)IDC_CHECKBOX1,Wea->hIns,0);
 hCtl=CreateWindow(_T("button"),_T("Check Box #2"),WS_CHILD|WS_VISIBLE|BS_AUTOCHECKBOX,50,60,150,25,Wea->hWnd,(HMENU)IDC_CHECKBOX2,Wea->hIns,0);
 hCtl=CreateWindow(_T("button"),_T("Check Box #3"),WS_CHILD|WS_VISIBLE|BS_AUTOCHECKBOX,50,95,150,25,Wea->hWnd,(HMENU)IDC_CHECKBOX3,Wea->hIns,0);
 hCtl=CreateWindow(_T("button"),_T("Get States"),WS_CHILD|WS_VISIBLE,200,25,100,100,Wea->hWnd,(HMENU)IDC_BUTTON,Wea->hIns,0);

 return 0;
}


long fnWndProc_OnCommand(lpWndEventArgs Wea)
{
 switch(LOWORD(Wea->wParam))
 {
   case IDC_BUTTON:
     {
        if(HIWORD(Wea->wParam)==BN_CLICKED)
           InvalidateRect(Wea->hWnd,0,TRUE);
        break;
     }
 }

 return 0;
}


long fnWndProc_OnPaint(lpWndEventArgs Wea)
{
 TCHAR szBuffer[128];
 PAINTSTRUCT ps;
 int iReturn;
 HDC hDC;

 hDC=BeginPaint(Wea->hWnd,&ps);
 SetBkMode(hDC,TRANSPARENT);
 iReturn=SendMessage(GetDlgItem(Wea->hWnd,IDC_CHECKBOX1),BM_GETCHECK,0,0);
 if(iReturn==BST_CHECKED)
    _stprintf(szBuffer,_T("Check Box #1 Is Checked!"));
 else
    _stprintf(szBuffer,_T("Check Box #1 Is Unchecked!"));
 TextOut(hDC,60,175,szBuffer,_tcslen(szBuffer));
 iReturn=SendMessage(GetDlgItem(Wea->hWnd,IDC_CHECKBOX2),BM_GETCHECK,0,0);
 if(iReturn==BST_CHECKED)
    _stprintf(szBuffer,_T("Check Box #2 Is Checked!"));
 else
    _stprintf(szBuffer,_T("Check Box #2 Is Unchecked!"));
 TextOut(hDC,60,200,szBuffer,_tcslen(szBuffer));

 iReturn=SendMessage(GetDlgItem(Wea->hWnd,IDC_CHECKBOX3),BM_GETCHECK,0,0);
 if(iReturn==BST_CHECKED)
    _stprintf(szBuffer,_T("Check Box #3 Is Checked!"));
 else
    _stprintf(szBuffer,_T("Check Box #3 Is Unchecked!"));
 TextOut(hDC,60,225,szBuffer,_tcslen(szBuffer));
 EndPaint(Wea->hWnd,&ps);

 return 0;
}

long fnWndProc_OnDestroy(lpWndEventArgs Wea)
{
 PostQuitMessage(0);
 return 0;
}


LRESULT CALLBACK fnWndProc(HWND hwnd, unsigned int msg, WPARAM wParam, LPARAM lParam)
{
 WndEventArgs Wea;

 for(unsigned int i=0; i<dim(EventHandler); i++)
 {
     if(EventHandler[i].iMsg==msg)
     {
        Wea.hWnd=hwnd, Wea.lParam=lParam, Wea.wParam=wParam;
        return (*EventHandler[i].fnPtr)(&Wea);
     }
 }

 return (DefWindowProc(hwnd, msg, wParam, lParam));
}


int WINAPI WinMain(HINSTANCE hIns, HINSTANCE hPrevIns, LPSTR lpszArgument, int iShow)
{
 TCHAR szClassName[]=_T("Form1");
 WNDCLASSEX wc;
 MSG messages;
 HWND hWnd;

 wc.lpszClassName=szClassName;                wc.lpfnWndProc=fnWndProc;
 wc.cbSize=sizeof (WNDCLASSEX);               wc.style=CS_DBLCLKS;
 wc.hIcon=LoadIcon(NULL,IDI_APPLICATION);     wc.hInstance=hIns;
 wc.hIconSm=LoadIcon(NULL, IDI_APPLICATION);  wc.hCursor=LoadCursor(NULL,IDC_ARROW);
 wc.hbrBackground=(HBRUSH)COLOR_BTNSHADOW;    wc.cbWndExtra=0;
 wc.lpszMenuName=NULL;                        wc.cbClsExtra=0;
 RegisterClassEx(&wc);
 hWnd=CreateWindowEx(0,szClassName,szClassName,WS_OVERLAPPEDWINDOW,75,75,320,305,HWND_DESKTOP,0,hIns,0);
 ShowWindow(hWnd,iShow);
 while(GetMessage(&messages,NULL,0,0))
 {
    TranslateMessage(&messages);
    DispatchMessage(&messages);
 }

 return messages.wParam;
}


//header
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
//Main.h
#ifndef Main_h
#define Main_h

#define dim(x) (sizeof(x) / sizeof(x[0]))

struct WndEventArgs
{
 HWND                         hWnd;
 WPARAM                       wParam;
 LPARAM                       lParam;
 HINSTANCE                    hIns;
};

typedef WndEventArgs*         lpWndEventArgs;

long fnWndProc_OnCreate       (lpWndEventArgs Wea);
long fnWndProc_OnCommand      (lpWndEventArgs Wea);
long fnWndProc_OnPaint        (lpWndEventArgs Wea);
long fnWndProc_OnDestroy      (lpWndEventArgs Wea);

struct EVENTHANDLER
{
 unsigned int                 iMsg;
 long                         (*fnPtr)(lpWndEventArgs);
};

const EVENTHANDLER EventHandler[]=
{
 {WM_CREATE,                  fnWndProc_OnCreate},
 {WM_COMMAND,                 fnWndProc_OnCommand},
 {WM_PAINT,                   fnWndProc_OnPaint},
 {WM_DESTROY,                 fnWndProc_OnDestroy}
};

#define IDC_CHECKBOX1         1500
#define IDC_CHECKBOX2         1501
#define IDC_CHECKBOX3         1502
#define IDC_BUTTON            1505
#endif 


Let me know if anything doesn't work.
Mar 2, 2012 at 6:19pm
Thanks you guys for the help.. it is greatly appreciated and helps me understand c++ better... one question for you texan40, why didn't you just put the window id's when you were creating the check-boxs? is this just good coding or maybe is it to prevent bugs? Also thanks freddie1 but I went with Texan40s approach.. it made more sense to me.
Last edited on Mar 2, 2012 at 6:24pm
Mar 2, 2012 at 7:42pm
I have to say I just plain forgot that you could pass in the ID through the HMENU parameter. That would be the way to go surely.
Topic archived. No new replies allowed.