版權(quán)說明:本文檔由用戶提供并上傳,收益歸屬內(nèi)容提供方,若內(nèi)容存在侵權(quán),請(qǐng)進(jìn)行舉報(bào)或認(rèn)領(lǐng)
文檔簡(jiǎn)介
1、改變CButton背景顏(繪CButton)-VC(轉(zhuǎn))這是個(gè)實(shí)現(xiàn)繪CButton的類,期望對(duì)家有點(diǎn)幫助,我提供這個(gè)類,只是為家提供個(gè)繪控件的思路,你可以在此基礎(chǔ)上,隨意地修改代碼,直到它能完成你所需要的功能.其它控件的繪,原理了和這個(gè)差不多.#if !defined(AFX_BUTTONST_H_1271FF9C_E28C_4D3B_B429_AFE65924A5D0_INCLUDED_)#define AFX_BUTTONST_H_1271FF9C_E28C_4D3B_B429_AFE65924A5D0_INCLUDED_#if _MSC_VER 1000#pragma once#endi
2、f / _MSC_VER 1000/ ButtonST.h : header file/ CButtonST windowclass CButtonST : public CButton/ Constructionpublic:CButtonST();/ Attributespublic:/ Operationspublic:/設(shè)置背景顏void SetBkColor(COLORREF BkColor);/設(shè)置標(biāo)在按鈕上的偏移顏void SetShOffset(int nShOffset);/設(shè)置字體顏void SetTextColor(COLORREF TextColor);/設(shè)置頁鏈接vo
3、id SetURL(CString strURL);/設(shè)置背景圖void SetBkPicture(CBitmap *pBitMap);/ Overrides/ ClassWizard generated virtual function overrides/AFX_VIRTUAL(CButtonST)public:virtual void DrawItem(LPDRAWITEMSTRUCT lpDrawItemStruct);virtual BOOL Create(LPCTSTR lpszClassName, LPCTSTR lpszWindowName, DWORD dwStyle, co
4、nst RECT& rect, CWnd*pParentWnd, UINT nID, CCreateContext* pContext = NULL);protected:virtual BOOL PreCreateWindow(CREATESTRUCT& cs);virtual void PreSubclassWindow();/AFX_VIRTUAL/ Implementationpublic:virtual CButtonST();void DrawItem1(LPDRAWITEMSTRUCT lpDrawItemStruct);/ Generated message map funct
5、ionsprotected:/AFX_MSG(CButtonST)afx_msg void OnMouseMove(UINT nFlags, CPoint point);afx_msg BOOL OnNcActivate(BOOL bActive);afx_msg void OnNcMouseMove(UINT nHitTest, CPoint point);afx_msg void OnKillFocus(CWnd* pNewWnd);afx_msg void OnLButtonDown(UINT nFlags, CPoint point);/AFX_MSGprotected:/標(biāo)是否在按鈕
6、上BOOL m_IsPressed;COLORREF m_BkColor;int m_nShOffset;COLORREF m_TextColor;CString m_strURL;CBitmap *m_pBitMapBK;protected:/背景顏偏移COLORREF OffsetColor(COLORREF color,int nOffset);/標(biāo)離開LRESULT OnMouseLeave(WPARAM wParam, LPARAM lParam);DECLARE_MESSAGE_MAP();/AFX_INSERT_LOCATION/ Microsoft Visual C+ will
7、 insert additional declarations immediately before the previous line.#endif / !defined(AFX_BUTTONST_H_1271FF9C_E28C_4D3B_B429_AFE65924A5D0_INCLUDED_)/ ButtonST.cpp : implementation file/#include stdafx.h#include ContrlST.h#include ButtonST.h#ifdef _DEBUG#define new DEBUG_NEW#undef THIS_FILEstatic ch
8、ar THIS_FILE = _FILE_;#endif#define BS_TYPEMASK SS_TYPEMASK/ CButtonSTCButtonST:CButtonST()m_IsPressed = FALSE;m_BkColor = RGB(216,233,216);m_nShOffset = 30;m_TextColor = RGB(0,0,0);m_strURL = ;m_pBitMapBK = NULL;CButtonST:CButtonST()if(m_pBitMapBK!=NULL)delete m_pBitMapBK;m_pBitMapBK = NULL;BEGIN_M
9、ESSAGE_MAP(CButtonST, CButton)/AFX_MSG_MAP(CButtonST)ON_WM_MOUSEMOVE()ON_WM_NCACTIVATE()ON_WM_NCMOUSEMOVE()ON_WM_KILLFOCUS()ON_MESSAGE(WM_MOUSELEAVE, OnMouseLeave)ON_WM_LBUTTONDOWN()/AFX_MSG_MAPEND_MESSAGE_MAP()/ CButtonST message handlers/設(shè)置背景顏void CButtonST:SetBkColor(COLORREF BkColor)m_BkColor =
10、BkColor;this-Invalidate();/設(shè)置標(biāo)在按鈕上的偏移顏void CButtonST:SetShOffset(int nShOffset)m_nShOffset = nShOffset;this-Invalidate();/設(shè)置字體顏void CButtonST:SetTextColor(COLORREF TextColor)m_TextColor = TextColor;this-Invalidate();/設(shè)置頁鏈接void CButtonST:SetURL(CString strURL)m_strURL = strURL;/設(shè)置背景圖void CButtonST:Se
11、tBkPicture(CBitmap *pBitMap)if(m_pBitMapBK=pBitMap)return;if(m_pBitMapBK!=NULL)delete m_pBitMapBK;m_pBitMapBK = pBitMap;m_pBitMapBK = pBitMap;this-Invalidate();/背景顏偏移COLORREF CButtonST:OffsetColor(COLORREF color,int nOffset)BYTE byRed = 0;BYTE byGreen = 0;BYTE byBlue = 0;short shOffsetR = nOffset;sh
12、ort shOffsetG = nOffset;short shOffsetB = nOffset;if (nOffset 255)nOffset = 30;/ Get RGB components of specified colorbyRed = GetRValue(color);byGreen = GetGValue(color);byBlue = GetBValue(color);/ Calculate max. allowed real offsetif (nOffset 0)if (byRed + nOffset 255) shOffsetR = 255 - byRed;if (b
13、yGreen + nOffset 255) shOffsetG = 255 - byGreen;if (byBlue + nOffset 255) shOffsetB = 255 - byBlue;nOffset = min(min(shOffsetR, shOffsetG), shOffsetB);elseif (byRed + nOffset 0) shOffsetR = -byRed;if (byGreen + nOffset 0) shOffsetG = -byGreen;if (byBlue + nOffset hDC);CRect rect = lpDrawItemStruct-r
14、cItem;CRect offRect = rect;int ndist = 2;offRect.left+= ndist;offRect.right -=ndist;offRect.top += ndist;offRect.bottom -=ndist;pDC-SetBkMode(TRANSPARENT);pDC-SetTextColor(m_TextColor);/繪制背景if(m_pBitMapBK!=NULL)CDC* pNewDC = new CDC;pNewDC-CreateCompatibleDC(pDC);pNewDC-SelectObject(m_pBitMapBK);BIT
15、MAP bmp;m_pBitMapBK-GetBitmap(&bmp);if(m_IsPressed)pDC-StretchBlt(0,0,rect.Width(),rect.Height(),pNewDC,0,0,bmp.bmWidth,bmp.bmHeight,SRCCOPY);elseCBrush brush(RGB(220,220,220);/RGB(m_nShOffset,m_nShOffset,m_nShOffset);pDC-FillRect(&rect,&brush);pDC-StretchBlt(0,0,rect.Width(),rect.Height(),pNewDC,0,
16、0,bmp.bmWidth,bmp.bmHeight,SRCAND);delete pNewDC;pNewDC = NULL;elseif(m_IsPressed)CBrush brush(OffsetColor(m_BkColor,m_nShOffset);pDC-FillRect(rect,&brush);CBrush brush1(RGB(128,128,128);pDC-FrameRect(rect,&brush1);pDC-FrameRect(offRect,&brush1);elseCBrush brush(m_BkColor);pDC-FillRect(rect,&brush);
17、CBrush brush1(RGB(128,128,128);pDC-FrameRect(offRect,&brush1);pDC-FrameRect(offRect,&brush1);CString sTitle;GetWindowText(sTitle);offRect.OffsetRect(0,rect.Height()/2-8);/ pDC-DrawText(sTitle, sTitle.GetLength(),offRect, DT_WORDBREAK | DT_CENTER);pDC-DrawText(sTitle, sTitle.GetLength(),offRect, DT_W
18、ORDBREAK|DT_CENTER);void CButtonST:DrawItem(LPDRAWITEMSTRUCT lpDrawItemStruct)/ TODO: Add your code to draw the specified itemDrawItem1(lpDrawItemStruct);return;CDC* pDC = CDC:FromHandle(lpDrawItemStruct-hDC);CRect rect = lpDrawItemStruct-rcItem;CRect offRect = rect;int ndist = 2;offRect.left+= ndis
19、t;offRect.right -=ndist;offRect.top += ndist;offRect.bottom -=ndist;CDC* pResetDC=new CDC();pResetDC-CreateCompatibleDC(pDC);CBitmap bitmap;bitmap.CreateCompatibleBitmap(pDC,rect.Width(),rect.Height();pResetDC-SelectObject(&bitmap);pResetDC-SetBkMode(TRANSPARENT);pResetDC-SetTextColor(m_TextColor);/
20、繪制背景if(m_pBitMapBK!=NULL)CDC* pNewDC = new CDC;pNewDC-CreateCompatibleDC(pResetDC);pNewDC-SelectObject(m_pBitMapBK);BITMAP bmp;m_pBitMapBK-GetBitmap(&bmp);if(m_IsPressed)pResetDC-StretchBlt(0,0,rect.Width(),rect.Height(),pNewDC,0,0,bmp.bmWidth,bmp.bmHeight,SRCCOPY);elseCBrush brush(RGB(220,220,220);
21、/RGB(m_nShOffset,m_nShOffset,m_nShOffset);pResetDC-FillRect(&rect,&brush);pResetDC-StretchBlt(0,0,rect.Width(),rect.Height(),pNewDC,0,0,bmp.bmWidth,bmp.bmHeight,SRCAND);delete pNewDC;pNewDC = NULL;elseif(m_IsPressed)CBrush brush(OffsetColor(m_BkColor,m_nShOffset);pResetDC-FillRect(rect,&brush);CBrus
22、h brush1(RGB(128,128,128);pResetDC-FrameRect(rect,&brush1);pResetDC-FrameRect(offRect,&brush1);elseCBrush brush(m_BkColor);pResetDC-FillRect(rect,&brush);CBrush brush1(RGB(128,128,128);pResetDC-FrameRect(offRect,&brush1);CString sTitle;GetWindowText(sTitle);offRect.OffsetRect(0,rect.Height()/2-8);/
23、pDC-DrawText(sTitle, sTitle.GetLength(),offRect, DT_WORDBREAK | DT_CENTER);pResetDC-DrawText(sTitle, sTitle.GetLength(),offRect, DT_CENTER);pDC-StretchBlt(0,0,rect.Width(),rect.Height(),pResetDC,0,0,rect.Width(),rect.Height(),SRCCOPY);delete pResetDC;void CButtonST:OnMouseMove(UINT nFlags, CPoint po
24、int)/ TODO: Add your message handler code here and/or call defaultTRACKMOUSEEVENT csTME;csTME.cbSize = sizeof(csTME);csTME.dwFlags = TME_LEAVE;csTME.hwndTrack = m_hWnd;:_TrackMouseEvent(&csTME);if(m_IsPressed=FALSE)m_IsPressed = TRUE;this-Invalidate();CButton:OnMouseMove(nFlags, point);BOOL CButtonS
25、T:OnNcActivate(BOOL bActive)/ TODO: Add your message handler code here and/or call defaultreturn CButton:OnNcActivate(bActive);void CButtonST:OnNcMouseMove(UINT nHitTest, CPoint point)/ TODO: Add your message handler code here and/or call defaultCButton:OnNcMouseMove(nHitTest, point);void CButtonST:
26、OnKillFocus(CWnd* pNewWnd)CButton:OnKillFocus(pNewWnd);/ TODO: Add your message handler code hereLRESULT CButtonST:OnMouseLeave(WPARAM wParam, LPARAM lParam)m_IsPressed = FALSE;this-Invalidate();return 0; / End of OnMouseLeaveBOOL CButtonST:Create(LPCTSTR lpszClassName, LPCTSTR lpszWindowName, DWORD dwStyle, const RECT& rect,CWnd* pParentWnd, UINT nID, CCreateContext* pContext)/ TODO: Add your specialized code here and/or c
溫馨提示
- 1. 本站所有資源如無特殊說明,都需要本地電腦安裝OFFICE2007和PDF閱讀器。圖紙軟件為CAD,CAXA,PROE,UG,SolidWorks等.壓縮文件請(qǐng)下載最新的WinRAR軟件解壓。
- 2. 本站的文檔不包含任何第三方提供的附件圖紙等,如果需要附件,請(qǐng)聯(lián)系上傳者。文件的所有權(quán)益歸上傳用戶所有。
- 3. 本站RAR壓縮包中若帶圖紙,網(wǎng)頁內(nèi)容里面會(huì)有圖紙預(yù)覽,若沒有圖紙預(yù)覽就沒有圖紙。
- 4. 未經(jīng)權(quán)益所有人同意不得將文件中的內(nèi)容挪作商業(yè)或盈利用途。
- 5. 人人文庫網(wǎng)僅提供信息存儲(chǔ)空間,僅對(duì)用戶上傳內(nèi)容的表現(xiàn)方式做保護(hù)處理,對(duì)用戶上傳分享的文檔內(nèi)容本身不做任何修改或編輯,并不能對(duì)任何下載內(nèi)容負(fù)責(zé)。
- 6. 下載文件中如有侵權(quán)或不適當(dāng)內(nèi)容,請(qǐng)與我們聯(lián)系,我們立即糾正。
- 7. 本站不保證下載資源的準(zhǔn)確性、安全性和完整性, 同時(shí)也不承擔(dān)用戶因使用這些下載資源對(duì)自己和他人造成任何形式的傷害或損失。
最新文檔
- 二零二五年重型機(jī)械焊接安裝服務(wù)協(xié)議3篇
- 2025年度二手房交易首付分期及風(fēng)險(xiǎn)控制協(xié)議4篇
- 2025年度防火門檢測(cè)維修服務(wù)合同4篇
- 2025版協(xié)議離婚實(shí)操教程與全程輔導(dǎo)合同3篇
- 2025年個(gè)人房產(chǎn)測(cè)繪與房地產(chǎn)市場(chǎng)調(diào)研合同4篇
- 2025版臨時(shí)演出場(chǎng)地租賃協(xié)議書3篇
- 2025年度綠色環(huán)保項(xiàng)目臨時(shí)工勞動(dòng)合同范本8篇
- 個(gè)人家政服務(wù)合同2024年度專用3篇
- 2025年度智慧城市基礎(chǔ)設(shè)施場(chǎng)外工程承包合同4篇
- 2025年度物業(yè)設(shè)施設(shè)備智能化升級(jí)合同3篇
- 2025年生產(chǎn)主管年度工作計(jì)劃
- 2024-2025學(xué)年山東省聊城市高一上學(xué)期期末數(shù)學(xué)教學(xué)質(zhì)量檢測(cè)試題(附解析)
- 西方史學(xué)史課件3教學(xué)
- 2024年中國醫(yī)藥研發(fā)藍(lán)皮書
- 廣東省佛山市 2023-2024學(xué)年五年級(jí)(上)期末數(shù)學(xué)試卷
- 臺(tái)兒莊介紹課件
- 人工智能算法與實(shí)踐-第16章 LSTM神經(jīng)網(wǎng)絡(luò)
- 17個(gè)崗位安全操作規(guī)程手冊(cè)
- 2025年山東省濟(jì)南市第一中學(xué)高三下學(xué)期期末統(tǒng)一考試物理試題含解析
- 中學(xué)安全辦2024-2025學(xué)年工作計(jì)劃
- 網(wǎng)絡(luò)安全保障服務(wù)方案(網(wǎng)絡(luò)安全運(yùn)維、重保服務(wù))
評(píng)論
0/150
提交評(píng)論