CMyButton类----功能---- 鼠标经过此按钮时,按钮改变颜色
来源:互联网 发布:宏编程左键双击录制 编辑:程序博客网 时间:2024/04/30 07:19
MyButton.h
#if !defined(AFX_MYBUTTON_H__10CEB9E1_11F9_11D4_A2EA_0048543D92F7__INCLUDED_)#define AFX_MYBUTTON_H__10CEB9E1_11F9_11D4_A2EA_0048543D92F7__INCLUDED_#if _MSC_VER > 1000#pragma once#endif // _MSC_VER > 1000// MyButton.h : header file///////////////////////////////////////////////////////////////////////////////// CMyButton windowclass CMyButton : public CButton{// Constructionpublic:CMyButton();// Attributespublic: BOOL m_bOverControl; UINT m_nTimerID;// Operationspublic:// Overrides// ClassWizard generated virtual function overrides//{{AFX_VIRTUAL(CMyButton)public:virtual void DrawItem(LPDRAWITEMSTRUCT lpDrawItemStruct);protected:virtual void PreSubclassWindow();//}}AFX_VIRTUAL// Implementationpublic:virtual ~CMyButton();// Generated message map functionsprotected://{{AFX_MSG(CMyButton)afx_msg void OnMouseMove(UINT nFlags, CPoint point);afx_msg void OnTimer(UINT nIDEvent);//}}AFX_MSGDECLARE_MESSAGE_MAP()};///////////////////////////////////////////////////////////////////////////////{{AFX_INSERT_LOCATION}}// Microsoft Visual C++ will insert additional declarations immediately before the previous line.#endif // !defined(AFX_MYBUTTON_H__10CEB9E1_11F9_11D4_A2EA_0048543D92F7__INCLUDED_)
MyButton.cpp
// MyButton.cpp : implementation file//#include "stdafx.h"#include "MyButton.h"#ifdef _DEBUG#define new DEBUG_NEW#undef THIS_FILEstatic char THIS_FILE[] = __FILE__;#endif/////////////////////////////////////////////////////////////////////////////// CMyButtonCMyButton::CMyButton(){ m_bOverControl = FALSE; m_nTimerID = 1;}CMyButton::~CMyButton(){}BEGIN_MESSAGE_MAP(CMyButton, CButton)//{{AFX_MSG_MAP(CMyButton)ON_WM_MOUSEMOVE()ON_WM_TIMER()//}}AFX_MSG_MAPEND_MESSAGE_MAP()/////////////////////////////////////////////////////////////////////////////// CMyButton message handlersvoid CMyButton::OnMouseMove(UINT nFlags, CPoint point) { if (!m_bOverControl) // Cursor has just moved over control { TRACE0("Entering control\n"); m_bOverControl = TRUE;// Set flag telling us the mouse is in Invalidate(); // Force a redraw SetTimer(m_nTimerID, 100, NULL); // Keep checking back every 1/10 sec }CButton::OnMouseMove(nFlags, point); // drop through to default handler}void CMyButton::OnTimer(UINT nIDEvent) { // Where is the mouse? CPoint p(GetMessagePos()); ScreenToClient(&p); // Get the bounds of the control (just the client area) CRect rect; GetClientRect(rect); // Check the mouse is inside the control if (!rect.PtInRect(p)) { TRACE0("Leaving control\n"); // if not then stop looking... m_bOverControl = FALSE; KillTimer(m_nTimerID); // ...and redraw the control Invalidate(); }// drop through to default handlerCButton::OnTimer(nIDEvent);}void CMyButton::DrawItem(LPDRAWITEMSTRUCT lpDrawItemStruct) {CDC* pDC = CDC::FromHandle(lpDrawItemStruct->hDC);CRect rect = lpDrawItemStruct->rcItem;UINT state = lpDrawItemStruct->itemState;CString strText;GetWindowText(strText); // draw the control edges (DrawFrameControl is handy!)if (state & ODS_SELECTED) pDC->DrawFrameControl(rect, DFC_BUTTON, DFCS_BUTTONPUSH | DFCS_PUSHED); else pDC->DrawFrameControl(rect, DFC_BUTTON, DFCS_BUTTONPUSH); // Fill the interior color if necessary rect.DeflateRect( CSize(GetSystemMetrics(SM_CXEDGE), GetSystemMetrics(SM_CYEDGE))); if (m_bOverControl) pDC->FillSolidRect(rect, RGB(233, 233, 0)); // yellow // Draw the text if (!strText.IsEmpty()) { CSize Extent = pDC->GetTextExtent(strText);CPoint pt( rect.CenterPoint().x - Extent.cx/2, rect.CenterPoint().y - Extent.cy/2 );if (state & ODS_SELECTED) pt.Offset(1,1);int nMode = pDC->SetBkMode(TRANSPARENT);if (state & ODS_DISABLED)pDC->DrawState(pt, Extent, strText, DSS_DISABLED, TRUE, 0, (HBRUSH)NULL);elsepDC->TextOut(pt.x, pt.y, strText); pDC->SetBkMode(nMode); }}void CMyButton::PreSubclassWindow() {CButton::PreSubclassWindow();ModifyStyle(0, BS_OWNERDRAW);// make the button owner drawn}
- CMyButton类----功能---- 鼠标经过此按钮时,按钮改变颜色
- 四态按钮CMyButton类
- Javascript实现鼠标经过改变按钮
- 如何使鼠标经过按钮时按钮的图像发生改变
- 鼠标经过时,改变表格背景颜色
- 改变按钮的背景颜色和鼠标在按钮上时指针的样子
- VC中鼠标经过按钮弹出功能提示(TIPS)
- VC中鼠标经过按钮弹出功能提示(TIPS)
- QT之鼠标滑过按钮,按钮改变颜色,离开之后,按钮恢复原先颜色
- 自定义按钮CMyButton与subclassing
- gridview 鼠标经过改变颜色
- CSS 鼠标经过改变颜色
- WinForm 鼠标经过按钮 按钮抖动一下
- MFC/vc中当鼠标经过按钮等控件时出现文字提示功能
- MFC/VC中当鼠标经过按钮等控件时出现文字提示功能
- MFC/vc中当鼠标经过按钮等控件时出现文字提示功能
- 按钮改变文字大小颜色
- 鼠标放按钮上去背景(颜色图片改变)
- V$SESSION
- 在Linux操作系统下修改IP、DNS和路由配置
- Linux常用的postfix命令
- SQL 优化,值得收藏
- Python 使用 subprocess 调用外部命令
- CMyButton类----功能---- 鼠标经过此按钮时,按钮改变颜色
- 那爱小小的、很美
- php 使用 ffmpeg 转换视频,截图,并生成缩略图
- 关于tty,ppy和console
- Linux下的pthread_cond_t变量的部分使用
- 周边知识获取的价值
- 关于工具编译asm文件产生unresolved external symbol _WinMainCRTStartup错误的解决方法
- gcc下static 、 shared 与 dynamically loaded动态库详解
- C#正则表达式(RegEx)高级应用之分组(Group)替换(Replace)