如何创建和处理单选按钮消息C ++ windows.h
问题描述:
我想创建一个单选按钮菜单,但不知道如何处理消息,我尝试的代码没有显示菜单。请帮帮我,提前谢谢
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);
}
}
我的尝试:
尝试向createwindow添加Group选项但是没有帮助
What I have tried:
Tried adding Group option to createwindow but that isn't helping