文件名称:自定义按钮
文件大小:3KB
文件格式:ZIP
更新时间:2016-12-10 15:33:58
ImageButton
使用多张不同状态的图,在窗口上画按钮, 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; //字体 };
【文件预览】:
VrImageButtonCL.cpp
VrImageButtonCL.h