Radio button in groupbox is not generating WM_COMMAND

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • johny10151981
    Top Contributor
    • Jan 2010
    • 1059

    #1

    Radio button in groupbox is not generating WM_COMMAND

    Hi,
    Here a code part that create a group box and radio button
    Code:
    hGroup=CreateWindowEx(0,L"BUTTON",L"Choose Connection type", WS_CHILD|WS_VISIBLE|BS_GROUPBOX|WS_GROUP,30,180,300,85,hWnd,(HMENU)10006,hInstance, NULL);
    CreateWindowEx(0,L"BUTTON",L"Direct Connection",WS_CHILD|WS_VISIBLE|BS_RADIOBUTTON, 10,17,280,30,hGroup,(HMENU) 10010,hInstance ,NULL);
    CreateWindowEx(0,L"BUTTON",L"XML Connection",WS_CHILD|WS_VISIBLE|BS_RADIOBUTTON, 10,47,280,30,hGroup,(HMENU) 10011,hInstance,NULL);
    here is the part in WM_COMMAND..
    Code:
    case WM_COMMAND:
    wmId    = LOWORD(wParam);
    wmEvent = HIWORD(wParam);
    // Parse the menu selections:
    switch (wmId)
      {
       case 10010:
    	setRadiocehck(hGroup,GetDlgItem(hGroup,10010));
            break;
       case 10011:
    	setRadiocehck(hGroup,GetDlgItem(hGroup,10011));
    	break;  
       }
    and this WM_COMMAND is related with hGroup window's Mother window i.e. main window in my program.

    The problem is on click action 10010 or 10011 never get called.
    I have realized one possible reason. The reason is the WndProc is related with main window it only process its child window but not grand child (:)) Radiobuttons are not main windows child. in that case what would be the best solution to toggle between radio buttons.

    Please let me know.
    Best regards,
    Johny
  • johny10151981
    Top Contributor
    • Jan 2010
    • 1059

    #2
    Well, got an sad answer there is no solution for it. :(
    The reason is GROUPBOX is a static control. It wont generate any WM_COMMAND anyway

    Comment

    • thejaguar
      New Member
      • Jul 2010
      • 1

      #3
      It most certainly can be done, here is sample code:

      Code:
      // Global
      WNDPROC GroupBoxProc;
      
      LONG CALLBACK GroupRelay(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam){
      	if(msg == WM_COMMAND || msg == WM_NOTIFY){
      		return SendMessage(GetParent(hwnd), msg, wParam, lParam);
      	}
      
      	return CallWindowProc(GroupBoxProc, hwnd, msg, wParam, lParam);
      }
      
      //	WM_CREATE
      
      	grpMailbox = CreateWindowEx(
      			WS_EX_CONTROLPARENT,
      			"BUTTON",
      			"Mailbox settings",
      			WS_CHILD | WS_VISIBLE | BS_GROUPBOX | WS_CLIPCHILDREN,
      			12, 12,
      			371, 131,
      			hwnd,
      			(HMENU)(GRPMAILBOX),
      			hInst,
      			NULL);
      
      	GroupBoxProc = reinterpret_cast<WNDPROC>(GetWindowLongPtr(grpMailbox, GWLP_WNDPROC));
      	SetWindowLongPtr(grpMailbox, GWLP_WNDPROC, reinterpret_cast<LONG_PTR>(GroupRelay));
      This will relay all WM_COMMAND and WM_NOTIFY messages to the parent and pass the rest to the box as normal.

      This code is directly from my working code, so it is verified working (Under XP SP3, but it should work in all others)

      Note: Just in case you're not familiar, this is C++, in C replace reinterpret_cas t<X> with (X)

      Comment

      • johny10151981
        Top Contributor
        • Jan 2010
        • 1059

        #4
        OK
        I will try this:)
        thank you :)

        Comment

        Working...