CEdit & CStatic Transparency Control
来源:互联网 发布:淘宝店铺商品详情模板 编辑:程序博客网 时间:2024/05/21 17:45
CEdit & CStatic Transparency Control
6 Oct 2001 CPOL
, 29 votes) (
This acticle explain how to apply transparency on CEdit and CStatic Controls
- Download source files - 2.86 Kb
- Download demo project - 22.80 Kb
Introduction
To apply transparency on CEdit
control, create a new class derived from CEdit
control and simply add these members.
In the new class .h file add.
Collapse | Copy Code
// Attributesprivate: COLORREF m_TextColor; COLORREF m_BackColor; CBrush m_Brush; // Operationspublic: void SetTextColor(COLORREF col) { m_TextColor = col; UpdateCtrl(); } void SetBackColor(COLORREF col) { m_BackColor = col; UpdateCtrl(); }private: void UpdateCtrl(); // Generated message map functionsprotected: //{{AFX_MSG(CEditTrans) afx_msg HBRUSH CtlColor(CDC* pDC, UINT nCtlColor); afx_msg void OnUpdate(); afx_msg void OnLButtonDown(UINT nFlags, CPoint point); afx_msg void OnKillfocus(); //}}AFX_MSG DECLARE_MESSAGE_MAP()
In the new class .cpp file add.
Collapse | Copy Code
CEditTrans::CEditTrans(){ m_TextColor = RGB(0, 0, 0); m_BackColor = TRANS_BACK;}BEGIN_MESSAGE_MAP(CEditTrans, CEdit) //{{AFX_MSG_MAP(CEditTrans) ON_WM_CTLCOLOR_REFLECT() ON_CONTROL_REFLECT(EN_UPDATE, OnUpdate) ON_WM_LBUTTONDOWN() ON_CONTROL_REFLECT(EN_KILLFOCUS, OnKillfocus) //}}AFX_MSG_MAPEND_MESSAGE_MAP()HBRUSH CEditTrans::CtlColor(CDC* pDC, UINT nCtlColor) { m_Brush.DeleteObject(); if (m_BackColor == TRANS_BACK) { m_Brush.CreateStockObject(HOLLOW_BRUSH); pDC->SetBkMode(TRANSPARENT); } else { m_Brush.CreateSolidBrush(m_BackColor); pDC->SetBkColor(m_BackColor); } pDC->SetTextColor(m_TextColor); return (HBRUSH)m_Brush;}void CEditTrans::OnUpdate() { UpdateCtrl();}void CEditTrans::UpdateCtrl(){ CWnd* pParent = GetParent(); CRect rect; GetWindowRect(rect); pParent->ScreenToClient(rect); rect.DeflateRect(2, 2); pParent->InvalidateRect(rect, FALSE); }
Implementation of the class
Collapse | Copy Code
#include "EditTrans.h"//Derived control from ClassWizardCEditTrans m_edtTrans; //To make transparencym_edtTrans.SetBackColor(TRANS_BACK);
That all. Enjoy!
0 0
- CEdit & CStatic Transparency Control
- CStatic和CEdit
- MFC中的CEdit和CStatic
- Transparency
- cedit cstatic控件动态生成及字体大小改变
- MFC-自绘控件(CStatic与CEdit)
- CEdit control 读取一行的问题
- add CEdit control's command history
- CStatic
- CStatic
- CStatic
- CStatic
- cstatic
- CStatic
- WTL环境中CEdit或Cstatic控件中修改字体大小和颜色
- 一个有意思的CStatic和combobox以及Cedit控件结合使用
- CEdit
- CEdit
- BootStrap3如何禁止响应式布局
- Colorizing edit control
- Alibaba 原创FastJson工具
- 冒泡排序
- UVA 10700
- CEdit & CStatic Transparency Control
- 修改系统action bar字体大小、粗细、颜色等样式的方法
- UVA - 11039 Building designing
- CentOS6.6 更改官方源、增加第三方源、配置本地源
- AVL树
- 质变的数学模型/黑箱认识论
- 逻辑回归与梯度下降法
- Java原书第8版(第一章)
- msysgit的使用教程