您的位置:首页 > 其它

[Win32SDK基本]Button Control(3)Group Boxes

2015-07-01 13:48 225 查看
本文由CSDN用户zuishikonghuan所作,转载请注明出处:/article/9672505.html
上两篇中说了push button和check box这两种按钮,上两篇中还算有点东西说,BM_SETIMAGE 和 BM_SETCHECK 嘛,可是 Group Boxes

我实在是不知道说些什么好了,但好歹也是按钮控件的一种,于是就说说。

MSDN:A group box is a rectangle that surrounds a set of controls, such as check boxes or radio buttons, with an application-defined text label in its upper left corner. The sole purpose of a group box is to organize controls related by a common purpose (usually
indicated by the label). The group box has only one style, defined by the constant BS_GROUPBOX. Because a group box cannot be selected, it has no check state, focus state, or push state.

其实还是子窗口,static那节说的很明白了,就不重复了 ,这个控件的风格是 BS_GROUPBOX

还是以我的博客“[Win32SDK基本] 窗口详解(超详细)”(地址:/article/9672496.html)为模板,进一步编写。

先创建全局变量

HWND button6 = 0;

再创建 Group Boxes:
button6 = CreateWindow(TEXT("Button"), TEXT("Check Boxes"), WS_CHILD | WS_VISIBLE | BS_GROUPBOX, 10, 300, 320, 100, hwnd, (HMENU)8, (HINSTANCE)GetWindowLong(hwnd, GWL_HINSTANCE), NULL);
SendMessage(button6, WM_SETFONT, (WPARAM)GetStockObject(17), 0);


效果图



值得一提的是,Group Boxes 是窗口的子窗口,但是对于它的子窗口而言,它就是一个父窗口了,换句话说,Group Boxes 本身就是为了成为一个“容器”而设计的。

举例:再创建一个按钮,位置为(10,25),父窗口句柄不再是之前我们用的最早创建的窗口句柄hwnd了,而是用我们刚刚创建的 Group Boxes 的句柄,也就是说用这个 Group Boxes 作父窗口。

代码:

button7 = CreateWindow(TEXT("Button"), TEXT("在Group Boxes里的按钮"), WS_CHILD | WS_VISIBLE | BS_PUSHBUTTON, 10, 25, 200, 30, button6, (HMENU)4, (HINSTANCE)GetWindowLong(hwnd, GWL_HINSTANCE), NULL);
SendMessage(button7, WM_SETFONT, (WPARAM)GetStockObject(17), 0);


效果图:




内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: