CFlexiButton 类






3.27/5 (8投票s)
2004年2月20日
3分钟阅读

79381

7459
一个类,
引言
不要被上面的图片吓到。 嗯,毕竟,这是一个演示。
这个类对于那些厌倦了屏幕上熟悉的灰色矩形的程序员朋友们很有用。 好吧,这里有一些东西可能会让你从那解脱出来......一些改变!!! 我以前写过这段代码,希望你们中的一些人会发现它有用。
嗯……有什么大不了的?? 可以使用CBitmapButton
吗? 是的,你可以,但你可能需要为每个状态提供 4 张不同的图片; 但不是用CflexiButton
!! 你只需要提供一张图片,瞧!! 它会为所有按钮状态生成自己的图片! 还有一个有趣的小东西; 如果你要更改系统的外观主题,那么按钮会同步更改按钮的外观。 是的,这是一个很酷的小东西。
你在上面对话框中看到的每张图片都是一个按钮。 它们中的每一个都展示了这种灵活按钮的不同风格。 左边的第一个按钮是更改为系统中强制执行的主题颜色的按钮。 有趣的小倒置“下一步”按钮已启用,它完全代表按钮的活动区域。 然后是最底部的图片,它的行为类似于普通的位图按钮。 试试看,看看会发生什么。 第一个按钮被禁用。 最后,顶部的“灰色”播放图片,即“灰色”播放按钮。
是的,我从代码项目获得了很大的帮助。 我必须浏览一些文章并从其中一些文章中借用函数(并修复错误)才能完成这个简洁的小类。 CXImage
, PictureEx
, WindowBitmap
... 仅举几例... 感谢作者!!
背景
我正在编程一个与我的 Winamp 并排工作的 mp3 数据库。 然后我想我会改变界面从传统的矩形外观。 这就是导致我改变按钮外观的原因,从而创建了这个类。
使用代码
按钮事件
#define FB_BTNCLIK WM_USER+111 //Fired when the button is clicked #define FB_BTNHOVR WM_USER+112 //Fired when the mouse hovers the button #define FB_BTNLEAV WM_USER+113 //Fired when the mouse leaves the button
预设
//used if the FBS_PRESSEFFECT style is specified //and when the mouse leaves the button #define BTN_PRS_DISP 1 // Effects Supported #define FB_CREATEBMPS_SUPPORT 1
按钮样式
** Styles used during Bitmap Loading only // specifies if the button size is to be adjusted to the size of the window #define FBS_ADJUSTTOBMP 0x00000010 ** Other Styles // The press effect if only one bitmap is specified #define FBS_PRESSEFFECT 0x00000001 // Specifies if the bitmaps are to be blended to system color. #define FBS_BLENDSYSCLR 0x00000100 // Specifies if all bitmaps are to be created from the first bitmap. #define FBS_CREATE4ALL 0x00001000 // Specifies if all bitmaps are to be updated if the system color changes. #define FBS_UPDATEBMPS 0x00010000
成员函数
// Enable And Disable Window bool CFlexiButton::EnableWindow(bool bEnable) // Show Button or hide it bool CFlexiButton::ShowButton(bool bShow) // Show button region bool CFlexiButton::ShowButtonRegion(HRGN hRgn) // A predefined region can be set as the visible region of the button. // Delete region with specified color and tolerance from lpszBitmapResource bool CFlexiButton::DeleteButtonRegion(COLORREF sRef,COLORREF sTol = 0x000000) // A color with tolerance can be set to be deleted from the // region of the button. The rest would be the region of the button. // Load Bitmaps bool CFlexiButton::LoadBitmaps (LPCTSTR lpszBitmapResource, LPCTSTR lpszBitmapResourceSel = NULL, LPCTSTR lpszBitmapResourceFocus = NULL, LPCTSTR lpszBitmapResourceDisabled = NULL, bool bFromFile = 0)
- 第一个位图是必须的,如果没有指定,则会自动生成禁用位图。
- 如果设置了
FBS_CREATE4ALL
样式,此函数将仅采用第一个位图并生成所有其他按钮状态的图像。 - 如果设置了
FBS_BLENDSYSCLR
样式,则所有位图颜色都将混合到当前窗口框架颜色。
// Get Button's Handle HWND CFlexiButton::GetWindowHandle() // Create Button with Styles and button sizes HWND CFlexiButton::CreateButton (HWND hWnd, int iStyle, int iButtonID, RECT sRect)
- 如果要相应地调整按钮,则应在此处指定
FBS_ADJUSTTOBMP
。 在此函数之后删除或添加此样式没有任何效果。 - 必须设置标识按钮的资源 ID。 并且按钮的边界矩形,即坐标,必须与父窗口的客户端区域相关。
- 如果您指定一个带有
BN_CLICKED
事件处理程序的 MFC 按钮,并将该按钮的资源 ID 传递给CreateButton
函数,则CFlexibutton
将使用该 MFC 按钮的处理程序。 无需在父窗口的OnCommand
中捕获任何事件。
我希望以上对这些方法的描述能让你们中的大多数人清楚。 如果您有任何问题,请随时与我联系。
// Please take care to make necessary change according to your circumstances.. // //*** Do this where u would like to declare the object ***// #include "FlexiButton.h" using namespace C001_FlexButton; CFlexiButton oFButton; //*** Do similarly where u would like to create and show the button ***// oR.left = 200; oR.top =250; oR.bottom = 400; oR.right = 300; if(!oFButton4.CreateButton(m_hWnd,FBS_ADJUSTTOBMP,IDC_FLEXBUTTON4,oR)) return 0; if(!oFButton4.LoadBitmaps("wire13.bmp","wire12.bmp","wire1.bmp","wire14.bmp",1)) return 0; oFButton4.ShowButton(1); //
以上是在上面图片中对话框底部创建按钮的代码。 请记住,此类还提供了一些其他样式。
关注点
哦,是的……在使用此类时,您可能会发现一些非故意的有趣行为,请告诉我。 我当时正在考虑编写一个日志文件... 用于按钮控件?? 不要啊!!!!
历史
这是我第一次提交给代码项目或任何程序员的网站; 我将称之为... 嗯... CFlexiButton
No.1.0。