win32 Radio button doesn't show when is checked
-
Hi, I am covering a book tutorial about programming win32 and when I am compiling the code provided, radio buttons doesn't show when are checked, instead the checkbox that is in the same dialog window shows when it is checked. I will attach the code if you can help me: resource code:
TESTDIALOG DIALOG DISCARDABLE 20, 20, 180, 70
STYLE DS_MODALFRAME | WS_POPUP | WS_VISIBLE | WS_CAPTION | WS_SYSMENU
CAPTION "Test Dialog"
FONT 8, "MS Sans Serif"
BEGIN
CHECKBOX "Check box control.",IDC_CHECKBOX,9,7,70,10
GROUPBOX "Radio Buttons",-1,7,21,86,39
RADIOBUTTON "First", IDC_RADIO1,13,32,37,10,WS_GROUP | WS_TABSTOP
RADIOBUTTON "Second",IDC_RADIO2,13,45,39,10
PUSHBUTTON "Done",IDCANCEL,116,8,50,14,WS_GROUP
ENDcpp code:
LRESULT CALLBACK WndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
{
int wmId, wmEvent;
PAINTSTRUCT ps;
HDC hdc;switch (message) { case WM\_COMMAND: wmId = LOWORD(wParam); wmEvent = HIWORD(wParam); // Parse the menu selections: switch (wmId) { case ID\_FILE\_TEST: // adaugat de mine // ShowWindow(hWnd,SW\_SHOWMAXIMIZED); // maximizeaza fereastra if ( !hDlgModeless ) hDlgModeless = CreateDialog( hInst, MAKEINTRESOURCE(32767), hWnd, (DLGPROC)TestDlgProc ); break; case IDM\_ABOUT: DialogBox(hInst, MAKEINTRESOURCE(IDD\_ABOUTBOX), hWnd, About); break; case IDM\_EXIT: DestroyWindow(hWnd); break; default: return DefWindowProc(hWnd, message, wParam, lParam); } break; case WM\_PAINT: hdc = BeginPaint(hWnd, &ps); // TODO: Add any drawing code here... EndPaint(hWnd, &ps); break; case WM\_DESTROY: PostQuitMessage(0); break; default: return DefWindowProc(hWnd, message, wParam, lParam); } return 0;
}
LRESULT CALLBACK TestDlgProc(HWND hDlg, UINT uMsg, WPARAM wParam, LPARAM lParam)
{
switch (uMsg)
{
// Initially set the check box
// and radio button states.
//...........................
case WM_INITDIALOG:
CheckDlgButton(hDlg,IDC_CHECKBOX, bChecked ? MF_CHECKED : MF_UNCHECKED);
CheckRadioButton(hDlg,IDC_RADIO1,IDC_RADIO2,bRadio1 ? IDC_RADIO1 : IDC_RADIO2);
break;
case WM_COMMAND:
switch( LOWORD(wParam))
{
case IDC_CHECKBOX:
bChecked=!IsDlgButtonChecked(hDlg,IDC_CHECKBOX);
CheckDlgButton(hDlg,IDC_CHECKBOX, bChecked ? MF_CHECKED : MF_UNCHEC -
Hi, I am covering a book tutorial about programming win32 and when I am compiling the code provided, radio buttons doesn't show when are checked, instead the checkbox that is in the same dialog window shows when it is checked. I will attach the code if you can help me: resource code:
TESTDIALOG DIALOG DISCARDABLE 20, 20, 180, 70
STYLE DS_MODALFRAME | WS_POPUP | WS_VISIBLE | WS_CAPTION | WS_SYSMENU
CAPTION "Test Dialog"
FONT 8, "MS Sans Serif"
BEGIN
CHECKBOX "Check box control.",IDC_CHECKBOX,9,7,70,10
GROUPBOX "Radio Buttons",-1,7,21,86,39
RADIOBUTTON "First", IDC_RADIO1,13,32,37,10,WS_GROUP | WS_TABSTOP
RADIOBUTTON "Second",IDC_RADIO2,13,45,39,10
PUSHBUTTON "Done",IDCANCEL,116,8,50,14,WS_GROUP
ENDcpp code:
LRESULT CALLBACK WndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
{
int wmId, wmEvent;
PAINTSTRUCT ps;
HDC hdc;switch (message) { case WM\_COMMAND: wmId = LOWORD(wParam); wmEvent = HIWORD(wParam); // Parse the menu selections: switch (wmId) { case ID\_FILE\_TEST: // adaugat de mine // ShowWindow(hWnd,SW\_SHOWMAXIMIZED); // maximizeaza fereastra if ( !hDlgModeless ) hDlgModeless = CreateDialog( hInst, MAKEINTRESOURCE(32767), hWnd, (DLGPROC)TestDlgProc ); break; case IDM\_ABOUT: DialogBox(hInst, MAKEINTRESOURCE(IDD\_ABOUTBOX), hWnd, About); break; case IDM\_EXIT: DestroyWindow(hWnd); break; default: return DefWindowProc(hWnd, message, wParam, lParam); } break; case WM\_PAINT: hdc = BeginPaint(hWnd, &ps); // TODO: Add any drawing code here... EndPaint(hWnd, &ps); break; case WM\_DESTROY: PostQuitMessage(0); break; default: return DefWindowProc(hWnd, message, wParam, lParam); } return 0;
}
LRESULT CALLBACK TestDlgProc(HWND hDlg, UINT uMsg, WPARAM wParam, LPARAM lParam)
{
switch (uMsg)
{
// Initially set the check box
// and radio button states.
//...........................
case WM_INITDIALOG:
CheckDlgButton(hDlg,IDC_CHECKBOX, bChecked ? MF_CHECKED : MF_UNCHECKED);
CheckRadioButton(hDlg,IDC_RADIO1,IDC_RADIO2,bRadio1 ? IDC_RADIO1 : IDC_RADIO2);
break;
case WM_COMMAND:
switch( LOWORD(wParam))
{
case IDC_CHECKBOX:
bChecked=!IsDlgButtonChecked(hDlg,IDC_CHECKBOX);
CheckDlgButton(hDlg,IDC_CHECKBOX, bChecked ? MF_CHECKED : MF_UNCHECDid you debug this code? Is this code:
case IDC_CHECKBOX:
bChecked=!IsDlgButtonChecked(hDlg,IDC_CHECKBOX);
CheckDlgButton(hDlg,IDC_CHECKBOX, bChecked ? MF_CHECKED : MF_UNCHECKED);executed? Is this code:
case IDC_RADIO1:
bRadio1=TRUE;
CheckRadioButton(hDlg,IDC_RADIO1,IDC_RADIO2, IDC_RADIO1);
break;executed?
-
Did you debug this code? Is this code:
case IDC_CHECKBOX:
bChecked=!IsDlgButtonChecked(hDlg,IDC_CHECKBOX);
CheckDlgButton(hDlg,IDC_CHECKBOX, bChecked ? MF_CHECKED : MF_UNCHECKED);executed? Is this code:
case IDC_RADIO1:
bRadio1=TRUE;
CheckRadioButton(hDlg,IDC_RADIO1,IDC_RADIO2, IDC_RADIO1);
break;executed?
Yes, I attached a link to the result, but how I sayed, when I check the radio box nothing happens: Dialog-Box — imgbb.com[^] The checkbox instead is ok: Dialog-Box1 — imgbb.com[^] [url=https://imgbb.com/\][img]https://i.ibb.co/SBV51Bm/Dialog-Box1.jpg\[/img\]\[/url\]
-
Yes, I attached a link to the result, but how I sayed, when I check the radio box nothing happens: Dialog-Box — imgbb.com[^] The checkbox instead is ok: Dialog-Box1 — imgbb.com[^] [url=https://imgbb.com/\][img]https://i.ibb.co/SBV51Bm/Dialog-Box1.jpg\[/img\]\[/url\]
Again: did you set a break point to one of these lines:
case IDC_RADIO1:
bRadio1=TRUE;
CheckRadioButton(hDlg,IDC_RADIO1,IDC_RADIO2, IDC_RADIO1);
break;and was sure that this
CheckRadioButton(hDlg,IDC_RADIO1,IDC_RADIO2, IDC_RADIO1);
has been executed?
-
Again: did you set a break point to one of these lines:
case IDC_RADIO1:
bRadio1=TRUE;
CheckRadioButton(hDlg,IDC_RADIO1,IDC_RADIO2, IDC_RADIO1);
break;and was sure that this
CheckRadioButton(hDlg,IDC_RADIO1,IDC_RADIO2, IDC_RADIO1);
has been executed?
Yes, I had placed a brakepoint after the CheckRadioButton RADIO1 function at the "break" statement. When I press the Radio1 radio button the program goes and stops at the breakpoint, but what I had observed is that when a press play again to the compiler the program continues to execute and then it's comes back at the break point without to press again the radio button. Thanks,
-
Yes, I had placed a brakepoint after the CheckRadioButton RADIO1 function at the "break" statement. When I press the Radio1 radio button the program goes and stops at the breakpoint, but what I had observed is that when a press play again to the compiler the program continues to execute and then it's comes back at the break point without to press again the radio button. Thanks,
-
Hi, I am covering a book tutorial about programming win32 and when I am compiling the code provided, radio buttons doesn't show when are checked, instead the checkbox that is in the same dialog window shows when it is checked. I will attach the code if you can help me: resource code:
TESTDIALOG DIALOG DISCARDABLE 20, 20, 180, 70
STYLE DS_MODALFRAME | WS_POPUP | WS_VISIBLE | WS_CAPTION | WS_SYSMENU
CAPTION "Test Dialog"
FONT 8, "MS Sans Serif"
BEGIN
CHECKBOX "Check box control.",IDC_CHECKBOX,9,7,70,10
GROUPBOX "Radio Buttons",-1,7,21,86,39
RADIOBUTTON "First", IDC_RADIO1,13,32,37,10,WS_GROUP | WS_TABSTOP
RADIOBUTTON "Second",IDC_RADIO2,13,45,39,10
PUSHBUTTON "Done",IDCANCEL,116,8,50,14,WS_GROUP
ENDcpp code:
LRESULT CALLBACK WndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
{
int wmId, wmEvent;
PAINTSTRUCT ps;
HDC hdc;switch (message) { case WM\_COMMAND: wmId = LOWORD(wParam); wmEvent = HIWORD(wParam); // Parse the menu selections: switch (wmId) { case ID\_FILE\_TEST: // adaugat de mine // ShowWindow(hWnd,SW\_SHOWMAXIMIZED); // maximizeaza fereastra if ( !hDlgModeless ) hDlgModeless = CreateDialog( hInst, MAKEINTRESOURCE(32767), hWnd, (DLGPROC)TestDlgProc ); break; case IDM\_ABOUT: DialogBox(hInst, MAKEINTRESOURCE(IDD\_ABOUTBOX), hWnd, About); break; case IDM\_EXIT: DestroyWindow(hWnd); break; default: return DefWindowProc(hWnd, message, wParam, lParam); } break; case WM\_PAINT: hdc = BeginPaint(hWnd, &ps); // TODO: Add any drawing code here... EndPaint(hWnd, &ps); break; case WM\_DESTROY: PostQuitMessage(0); break; default: return DefWindowProc(hWnd, message, wParam, lParam); } return 0;
}
LRESULT CALLBACK TestDlgProc(HWND hDlg, UINT uMsg, WPARAM wParam, LPARAM lParam)
{
switch (uMsg)
{
// Initially set the check box
// and radio button states.
//...........................
case WM_INITDIALOG:
CheckDlgButton(hDlg,IDC_CHECKBOX, bChecked ? MF_CHECKED : MF_UNCHECKED);
CheckRadioButton(hDlg,IDC_RADIO1,IDC_RADIO2,bRadio1 ? IDC_RADIO1 : IDC_RADIO2);
break;
case WM_COMMAND:
switch( LOWORD(wParam))
{
case IDC_CHECKBOX:
bChecked=!IsDlgButtonChecked(hDlg,IDC_CHECKBOX);
CheckDlgButton(hDlg,IDC_CHECKBOX, bChecked ? MF_CHECKED : MF_UNCHEC -
Hi, I am covering a book tutorial about programming win32 and when I am compiling the code provided, radio buttons doesn't show when are checked, instead the checkbox that is in the same dialog window shows when it is checked. I will attach the code if you can help me: resource code:
TESTDIALOG DIALOG DISCARDABLE 20, 20, 180, 70
STYLE DS_MODALFRAME | WS_POPUP | WS_VISIBLE | WS_CAPTION | WS_SYSMENU
CAPTION "Test Dialog"
FONT 8, "MS Sans Serif"
BEGIN
CHECKBOX "Check box control.",IDC_CHECKBOX,9,7,70,10
GROUPBOX "Radio Buttons",-1,7,21,86,39
RADIOBUTTON "First", IDC_RADIO1,13,32,37,10,WS_GROUP | WS_TABSTOP
RADIOBUTTON "Second",IDC_RADIO2,13,45,39,10
PUSHBUTTON "Done",IDCANCEL,116,8,50,14,WS_GROUP
ENDcpp code:
LRESULT CALLBACK WndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
{
int wmId, wmEvent;
PAINTSTRUCT ps;
HDC hdc;switch (message) { case WM\_COMMAND: wmId = LOWORD(wParam); wmEvent = HIWORD(wParam); // Parse the menu selections: switch (wmId) { case ID\_FILE\_TEST: // adaugat de mine // ShowWindow(hWnd,SW\_SHOWMAXIMIZED); // maximizeaza fereastra if ( !hDlgModeless ) hDlgModeless = CreateDialog( hInst, MAKEINTRESOURCE(32767), hWnd, (DLGPROC)TestDlgProc ); break; case IDM\_ABOUT: DialogBox(hInst, MAKEINTRESOURCE(IDD\_ABOUTBOX), hWnd, About); break; case IDM\_EXIT: DestroyWindow(hWnd); break; default: return DefWindowProc(hWnd, message, wParam, lParam); } break; case WM\_PAINT: hdc = BeginPaint(hWnd, &ps); // TODO: Add any drawing code here... EndPaint(hWnd, &ps); break; case WM\_DESTROY: PostQuitMessage(0); break; default: return DefWindowProc(hWnd, message, wParam, lParam); } return 0;
}
LRESULT CALLBACK TestDlgProc(HWND hDlg, UINT uMsg, WPARAM wParam, LPARAM lParam)
{
switch (uMsg)
{
// Initially set the check box
// and radio button states.
//...........................
case WM_INITDIALOG:
CheckDlgButton(hDlg,IDC_CHECKBOX, bChecked ? MF_CHECKED : MF_UNCHECKED);
CheckRadioButton(hDlg,IDC_RADIO1,IDC_RADIO2,bRadio1 ? IDC_RADIO1 : IDC_RADIO2);
break;
case WM_COMMAND:
switch( LOWORD(wParam))
{
case IDC_CHECKBOX:
bChecked=!IsDlgButtonChecked(hDlg,IDC_CHECKBOX);
CheckDlgButton(hDlg,IDC_CHECKBOX, bChecked ? MF_CHECKED : MF_UNCHECIn addition what was said before, I suggest you add a default case for the inner switch in WM_COMMAND. Then set a breakpoint on that default. Maybe you're missing a case in that switch statement?
GOTOs are a bit like wire coat hangers: they tend to breed in the darkness, such that where there once were few, eventually there are many, and the program's architecture collapses beneath them. (Fran Poretto)
-
Check in Resource.h file to see if those two radio buttons has consecutive values ... might be a problem if they are not.
_Flaviu wrote:
Check in Resource.h file to see if those two radio buttons has consecutive values ... might be a problem if they are not.
Yes, that it was, in the resource.h the values of the radio butons were reversed, first it was Radio2 then Radio1. I putted their correspondent values in increasing order and problem was solved. Many thank Flaviu
-
_Flaviu wrote:
Check in Resource.h file to see if those two radio buttons has consecutive values ... might be a problem if they are not.
Yes, that it was, in the resource.h the values of the radio butons were reversed, first it was Radio2 then Radio1. I putted their correspondent values in increasing order and problem was solved. Many thank Flaviu