《2022年孙鑫编写的C++按钮修饰代码借鉴 .pdf》由会员分享,可在线阅读,更多相关《2022年孙鑫编写的C++按钮修饰代码借鉴 .pdf(4页珍藏版)》请在taowenge.com淘文阁网|工程机械CAD图纸|机械工程制图|CAD装配图下载|SolidWorks_CaTia_CAD_UG_PROE_设计图分享下载上搜索。
1、以下程序是孙鑫老师编写的关于MFC 的按钮修饰的一个类,只要导入自己的程序就可以应用。下面介绍了具体如何操作。头文件:(将下面代码复制到文本文件内,然后改文件类型名为.h)#if !defined(AFX_WEIXINBUTTON_H_6A1ADB4D_B745_4F9B_B7BD_D0B151046A0A_INCLUDED_) #define AFX_WEIXINBUTTON_H_6A1ADB4D_B745_4F9B_B7BD_D0B151046A0A_INCLUDED_ #if _MSC_VER 1000 #pragma once #endif / _MSC_VER 1000 / SXBt
2、n.h : header file / / / CSXBtn window class CSXBtn : public CButton / Construction public: CSXBtn(); / Attributes public: / Operations public: / Overrides / ClassWizard generated virtual function overrides /AFX_VIRTUAL(CSXBtn) /AFX_VIRTUAL / Implementation public: void DrawItem(LPDRAWITEMSTRUCT lpDr
3、awItemStruct); virtual CSXBtn(); 名师资料总结 - - -精品资料欢迎下载 - - - - - - - - - - - - - - - - - - 名师精心整理 - - - - - - - 第 1 页,共 4 页 - - - - - - - - - / Generated message map functions protected: /AFX_MSG(CSXBtn) / NOTE - the ClassWizard will add and remove member functions here. /AFX_MSG DECLARE_MESSAGE_MAP(
4、) ; / /AFX_INSERT_LOCATION / Microsoft Visual C+ will insert additional declarations immediately before the previous line. #endif / !defined(AFX_WEIXINBUTTON_H_6A1ADB4D_B745_4F9B_B7BD_D0B151046A0A_INCLUDED_) 源文件:(将一下内容复制到文本文件,改文件类型名为.cpp)/ SXBtn.cpp : implementation file / #include stdafx.h #include
5、 Graphic.h #include SXBtn.h #ifdef _DEBUG #define new DEBUG_NEW #undef THIS_FILE static char THIS_FILE = _FILE_; #endif / / CSXBtn CSXBtn:CSXBtn() CSXBtn:CSXBtn() 名师资料总结 - - -精品资料欢迎下载 - - - - - - - - - - - - - - - - - - 名师精心整理 - - - - - - - 第 2 页,共 4 页 - - - - - - - - - BEGIN_MESSAGE_MAP(CSXBtn, CBu
6、tton) /AFX_MSG_MAP(CSXBtn) / NOTE - the ClassWizard will add and remove mapping macros here. /AFX_MSG_MAP END_MESSAGE_MAP() / / CSXBtn message handlers void CSXBtn:DrawItem(LPDRAWITEMSTRUCT lpDrawItemStruct) UINT uStyle = BS_DEFPUSHBUTTON ;/DFCS_BUTTONPUSH; / This code only works with buttons. ASSER
7、T(lpDrawItemStruct-CtlType = ODT_BUTTON); / If drawing selected, add the pushed style to DrawFrameControl. if (lpDrawItemStruct-itemState & ODS_SELECTED) uStyle |= DFCS_PUSHED; / Draw the button frame. :DrawFrameControl(lpDrawItemStruct-hDC, &lpDrawItemStruct-rcItem, DFC_BUTTON, uStyle); CDC* pDC =
8、CDC:FromHandle(lpDrawItemStruct-hDC); / Get the buttons text. CString strText; GetWindowText(strText); / Draw the button text using the text color red. CBrush B; CRect rect; CRect focusRect; focusRect.CopyRect(&lpDrawItemStruct-rcItem); DrawFocusRect(lpDrawItemStruct-hDC, (LPRECT)&focusRect); focusR
9、ect.left += 4; focusRect.right -= 4; focusRect.top += 4; focusRect.bottom -= 4; rect.CopyRect(&lpDrawItemStruct-rcItem); 名师资料总结 - - -精品资料欢迎下载 - - - - - - - - - - - - - - - - - - 名师精心整理 - - - - - - - 第 3 页,共 4 页 - - - - - - - - - pDC-Draw3dRect(rect, :GetSysColor(COLOR_BTNSHADOW), :GetSysColor(COLOR_
10、BTNHILIGHT); B.CreateSolidBrush(RGB(0,255,0); :FillRect(lpDrawItemStruct-hDC,&rect, (HBRUSH)B.m_hObject); :SetBkMode(lpDrawItemStruct-hDC,TRANSPARENT); COLORREF crOldColor = :SetTextColor(lpDrawItemStruct-hDC, RGB(255,0,0); :DrawText(lpDrawItemStruct-hDC, strText, strText.GetLength(), &lpDrawItemStruct-rcItem, DT_SINGLELINE|DT_VCENTER|DT_CENTER); :SetTextColor(lpDrawItemStruct-hDC, crOldColor); 将以上生成的两个文件,添加到工程目录下就可以了。http:/ - - -精品资料欢迎下载 - - - - - - - - - - - - - - - - - - 名师精心整理 - - - - - - - 第 4 页,共 4 页 - - - - - - - - -