Click here to Skip to main content
15,888,454 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I want to create a radio button menu but don't know how to handle messages, the code that I tried isn't displaying the menu. Please help me out, thanks in advance

<pre lang="c++">
#include <windows.h>

 LRESULT CALLBACK WndProc( HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam );

static char *title = TEXT("Check Box");

int WINAPI WinMain( HINSTANCE hInstance, HINSTANCE hPrevInstance,
					LPSTR lpCmdLine, int nCmdShow )
{
  MSG  msg ;    
  WNDCLASS wc = {0};
  wc.lpszClassName = TEXT( "Check Box" );
  wc.hInstance     = hInstance ;
  wc.hbrBackground = GetSysColorBrush(COLOR_3DFACE);
  wc.lpfnWndProc   = WndProc ;
  wc.hCursor       = LoadCursor(0, IDC_ARROW);

  
  RegisterClass(&wc);
  CreateWindow( wc.lpszClassName, title,
                WS_OVERLAPPEDWINDOW | WS_VISIBLE,
                150, 150, 230, 150, 0, 0, hInstance, 0);  

  while( GetMessage(&msg, NULL, 0, 0)) {
    TranslateMessage(&msg);
    DispatchMessage(&msg);
  }
  return (int) msg.wParam;
}

 LRESULT CALLBACK WndProc( HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam )
{

 switch(msg)  
 {
  case WM_CREATE:
  {
    CreateWindow(TEXT("button"), TEXT("&Red"),
                WS_CHILD | WS_VISIBLE | BS_AUTORADIOBUTTON|WS_GROUP ,
                20, 155, 100, 30, hwnd, (HMENU) 1, ((LPCREATESTRUCT)lParam)->hInstance, NULL);

CreateWindow(TEXT("button"), TEXT("&Red"),
                WS_CHILD | WS_VISIBLE | BS_AUTORADIOBUTTON,
                20, 155, 100, 30,hwnd, (HMENU) 1, ((LPCREATESTRUCT)lParam)->hInstance, NULL);

CreateWindow(TEXT("button"), TEXT("&Red"),
                WS_CHILD | WS_VISIBLE | BS_AUTORADIOBUTTON,
                20, 155, 100, 30, hwnd, (HMENU) 1, ((LPCREATESTRUCT)lParam)->hInstance, NULL);

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


What I have tried:

Tried adding Group option to createwindow but that isn't helping
Posted
Updated 18-Aug-16 9:50am

1 solution

Looks like you're not calling ShowWindow() and UpdateWindow() which requires you to get a handle to the created window (the return value from CreateWindow()), maybe take a look at this[^] link.
 
Share this answer
 
Comments
Erebus_22 18-Aug-16 22:03pm    
Yes, but the main case is to handle command case, how to do that for radio button, how to know weather a change in selection is required
jeron1 19-Aug-16 10:10am    
I am not understanding, the radio button is a window within a parent window, you can invoke windows methods on the radio button. Not sure what 'change in selection' you are referring to.
Erebus_22 19-Aug-16 23:33pm    
Once the user clicks a radio button, how can I know which button is clicked?
What code do I use for that
jeron1 22-Aug-16 10:24am    
Maybe take a look at this thread.
http://stackoverflow.com/questions/37271194/wm-command-catch-button-press-in-c-win32

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900