//LinkButton.h #if _MSC_VER > 1000 #pragma once #endif // _MSC_VER > 1000 #ifndef LinkButtonh #define LinkButtonh /* Usage: in your header file: #include "LinkButton.h" ... CLinkButton Button1; CLinkButton Button2; CLinkButton Button3; in your .cpp file OnInitDialog: // subclass Owner Draw Button Resources: Button1.SubclassDlgItem(IDC_BUTTON1, this); Button2.SubclassDlgItem(IDC_BUTTON2, this); Button3.SubclassDlgItem(IDC_BUTTON3, this); Use ClassWizard to create BN_CLICKED messages for IDC_BUTTON1 etc: void CLinkButtonTesterDlg::OnButton1() {AfxMessageBox("1");} void CLinkButtonTesterDlg::OnButton2() {AfxMessageBox("2");} void CLinkButtonTesterDlg::OnButton3() {AfxMessageBox("3");} */ #include "HandCursor.h" class CLinkButton : public CButton { public: CLinkButton( COLORREF ButtonColor=GetSysColor(COLOR_BTNFACE ), COLORREF FocusColor =GetSysColor(COLOR_INFOBK ), COLORREF TextColor =GetSysColor(COLOR_BTNTEXT ), COLORREF LinkColor =GetSysColor(COLOR_HIGHLIGHT)) : ButtonColor(ButtonColor), FocusColor(FocusColor), TextColor(TextColor), LinkColor(LinkColor), LButtonDown(false), MouseOver(false), Captured(false), KeyDown(false), Focus(false) { Cursor=HandCursor; NONCLIENTMETRICS ncm; ncm.cbSize=sizeof(NONCLIENTMETRICS); SystemParametersInfo(SPI_GETNONCLIENTMETRICS,0,&ncm,0); TextFont.CreateFontIndirect(&ncm.lfStatusFont); ncm.lfStatusFont.lfUnderline=TRUE; LinkFont.CreateFontIndirect(&ncm.lfStatusFont); } virtual ~CLinkButton() {} void SetCursor(int nID) {Cursor=::LoadCursor(AfxGetInstanceHandle(), MAKEINTRESOURCE(nID));} void SetButtonColor(COLORREF Color=GetSysColor(COLOR_BTNFACE )) {ButtonColor=Color;} void SetFocusColor (COLORREF Color=GetSysColor(COLOR_INFOBK )) {FocusColor =Color;} void SetTextColor (COLORREF Color=GetSysColor(COLOR_BTNTEXT )) {TextColor =Color;} void SetLinkColor (COLORREF Color=GetSysColor(COLOR_HIGHLIGHT)) {LinkColor =Color;} void SetColors( COLORREF _ButtonColor=GetSysColor(COLOR_BTNFACE ), COLORREF _FocusColor =GetSysColor(COLOR_INFOBK ), COLORREF _TextColor =GetSysColor(COLOR_BTNTEXT ), COLORREF _LinkColor =GetSysColor(COLOR_HIGHLIGHT)) { ButtonColor=_ButtonColor; FocusColor =_FocusColor ; TextColor =_TextColor ; LinkColor =_LinkColor ; } void Redraw() {RedrawWindow(NULL, NULL, RDW_INVALIDATE | RDW_UPDATENOW);} // Attributes protected: bool LButtonDown; //true when the Mouse down event has been noticed. bool MouseOver; //true when the Mouse is over the Button. bool Captured; //true when the Mouse captured. bool KeyDown; //true when the Return or Enter key is down. bool Focus; //true when the Button has focus. HCURSOR Cursor; //The mouse cursor shown when the Mouse is over the Button. COLORREF ButtonColor; //Background color of the button when it doesn't have focus. COLORREF FocusColor; //Background color of the button when it has focus. COLORREF TextColor; //Text color of the button when the mouse isn't over it. COLORREF LinkColor; //Text color of the button when the mouse is over it. CFont TextFont; //The button's Font when the mouse isn't over it. CFont LinkFont; //The button's Font when the mouse is over it. // Operations public: // Overrides // ClassWizard generated virtual function overrides //{{AFX_VIRTUAL(CLinkButton) public: virtual void DrawItem(LPDRAWITEMSTRUCT lpDrawItemStruct); virtual BOOL PreTranslateMessage(MSG* pMsg); //}}AFX_VIRTUAL // Generated message map functions protected: //{{AFX_MSG(CLinkButton) afx_msg BOOL OnEraseBkgnd(CDC* pDC); afx_msg void OnKillFocus(CWnd* pNewWnd); afx_msg void OnLButtonDblClk(UINT nFlags, CPoint point); 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 OnSetFocus(CWnd* pOldWnd); //}}AFX_MSG DECLARE_MESSAGE_MAP() }; ///////////////////////////////////////////////////////////////////////////// //{{AFX_INSERT_LOCATION}} // Microsoft Visual C++ will insert additional declarations immediately before the previous line. #endif // !defined(AFX_LINKBUTTON_H__49E806D7_419B_11D6_8AD6_000000000000__INCLUDED_)