user-0 提问: 如何给单选框或多选框分组？

回复:
user: user-1
content: //* #define UNICODE #define _UNICODE //*/ #include <Windows.h> #include <tchar.h> #include <stdio.h>  #pragma comment(lib, "gdi32") #pragma comment(lib, "user32")  #pragma comment(linker, "/subsystem:windows")  LRESULT CALLBACK WndProc(HWND, UINT, WPARAM, LPARAM);  int WINAPI _tWinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPTSTR szCmdLine, int iCmdShow) {    static TCHAR szAppName[] = TEXT("HelloWin");    HWND         hwnd;    MSG          msg;    WNDCLASS     wndclass;     RtlZeroMemory(&wndclass, sizeof(wndclass));    wndclass.style         = CS_HREDRAW | CS_VREDRAW;    wndclass.lpfnWndProc   = WndProc;    wndclass.hInstance     = hInstance;    wndclass.hIcon         = LoadIcon(NULL, TEXT("#32512"));    wndclass.hCursor       = LoadCursor(NULL, IDC_ARROW);    wndclass.hbrBackground = (HBRUSH)GetStockObject(WHITE_BRUSH);    wndclass.lpszMenuName  = NULL;    wndclass.lpszClassName = szAppName;     if (!RegisterClass(&wndclass))    {       MessageBox(NULL, TEXT("This program requires Windows NT series!"), szAppName, MB_ICONERROR);       return -1;    }     hwnd = CreateWindowEx(WS_EX_APPWINDOW,         // A tool window does not appear in the task bar or in the window that appears when the user presses ALT+TAB.                          szAppName,                  // window class name                          TEXT("The Hello Program"),  // window caption                          WS_OVERLAPPEDWINDOW,        // window style                          500,//CW_USEDEFAULT,              // initial x position                          200,//CW_USEDEFAULT,              // initial y position                          320,//CW_USEDEFAULT,              // initial x size                          320,//CW_USEDEFAULT,              // initial y size                          NULL,                       // parent window handle                          NULL,                       // window menu handle                          hInstance,                  // program instance handle                          NULL);                      // creation parameters     ShowWindow(hwnd, SW_SHOW);    UpdateWindow(hwnd);     {       BOOL bRet;       while ((bRet = GetMessage(&msg, NULL, 0, 0)) != 0)       {          if (bRet == -1)          {             MessageBox(NULL, TEXT("GetMessage Error."), TEXT("Message"), MB_ICONERROR);             return -1;          }          else          {             TranslateMessage(&msg);             DispatchMessage(&msg);          }       }    }     //All window classes that an application registers are unregistered when it terminates.    //No window classes registered by a DLL are unregistered when the dll is unloaded.    //hInstance如果设为NULL,会从系统、全局和局部三个作用域查找    UnregisterClass(szAppName, hInstance);    return msg.wParam; }  LRESULT CALLBACK WndProc(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam) {    HWND h_kuang1, h_n1, h_n2, h_n3, h_kuang2, h_n12, h_n22, h_n32;     switch (message)    {       case WM_CREATE:          //*          //画一个框          h_kuang1 = CreateWindowEx(0,                                   TEXT("button"),                                   TEXT("Group1"),                                   WS_CHILD | WS_VISIBLE | BS_GROUPBOX,                                   10,                                   10,                                   100,                                   150,                                   hwnd,     //父窗口句柄                                   (HMENU)10086,                                   (HINSTANCE)GetWindowLong(hwnd, GWL_HINSTANCE),                                   NULL);          //*/          //添个单选按钮          h_n1 = CreateWindowEx(0,                                TEXT("button"),                                TEXT("n1"),                                WS_CHILD | WS_VISIBLE | BS_AUTORADIOBUTTON | WS_GROUP, //在每一组中设置第一个radio的属性为WS_GROUP                                20,                                40,                                50,                                30,                                hwnd,     //父窗口句柄                                (HMENU)100,                                (HINSTANCE)GetWindowLong(hwnd, GWL_HINSTANCE),                                NULL);                    //下面是二个单选按钮          h_n2 = CreateWindowEx(0,                                TEXT("button"),                                TEXT("n2"),                                WS_CHILD | WS_VISIBLE | BS_AUTORADIOBUTTON,                                20,                                70,                                50,                                30,                                hwnd,     //父窗口句柄                                (HMENU)101,                                (HINSTANCE)GetWindowLong(hwnd, GWL_HINSTANCE),                                NULL);          h_n3 = CreateWindowEx(0,                                TEXT("button"),                                TEXT("n3"),                                WS_CHILD | WS_VISIBLE | BS_AUTORADIOBUTTON,                                20,                                100,                                50,                                30,                                hwnd,     //父窗口句柄                                (HMENU)102,                                (HINSTANCE)GetWindowLong(hwnd, GWL_HINSTANCE),                                NULL);          h_kuang2 = CreateWindowEx(0,                                   TEXT("button"),                                   TEXT("Group2"),                                   WS_CHILD | WS_VISIBLE | BS_GROUPBOX,                                   110,                                   10,                                   100,                                   150,                                   hwnd,     //父窗口句柄                                   (HMENU)110086,                                   (HINSTANCE)GetWindowLong(hwnd, GWL_HINSTANCE),                                   NULL);          //*/          //添个单选按钮          h_n12 = CreateWindowEx(0,                                TEXT("button"),                                TEXT("n1"),                                WS_CHILD | WS_VISIBLE | BS_AUTORADIOBUTTON | WS_GROUP, //在每一组中设置第一个radio的属性为WS_GROUP                                120,                                40,                                50,                                30,                                hwnd,     //父窗口句柄                                (HMENU)1100,                                (HINSTANCE)GetWindowLong(hwnd, GWL_HINSTANCE),                                NULL);                    //下面是二个单选按钮          h_n22 = CreateWindowEx(0,                                TEXT("button"),                                TEXT("n2"),                                WS_CHILD | WS_VISIBLE | BS_AUTORADIOBUTTON,                                120,                                70,                                50,                                30,                                hwnd,     //父窗口句柄                                (HMENU)1101,                                (HINSTANCE)GetWindowLong(hwnd, GWL_HINSTANCE),                                NULL);          h_n32 = CreateWindowEx(0,                                TEXT("button"),                                TEXT("n3"),                                WS_CHILD | WS_VISIBLE | BS_AUTORADIOBUTTON,                                120,                                100,                                50,                                30,                                hwnd,     //父窗口句柄                                (HMENU)1102,                                (HINSTANCE)GetWindowLong(hwnd, GWL_HINSTANCE),                                NULL);          return 0;       case WM_DESTROY:          PostQuitMessage(0);          return 0;    }    return DefWindowProc(hwnd, message, wParam, lParam); }

user: user-2
content: win32界面可以按下面的方式分组 为对话框添加Radio1，Radio2，Radio3和Radio4。很简单，先为这些Radio Button排个顺序(这 个必须要做，比如你的一组控件有Radio1,Radio2,Radio3,就把它们的TAB顺序分别设为1,2,3,并将Radio1的Group属性 设为True，这样，当选中Radio1的时候和它关联的变量就是０，当选中Radio２的时候和它关联的变量就是１，依此类推)，就是排 列他们的TAB ORDER。在对话框资源面板上Ctrl+D，然后按你自己的理想顺序用鼠标逐个点击就可以了。不妨假设Radio1、Radio2、Radio3、 Radio4分别是1、2、3、4。Radio1和Radio3都选上Group属性，那么，1、2是一组，3、4是另外一组，因为分组的原则是在选上 Group属性的这一个开始直到碰到下一个选上Group属性的。你不妨再Ctrl+D，令Radio1、Radio2、Radio3、Radio4分别 是1、3、2、4，那么Radio1和Radio3是一组，如果m_nRadio1=1,此时是Radio3被选上而不是Radio2被选上。分好了组就 分别使用它们吧。

user: user-0
content: 引用 2 楼 Intel0011 的回复://* #define UNICODE #define _UNICODE //*/ #include <Windows.h> #include <tchar.h> #include <stdio.h>  #pragma comment(lib, "gdi32") #pragma comment(lib, "user32")  #pragma comment(linker, "/subsystem:windows")  LRESULT CALLBACK WndProc(HWND, UINT, WPARAM, LPARAM);  int WINAPI _tWinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPTSTR szCmdLine, int iCmdShow) {    static TCHAR szAppName[] = TEXT("HelloWin");    HWND         hwnd;    MSG          msg;    WNDCLASS     wndclass;     RtlZeroMemory(&wndclass, sizeof(wndclass));    wndclass.style         = CS_HREDRAW | CS_VREDRAW;    wndclass.lpfnWndProc   = WndProc;    wndclass.hInstance     = hInstance;    wndclass.hIcon         = LoadIcon(NULL, TEXT("#32512"));    wndclass.hCursor       = LoadCursor(NULL, IDC_ARROW);    wndclass.hbrBackground = (HBRUSH)GetStockObject(WHITE_BRUSH);    wndclass.lpszMenuName  = NULL;    wndclass.lpszClassName = szAppName;     if (!RegisterClass(&wndclass))    {       MessageBox(NULL, TEXT("This program requires Windows NT series!"), szAppName, MB_ICONERROR);       return -1;    }     hwnd = CreateWindowEx(WS_EX_APPWINDOW,         // A tool window does not appear in the task bar or in the window that appears when the user presses ALT+TAB.                          szAppName,                  // window class name                          TEXT("The Hello Program"),  // window caption                          WS_OVERLAPPEDWINDOW,        // window style                          500,//CW_USEDEFAULT,              // initial x position                          200,//CW_USEDEFAULT,              // initial y position                          320,//CW_USEDEFAULT,              // initial x size                          320,//CW_USEDEFAULT,              // initial y size                          NULL,                       // parent window handle                          NULL,                       // window menu handle                          hInstance,                  // program instance handle                          NULL);                      // creation parameters     ShowWindow(hwnd, SW_SHOW);    UpdateWindow(hwnd);     {       BOOL bRet;       while ((bRet = GetMessage(&msg, NULL, 0, 0)) != 0)       {          if (bRet == -1)          {             MessageBox(NULL, TEXT("GetMessage Error."), TEXT("Message"), MB_ICONERROR);             return -1;          }          else          {             TranslateMessage(&msg);             DispatchMessage(&msg);          }       }    }     //All window classes that an application registers are unregistered when it terminates.    //No window classes registered by a DLL are unregistered when the dll is unloaded.    //hInstance如果设为NULL,会从系统、全局和局部三个作用域查找    UnregisterClass(szAppName, hInstance);    return msg.wParam; }  LRESULT CALLBACK WndProc(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam) {    HWND h_kuang1, h_n1, h_n2, h_n3, h_kuang2, h_n12, h_n22, h_n32;     switch (message)    {       case WM_CREATE:          //*          //画一个框          h_kuang1 = CreateWindowEx(0,                                   TEXT("button"),                                   TEXT("Group1"),                                   WS_CHILD | WS_VISIBLE | BS_GROUPBOX,                                   10,                                   10,                                   100,                                   150,                                   hwnd,     //父窗口句柄                                   (HMENU)10086,                                   (HINSTANCE)GetWindowLong(hwnd, GWL_HINSTANCE),                                   NULL);          //*/          //添个单选按钮          h_n1 = CreateWindowEx(0,                                TEXT("button"),                                TEXT("n1"),                                WS_CHILD | WS_VISIBLE | BS_AUTORADIOBUTTON | WS_GROUP, //在每一组中设置第一个radio的属性为WS_GROUP                                20,                                40,                                50,                                30,                                hwnd,     //父窗口句柄                                (HMENU)100,                                (HINSTANCE)GetWindowLong(hwnd, GWL_HINSTANCE),                                NULL);                    //下面是二个单选按钮          h_n2 = CreateWindowEx(0,                                TEXT("button"),                                TEXT("n2"),                                WS_CHILD | WS_VISIBLE | BS_AUTORADIOBUTTON,                                20,                                70,                                50,                                30,                                hwnd,     //父窗口句柄                                (HMENU)101,                                (HINSTANCE)GetWindowLong(hwnd, GWL_HINSTANCE),                                NULL);          h_n3 = CreateWindowEx(0,                                TEXT("button"),                                TEXT("n3"),                                WS_CHILD | WS_VISIBLE | BS_AUTORADIOBUTTON,                                20,                                100,                                50,                                30,                                hwnd,     //父窗口句柄                                (HMENU)102,                                (HINSTANCE)GetWindowLong(hwnd, GWL_HINSTANCE),                                NULL);          h_kuang2 = CreateWindowEx(0,                                   TEXT("button"),                                   TEXT("Group2"),                                   WS_CHILD | WS_VISIBLE | BS_GROUPBOX,                                   110,                                   10,                                   100,                                   150,                                   hwnd,     //父窗口句柄                                   (HMENU)110086,                                   (HINSTANCE)GetWindowLong(hwnd, GWL_HINSTANCE),                                   NULL);          //*/          //添个单选按钮          h_n12 = CreateWindowEx(0,                                TEXT("button"),                                TEXT("n1"),                                WS_CHILD | WS_VISIBLE | BS_AUTORADIOBUTTON | WS_GROUP, //在每一组中设置第一个radio的属性为WS_GROUP                                120,                                40,                                50,                                30,                                hwnd,     //父窗口句柄                                (HMENU)1100,                                (HINSTANCE)GetWindowLong(hwnd, GWL_HINSTANCE),                                NULL);                    //下面是二个单选按钮          h_n22 = CreateWindowEx(0,                                TEXT("button"),                                TEXT("n2"),                                WS_CHILD | WS_VISIBLE | BS_AUTORADIOBUTTON,                                120,                                70,                                50,                                30,                                hwnd,     //父窗口句柄                                (HMENU)1101,                                (HINSTANCE)GetWindowLong(hwnd, GWL_HINSTANCE),                                NULL);          h_n32 = CreateWindowEx(0,                                TEXT("button"),                                TEXT("n3"),                                WS_CHILD | WS_VISIBLE | BS_AUTORADIOBUTTON,                                120,                                100,                                50,                                30,                                hwnd,     //父窗口句柄                                (HMENU)1102,                                (HINSTANCE)GetWindowLong(hwnd, GWL_HINSTANCE),                                NULL);          return 0;       case WM_DESTROY:          PostQuitMessage(0);          return 0;    }    return DefWindowProc(hwnd, message, wParam, lParam); }  我知道了，说白了就是跟BS_GROUBOX没有关系，只跟WS_GROU有关系是吧？