自定义按钮
使用多张不同状态的图,在窗口上画按钮, class AFX_EXT_CLASS VrImageButtonCL : public CButton { DECLARE_DYNAMIC(VrImageButtonCL) public: VrImageButtonCL(); virtual ~VrImageButtonCL(); public: // 从磁盘上读取图像。 BOOL LoadBitmapsM(LPCTSTR normalImageFile, LPCTSTR downImageFile, LPCTSTR overImageFile=NULL, LPCTSTR disableImageFile=NULL ); void SetNormalImageM( VrImageCL& norImg ); void SetDownImageM( VrImageCL& downImg ); void SetOverImageM( VrImageCL& overImg ); void SetDisaImageM( VrImageCL& disaImg ); // 根据图像调整按钮大小 void SizeToContent() ; // 设置按钮位置(基于父窗口) void SetPositionM( POINT pos ) ; //可见性 void SetVisibleM( BOOL bVisible ); BOOL IsVisibleM(); //按下状态 void SetDownStateM( BOOL bDown = TRUE ); BOOL GetDownStateM() const ; //按钮风格。图像or文本 enum{ CR_BS_IMAGE, CR_BS_TEXT }; //图像按钮,文本按钮 void SetStyleM( int nType ); int GetstyleM() ; protected: DECLARE_MESSAGE_MAP() virtual void DrawItem(LPDRAWITEMSTRUCT lpDIS /*lpDrawItemStruct*/); afx_msg void OnLButtonDown(UINT nFlags, CPoint point); afx_msg void OnLButtonUp(UINT nFlags, CPoint point); afx_msg void OnMouseMove(UINT nFlags, CPoint point); afx_msg void OnEnable(BOOL bEnable); afx_msg void OnKillFocus(CWnd* pNewWnd); afx_msg LRESULT OnMouseLeave(WPARAM, LPARAM); protected: void releaseAllM(); void drawImageM(LPDRAWITEMSTRUCT lpDIS); void drawTextM(LPDRAWITEMSTRUCT lpDIS); private: VrImageCL normalImageM; //按钮正常时图片 VrImageCL overImageM; //按钮在鼠标悬停时图片 VrImageCL downImageM; //按钮按下时图片 VrImageCL disableImageM; //按钮无效时图片 BOOL bLBtnDownM ; BOOL trackingM ; BOOL bKeepDownM ; int styleM; //按钮样式 BOOL bVisibleM; //是否可见。 COLORREF backClrM; //底色 COLORREF textClrM; //文字颜色 CFont fontM; //字体 };
- 1
- 粉丝: 25
- 资源: 33
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助