Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C / C++ / MFC
  4. win32 Radio button doesn't show when is checked

win32 Radio button doesn't show when is checked

Scheduled Pinned Locked Moved C / C++ / MFC
learningc++graphicshelptutorial
10 Posts 5 Posters 1 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • C Offline
    C Offline
    coco243
    wrote on last edited by
    #1

    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
    END

    cpp 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

    V L S 3 Replies Last reply
    0
    • C coco243

      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
      END

      cpp 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

      V Offline
      V Offline
      Victor Nijegorodov
      wrote on last edited by
      #2

      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?

      C 1 Reply Last reply
      0
      • V Victor Nijegorodov

        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?

        C Offline
        C Offline
        coco243
        wrote on last edited by
        #3

        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\]

        V 1 Reply Last reply
        0
        • C coco243

          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\]

          V Offline
          V Offline
          Victor Nijegorodov
          wrote on last edited by
          #4

          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?

          C 1 Reply Last reply
          0
          • V Victor Nijegorodov

            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?

            C Offline
            C Offline
            coco243
            wrote on last edited by
            #5

            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,

            _ 1 Reply Last reply
            0
            • C coco243

              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,

              _ Offline
              _ Offline
              _Flaviu
              wrote on last edited by
              #6

              Check in Resource.h file to see if those two radio buttons has consecutive values ... might be a problem if they are not.

              C 1 Reply Last reply
              0
              • C coco243

                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
                END

                cpp 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

                L Offline
                L Offline
                Lost User
                wrote on last edited by
                #7

                I just created a quick test with your code and it works fine. There must be something else happening that we cannot see. As suggested by Flaviu above, please check the defined values for the dialog buttons.

                1 Reply Last reply
                0
                • C coco243

                  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
                  END

                  cpp 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

                  S Offline
                  S Offline
                  Stefan_Lang
                  wrote on last edited by
                  #8

                  In 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)

                  1 Reply Last reply
                  0
                  • _ _Flaviu

                    Check in Resource.h file to see if those two radio buttons has consecutive values ... might be a problem if they are not.

                    C Offline
                    C Offline
                    coco243
                    wrote on last edited by
                    #9

                    _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

                    _ 1 Reply Last reply
                    0
                    • C coco243

                      _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

                      _ Offline
                      _ Offline
                      _Flaviu
                      wrote on last edited by
                      #10

                      You are welcome :) I am glad to help !

                      1 Reply Last reply
                      0
                      Reply
                      • Reply as topic
                      Log in to reply
                      • Oldest to Newest
                      • Newest to Oldest
                      • Most Votes


                      • Login

                      • Don't have an account? Register

                      • Login or register to search.
                      • First post
                        Last post
                      0
                      • Categories
                      • Recent
                      • Tags
                      • Popular
                      • World
                      • Users
                      • Groups