MFC CStatic控件自绘,背景透明。
来源:互联网 发布:thinkpad怎么样知乎 编辑:程序博客网 时间:2024/06/04 19:30
#define TrackControl_h__
template <class BaseClass>
class CTrackControl : public BaseClass
{
public:
CTrackControl()
{
m_bTracking = m_bHover = false;
}
virtual ~CTrackControl() {}
bool IsHover() { return m_bHover; }
bool IsFocus() { return m_bFoucs; }
virtual LRESULT WindowProc (UINT message, WPARAM wParam, LPARAM lParam)
{
switch (message)
{
case WM_MOUSEMOVE:
{
if (!m_bTracking)
{
m_bTracking = !m_bTracking;
TRACKMOUSEEVENT TrackEvent;
TrackEvent.cbSize = sizeof (TrackEvent);
TrackEvent.hwndTrack = m_hWnd;
TrackEvent.dwFlags = TME_LEAVE;// | TME_HOVER;
TrackEvent.dwHoverTime = 0;
_TrackMouseEvent (&TrackEvent);
m_bHover = true;
OnEventMouseEnter();
}
}
break;
case WM_MOUSELEAVE:
{
m_bTracking = m_bHover = m_bFoucs = false;
OnEventMouseLeave();
}
break;
case WM_SETFOCUS:
{
m_bFoucs = true;
OnEventSetFocus();
} break;
case WM_KILLFOCUS:
{
m_bFoucs = false;
OnEventKillFocus();
} break;
}
return __super::WindowProc (message, wParam, lParam);
}
protected:
virtual void OnEventMouseEnter() = NULL;
virtual void OnEventMouseLeave() = NULL;
virtual void OnEventSetFocus() {}
virtual void OnEventKillFocus() {}
protected:
bool m_bFoucs;
bool m_bHover;
bool m_bTracking;
};
#endif // TrackControl_h__
#ifndef SkinStatic_h__
#define SkinStatic_h__
#include "ShareControl.h"
#include "TrackControl.h"
#include "HelperTool.h"
// CSkinStatic
class SHARE_CONTROL_CLASS CSkinStatic : public CTrackControl<CStatic>
{
DECLARE_DYNAMIC(CSkinStatic)
protected:
COLORREF m_clrNormalText;
COLORREF m_clrHotText;
public:
CSkinStatic();
virtual ~CSkinStatic();
protected:
virtual void PreSubclassWindow();
protected:
virtual void OnEventMouseEnter();
virtual void OnEventMouseLeave();
public:
void SetWindowText(LPCTSTR lpString);
void RefreshStatic();
public:
afx_msg HBRUSH CtlColor(CDC* pDC, UINT /*nCtlColor*/);
afx_msg BOOL OnEraseBkgnd(CDC* pDC);
DECLARE_MESSAGE_MAP()
};
#endif // SkinStatic_h__
// SkinStatic.cpp : implementation file
//
#include "stdafx.h"
#include "SkinStatic.h"
// CSkinStatic
IMPLEMENT_DYNAMIC(CSkinStatic, CStatic)
CSkinStatic::CSkinStatic()
{
m_clrNormalText = RGB(255, 140, 0);
m_clrHotText = RGB(0, 0, 255);
}
CSkinStatic::~CSkinStatic()
{
}
BEGIN_MESSAGE_MAP(CSkinStatic, CStatic)
ON_WM_CTLCOLOR_REFLECT()
ON_WM_ERASEBKGND()
END_MESSAGE_MAP()
// CSkinStatic message handlers
HBRUSH CSkinStatic::CtlColor(CDC* pDC, UINT /*nCtlColor*/)
{
pDC->SetBkMode(TRANSPARENT);
if (IsHover())
{
pDC->SetTextColor(m_clrHotText);
}
else
{
pDC->SetTextColor(m_clrNormalText);
}
return (HBRUSH)::GetStockObject(NULL_BRUSH);
}
BOOL CSkinStatic::OnEraseBkgnd(CDC* pDC)
{
return TRUE;
return CStatic::OnEraseBkgnd(pDC);
}
void CSkinStatic::SetWindowText(LPCTSTR lpString)
{
__super::SetWindowText(lpString);
RefreshStatic();
}
void CSkinStatic::OnEventMouseEnter()
{
RefreshStatic();
}
void CSkinStatic::OnEventMouseLeave()
{
RefreshStatic();
}
void CSkinStatic::RefreshStatic()
{
CWindowRect rcWindow(this->m_hWnd);
GetParent()->ScreenToClient(rcWindow);
GetParent()->InvalidateRect(rcWindow);
}
void CSkinStatic::PreSubclassWindow()
{
ModifyStyle(0, GetStyle() | SS_NOTIFY);
CTrackControl<CStatic>::PreSubclassWindow();
}
- MFC CStatic控件自绘,背景透明。
- 设置Cstatic控件背景透明
- 自绘控件背景透明
- CStatic控件背景透明实例代码
- 自绘CStatic控件
- CStatic控件自绘
- MFC CStatic控件在DrawItem中自绘
- MFC-自绘控件(CStatic与CEdit)
- MFC CStatic控件在DrawItem中自绘
- Cstatic背景透明
- MFC设置控件背景透明
- 利用 CStatic 开发自绘控件
- 自绘的CStatic控件自动换行
- MFC CStatic 透明重绘 使用双缓冲
- 使static控件背景透明(MFC)
- MFC 背景贴图及控件透明
- vs2010 MFC设置控件背景透明
- MFC-控件-标签-设置背景透明
- 【Oracle】-【show_space和show_space_asm】-执行存储过程show_space和show_space_asm报错
- android应用程序安装位置android:installLocation翻译
- 为什么计算机和一些电子产品的时间选择在1970.1.1
- Android LayoutInflater的使用
- 用户空间和内核空间的详解
- MFC CStatic控件自绘,背景透明。
- MySQL学习笔记 第五讲:实体和外键
- 测试一个应用程序的兼容性
- URL收藏
- Opencv之点线面(c++版)
- 二叉树遍历
- 计算几何之基础知识及例题
- int、long、float、double最大最小值
- android 用GridVew实现表格功能Sample