My WeChat public account : CPP Advanced Tour
If you think this article is helpful to you, please pay attention to "CPP Advanced Tour" to learn more technical dry goods
Win32 uses the WS_GROUP property to create radio buttons and check boxes
/*win32使用WS_GROUP属性创建单选框,复选框*/
void CreateRButton(HWND hWnd)
{
/*创建一个GroupBox*/
CreateWindowEx(WS_EX_WINDOWEDGE,
L"BUTTON",
L"Select Process Mode:",
WS_VISIBLE | WS_CHILD | BS_GROUPBOX,// <----BS_GROUPBOX does nothing on the grouping
10, 5,
350, 100,
hWnd,
nullptr,
hInst, NULL);
//创建第一个单选框按钮,需要设置BS_AUTORADIOBUTTON | WS_GROUP属性,从WS_GROUP开始到下一个含有WS_GROUP属性的radiobutton为一组,之前默认包含互斥的关系
CreateWindowEx(WS_EX_WINDOWEDGE,
L"BUTTON",
L"first radio button",
WS_VISIBLE | WS_CHILD | BS_AUTORADIOBUTTON | WS_GROUP, // <---- WS_GROUP group the following radio buttons 1st,2nd button
20, 25,
300, 20,
hWnd, //<----- Use main window handle
nullptr,
hInst, NULL);
CreateWindowEx(WS_EX_WINDOWEDGE,
L"BUTTON",
L"second radio button",
WS_VISIBLE | WS_CHILD | BS_AUTORADIOBUTTON, // Styles
20, 45,
300, 20,
hWnd,
nullptr,
hInst, NULL);
//复选框按钮
CreateWindowEx(WS_EX_WINDOWEDGE,
L"BUTTON",
L"third radio button",
WS_VISIBLE | WS_CHILD | BS_AUTOCHECKBOX | WS_GROUP, //<---Start second group for 3rd,4th button
20, 65,
300, 20,
hWnd,
nullptr,
hInst, NULL);
CreateWindowEx(WS_EX_WINDOWEDGE,
L"BUTTON",
L"forth radio button",
WS_VISIBLE | WS_CHILD | BS_AUTORADIOBUTTON, // Styles
20, 120,
300, 20,
hWnd,
nullptr,
hInst, NULL);
}
important
Welcome everyone to follow my personal WeChat public account to view professional client/server development knowledge, written test interview questions, programmers’ workplace experience and experience sharing.