I am trying to write a program in c++ win32 in which i need to have multiple check boxes. To be more specific, this program has multiple "pages" (after the user clicks the next button i delete any child windows and replace them with new ones). So, to keep the code understandable, i need a function that when is called brings up a couple of fields (i know how to handle those) and some check boxes. The problem is that i don't know how to manage the HWND for each one and so any box i click just runs the same code (and does not check any of the boxes). MSDN does not offer much help and the only source of information i found was this how to make checkbox in win32? This is the part in my code in which the problem arrives.
/* checked_box1 , checked_box2 are globals */
LRESULT CALLBACK WindowProcedure (HWND hwnd, UINT message, WPARAM wParam,
LPARAM lParam)
{
switch (message)
{
case WM_CREATE:
draw_obtions_screen(hwnd);
break;
case WM_COMMAND:
checked_box1 = IsDlgButtonChecked(draw_object, 1);
if (checked_box1) {
CheckDlgButton(hwnd, 1, BST_UNCHECKED);
SetWindowText(hwnd, TEXT("y"));
} else {
CheckDlgButton(hwnd, 1, BST_CHECKED);
SetWindowText(hwnd,"x");
}
checked_box2 = IsDlgButtonChecked(draw_object1, 1);
if (checked_box2) {
CheckDlgButton(hwnd, 1, BST_UNCHECKED);
SetWindowText(hwnd, TEXT("Y"));
} else {
CheckDlgButton(hwnd, 1, BST_CHECKED);
SetWindowText(hwnd,"X");
}
case WM_DESTROY:
PostQuitMessage (0);
break;
default:
return DefWindowProc (hwnd, message, wParam, lParam);
}
return 0;
}
......
/* HWND draw_object,draw_object1 are global. The function is also prev declared*/
void draw_obtions_screen(HWND hwnd)
{
draw_object = CreateWindow ("BUTTON","check",
WS_VISIBLE | WS_CHILD | BS_CHECKBOX,
110, 10 ,100 ,30,
hwnd, NULL,NULL,NULL);
CheckDlgButton(hwnd, 1, BST_CHECKED);
draw_object1 = CreateWindow ("BUTTON","check another",
WS_VISIBLE | WS_CHILD | BS_CHECKBOX,
110, 60 ,130 ,30,
hwnd, NULL,NULL,NULL);
CheckDlgButton(hwnd, 1, BST_UNCHECKED);
}
The code changes the title of the window to "X" (on any box i click) and then nothing.
I will apreciate any kind of information source or answer. Also please leave some information sources for me to further learn. Thanks!
Aucun commentaire:
Enregistrer un commentaire