VC 透明编辑框的实现
来源:互联网 发布:python查看版本 编辑:程序博客网 时间:2024/05/16 15:43
本方法对于背景为位图的对话框有效,其实也就是换了一种方式让编辑框相对于对话框是透明的,
把编辑框在当前对话框的位图给截取一部分出来用于填充编辑框
实现如下
派生一个CEdit的类,添加
CBitmap m_bmp;
CBrush m_brHollow;
添加WM_CTLCOLOR,WM_LBUTTONUP,EN_CHANGE,WM_ERASEBKGND响应消息
CMyEdit::CMyEdit()
{
m_brHollow.CreateStockObject(HOLLOW_BRUSH);
}
HBRUSH CMyEdit::CtlColor(CDC* pDC, UINT nCtlColor)
{
pDC->SetBkMode(TRANSPARENT);
pDC->SetTextColor(RGB(0,0,0));
return m_brHollow;
}
void CMyEdit::OnLButtonUp(UINT nFlags, CPoint point)
{
Invalidate();
CEdit::OnLButtonUp(nFlags, point);
}
void CMyEdit::OnChange()
{
Invalidate();
}
BOOL CMyEdit::OnEraseBkgnd(CDC* pDC)
{
BITMAP bm;
m_bmp.GetBitmap(&bm);
CDC dcMem;
dcMem.CreateCompatibleDC(pDC);
CRect rect;
CRect parentRect;
GetParent()->GetClientRect(&parentRect);
GetParent()->ClientToScreen(&parentRect);
GetClientRect(&rect);
ClientToScreen(&rect);
float prWidth = parentRect.Width(); //get dailog width
float ctWidth = rect.Width();; //get control width
float prHeight = parentRect.Height(); //get dailog height
float ctHeight = rect.Height(); //get control height
float Width = rect.left - parentRect.left;
float Height = rect.top - parentRect.top;
float tWidth = ctWidth/prWidth;//取得控件与对话框宽度的比值
float tHeight = ctHeight/prHeight;//取得控件与对话框高度的比值
//获取控制左上角点在位图中的相对位置
float tLeft = Width/prWidth;
float tTop = Height/prHeight;
dcMem.SelectObject(&m_bmp);
pDC->StretchBlt(0,0,
rect.Width(),
rect.Height(),
&dcMem,
(bm.bmWidth * tLeft),
(bm.bmHeight * tTop),
(bm.bmWidth * tWidth),
(bm.bmHeight * tHeight),
SRCCOPY);
return TRUE;
}
在对话框中添加编辑框的成员变量
m_xxx;
在OninitDialog里添加
m_xxx.m_bmp.LoadBitmap(IDB_BITMAP4);
::SendMessage(m_xxx.m_hWnd, WM_PAINT, NULL, NULL);
- VC 透明编辑框的实现
- VC 透明编辑框的实现
- CEdit编辑框透明的实现
- VC透明窗体的实现
- VC透明窗体的实现
- VC实现对话框的透明
- 透明的编辑框控件
- vc中透明窗体的实现!!
- VC透明位图的实现原理
- VC++实现透明窗体
- VC实现透明窗口
- VC实现具有回车移动焦点功能的编辑框
- 登录界面中透明编辑框的实现(测试平台WINCE 5.0)
- VC++中可编辑的CListCtrl实现
- VC++ 实现CEdit编辑框输入小数!
- VC 透明位图 实现透明位图类
- vc实现透明位图,透明背景
- vc实现透明位图,透明背景
- 修改C#编译器的环境变量
- XP + Fedora 9 + Ubuntu8.10 安装过程点滴
- 鱼眼effect
- 解决tomcat项目下的文件夹无法打开问题
- 装修省钱之道:一忌虚荣,二忌攀比.
- VC 透明编辑框的实现
- WM6天气预报程序的开发
- 雨夜网络音乐盒
- J2ME介绍
- blog整理说明
- 超级推荐!!值得收藏的黑客系列书:《黑客攻防实战xx》系列图书简介,一共4本
- 近期Sql心得
- 排列组合-打印出一个数组的元素的所有排列方式-算法
- Xfire的aegis绑定方式配置小结