CShadeButtonST






4.47/5 (9投票s)
2001年6月26日
2分钟阅读

179752
使用 CButtonST 创建的渐变按钮
摘要
如今,几乎所有东西都可以自定义外观或进行皮肤设置。
如果您看过新的 Windows XP,您会注意到即使按钮的外观也与我们所知的截然不同。
即使我不太喜欢过于复杂地自定义外观,我也注意到人们非常喜欢 Davide Pizzolato 发布的名为 CxShadeButton
的按钮控件。我的想法是公开 CButtonST
(MFC 平面按钮的参考控件)中的一两个虚函数,让开发人员可以从中派生自己的类,并实现自定义背景绘制,同时仍然保留 CButtonST
控件的所有功能。
为了展示这个新特性,我决定重现 CxShadeButton
的外观和感觉。我从原始代码中提取了名为 CxDib
的类以及创建和绘制背景效果的代码。
此代码片段的所有功劳归于 Davide Pizzolato。
虚函数
CButtonST
公开了两个虚函数。
OnDrawBackground
每次需要绘制按钮背景时都会调用此函数。
如果按钮处于透明模式,则不会调用此函数。
// Parameters: // [IN] pDC // Pointer to a CDC object that indicates the device context. // [IN] pRect // Pointer to a CRect object that indicates the bounds of the // area to be painted. // // Return value: // BTNST_OK // Function executed successfully. // DWORD OnDrawBackground(CDC* pDC, LPCRECT pRect)
OnDrawBorder
每次需要绘制按钮边框时都会调用此函数。
如果按钮处于标准(非平面)模式,则不会调用此函数。
// Parameters: // [IN] pDC // Pointer to a CDC object that indicates the device context. // [IN] pRect // Pointer to a CRect object that indicates the bounds of the // area to be painted. // // Return value: // BTNST_OK // Function executed successfully. // DWORD OnDrawBorder(CDC* pDC, LPCRECT pRect)
开发人员从 CButtonST
派生自己的类,然后在新的类中实现这两个函数。
示例
CButtonST
演示应用程序包含一个页面,演示如何实现新的效果。从 CButtonST
派生了一个名为 CShadeButtonST
的类,并在 OnDrawBackground
方法中主要实现了新的效果。
备注
这种架构使得能够生成默认情况下不可用的各种按钮。如果有人实现了在 Windows XP 中找到的新按钮的外观和感觉,我将很乐意在下一个 CButtonST
演示应用程序中包含他的代码。