




版權說明:本文檔由用戶提供并上傳,收益歸屬內容提供方,若內容存在侵權,請進行舉報或認領
文檔簡介
1、 VC+ 2010中實現(xiàn)自定義窗口按鈕控件1. 新建一個MFC類使得它繼承與CButton類;2.32.在生成的類中添加變量#pragma once/ CCustomButtonclass CCustomButton : public CButtonDECLARE_DYNAMIC(CCustomButton)public:CCustomButton();virtual CCustomButton();BOOL m_IsPressed;protected:DECLARE_MESSAGE_MAP()public:virtual void DrawItem(LPDRAWITEMSTRUCT /*lp
2、DrawItemStruct*/);afx_msg void OnLButtonUp(UINT nFlags, CPoint point);afx_msg void OnLButtonDown(UINT nFlags, CPoint point);afx_msg BOOL OnEraseBkgnd(CDC* pDC);3.。重寫方法WM_BUTTONDOWN WM_LBUTTONUP / CustomButton.cpp : 實現(xiàn)文件/#include "stdafx.h"#include "just test.h"#include "Cust
3、omButton.h"/ CCustomButtonIMPLEMENT_DYNAMIC(CCustomButton, CButton)CCustomButton:CCustomButton()CCustomButton:CCustomButton()BEGIN_MESSAGE_MAP(CCustomButton, CButton)ON_WM_LBUTTONUP()ON_WM_LBUTTONDOWN()ON_WM_ERASEBKGND()END_MESSAGE_MAP()/ CCustomButton 消息處理程序void CCustomButton:DrawItem(LPDRAWIT
4、EMSTRUCT lpDrawItemStruct)CRect rect;GetClientRect(rect);CDC dc;dc.Attach(lpDrawItemStruct->hDC);dc.SetBkMode(TRANSPARENT);CBrush m_Brush;m_Brush.CreateStockObject(NULL_BRUSH);dc.SelectObject(&m_Brush);if(m_IsPressed)CPen pen(PS_SOLID,2,RGB(255,2,0);dc.SelectObject(&pen);HRGN rgn = Create
5、EllipticRgn(0,0,rect.Width(),rect.Height();SetWindowRgn(rgn,TRUE);dc.Ellipse(0,0,rect.Width(),rect.Height();dc.SetTextColor(RGB(0,0,255);elseCPen pen(PS_SOLID,2,RGB(5,255,0);dc.SelectObject(&pen);HRGN rgn = CreateEllipticRgn(0,0,rect.Width(),rect.Height();SetWindowRgn(rgn,TRUE);dc.Ellipse(0,0,re
6、ct.Width(),rect.Height();dc.SetTextColor(RGB(120,0,190);CString str;GetWindowText(str);dc.DrawText(str,CRect(0,0,rect.Width(),rect.Height(),DT_CENTER|DT_VCENTER|DT_SINGLELINE);/ TODO: 添加您的代碼以繪制指定項void CCustomButton:OnLButtonUp(UINT nFlags, CPoint point)/ TODO: 在此添加消息處理程序代碼和/或調用默認值m_IsPressed = FALSE;CButton:OnLButtonUp(nFlags, point);void CCustomButton:OnLButtonDown(UINT nFlags, CPoint point)/ TODO: 在此添加消息處理程序代碼和/或調用默認值m_IsPressed = TRUE;CButton:OnLButtonDown(nFlags, point);BOOL CCustomButton:OnEraseBkgnd(CDC* pDC)/ TODO: 在此添加消息處理程序代碼和/
溫馨提示
- 1. 本站所有資源如無特殊說明,都需要本地電腦安裝OFFICE2007和PDF閱讀器。圖紙軟件為CAD,CAXA,PROE,UG,SolidWorks等.壓縮文件請下載最新的WinRAR軟件解壓。
- 2. 本站的文檔不包含任何第三方提供的附件圖紙等,如果需要附件,請聯(lián)系上傳者。文件的所有權益歸上傳用戶所有。
- 3. 本站RAR壓縮包中若帶圖紙,網(wǎng)頁內容里面會有圖紙預覽,若沒有圖紙預覽就沒有圖紙。
- 4. 未經(jīng)權益所有人同意不得將文件中的內容挪作商業(yè)或盈利用途。
- 5. 人人文庫網(wǎng)僅提供信息存儲空間,僅對用戶上傳內容的表現(xiàn)方式做保護處理,對用戶上傳分享的文檔內容本身不做任何修改或編輯,并不能對任何下載內容負責。
- 6. 下載文件中如有侵權或不適當內容,請與我們聯(lián)系,我們立即糾正。
- 7. 本站不保證下載資源的準確性、安全性和完整性, 同時也不承擔用戶因使用這些下載資源對自己和他人造成任何形式的傷害或損失。
最新文檔
- 個人與醫(yī)院合同范本
- 我國體育非遺保護與傳承的有效路徑
- 辦公樓員工合同范本
- 前期土地出租合同范本
- 2025年江蘇省建筑安全員-A證考試題庫及答案
- 勞動技術合同范例
- 產業(yè)園管護合同范本
- 個人銷售紅酒合同范本
- 個人造價合同范本
- 占用土地承包合同范例
- 書法全冊教案
- 建筑工程質量管理培訓
- 2024全新《婚姻法》精美課件
- 《毛毛》讀書會說課
- 華文版六年級上冊書法教案
- 基礎、主體、裝飾裝修階段檢驗、驗收計劃表-
- 胎兒附屬物課件
- 2025年4月自考15040習概押題及答案
- 2025年高考英語復習專項突破:讀后續(xù)寫提分寫作(解析版)
- iso13485:醫(yī)療器械質量管理體系標準
- 第六單元測試卷(單元卷)-2024-2025學年語文二年級上冊統(tǒng)編版
評論
0/150
提交評論