CGroup - 强大的组控件






4.33/5 (3投票s)
2001年8月22日
1分钟阅读

143114

2944
一个基于 CButton 类的控件,它将为组提供更强大的功能。
引言
CGroup
是一个基于 CButton
的类。该组将成为一个具有许多特性和选项的卷起控件。任何被限制在组区域内的控件,在组“关闭”时将隐藏,在组“打开”时将显示。如果多个 CGroup
对象共享同一个父窗口,它们将垂直吸引彼此(此选项可以禁用)。此外,控件的许多方面都可以完全自定义(有关更多信息,请参阅 方法 部分)。
使用 CGroup
- 使用“项目/添加至项目/文件...”将文件 Group.h 和 Group.cpp 添加到您的项目中。
- 在您的对话框中创建一个 Group 对象。
- 赋予它一个唯一的 ID(例如
IDC_GROUP1
)。 - 在其中放置一些控件(复选框、列表框、编辑框等)。[注意:控件必须完全包含在组内]。
- 为创建的组创建一个成员变量。(如果类型
CGroup
不可用,请保留CButton
)。 - 如果成员变量类型与
CGroup
不同,请转到创建组的对话框的头文件,并将变量名前面的CButton
替换为CGroup
。 - 不要忘记在同一文件中添加
#include "group.h"
。 - 现在,您可以使用创建的
CGroup
对象关联的任何方法(有关更多信息,请参阅演示项目)。组可以包含在其他组内(修订 - 2001 年 8 月 23 日)。
方法 (public)
//return a pointer to the CGroup object... CGroup* GetGroupCtrl() { return this; } // Change the titlebar color void SetBarColor(COLORREF color) { m_barColor = color; Invalidate(); } // Change the title text color void SetTextColor(COLORREF color) { m_textColor = color; Invalidate(); } // Tells the group whether it attracts other groups or not // Attraction is vertical and descending. // Any CGroup placed under the current // CGroup will be, if they didn't disable their attraction, attracted. void SetAttract(bool toggle = false) { m_attract = toggle; Invalidate(); } // Set whether the group can fold or not... // As a result, the button will hide/show void SetFold(bool toggle = true); // Add a bitmap to the title bar and assign a color mask // If the bitmap is bigger than the title bar, you can // choose to resize the bar automatically. void SetBitmap(UINT bmpID,COLORREF mask = RGB(0,0,0), bool resizeBar = false); // Toggle to tell whether the group can be attracted void SetAttraction(bool toggle = true) { m_IsAttracted = toggle; Invalidate(); } // Set text font using either a LOGFONT or variables void SetTextFont (LOGFONT lf); void SetTextFont (CString face,int size = 12, bool bold = true,bool italic = false,bool underline = false); //Set the title bar height void SetBarHeight(int h); // Set whether the group will change its height or not when attracted // (ie the bottom of the group area will remain the same, hence increasing // or decreasing the height of the group as other groups fold above it) void SetLastGroup(bool toggle = false) {m_last = toggle; Invalidate(); } //Set whether the last control (lowest) in the group //will have its height modified by attraction void SetLastCtrl(bool toggle = false) {m_extendLastCtrl = toggle; Invalidate(); } //Toggle the display of the frame for the group void DrawGroupBorder(bool toggle = true) { m_borders = toggle; Invalidate(); } //toggle the display the frame for the title bar void DrawBarBorder(bool toggle = true) { m_barBorders = toggle; Invalidate(); }
致谢
透明位图类和函数由 Paul Reynolds 编写。