透明窗体覆盖在视频上画图
2016-05-19 17:41
344 查看
原本是想在显示图像的地方直接画需要的图形,最后发现显示图像的地方在dll中,没有源码,只能够另辟他径了。 于是有了下面想法: *在窗口上覆盖一个透明窗口,然后对透明窗口进行绘图。根据需要对透明窗口进行刷新重绘。 全部代码上传csdn (还有鼠标点哪(透明窗体范围内),就在哪画图)
代码链接http://download.csdn.net/detail/xuleisdjn/9525884
下面代码是其中部分代码。
*下面是基本流程和基本代码:
1透明窗体创建
Insert DialogBorder :None
ID:IDD_DIALOG1
class:TopLayerdlg
初始化设置透明
BOOL TopLayerdlg::OnInitDialog() { CDialogEx::OnInitDialog(); // TODO: Add extra initialization here SetWindowLong(this->GetSafeHwnd(), GWL_EXSTYLE, GetWindowLong(this->GetSafeHwnd(), GWL_EXSTYLE)^WS_EX_LAYERED); COLORREF clr = RGB(255,255,255); SetLayeredWindowAttributes( clr, 128, LWA_COLORKEY);//LWA_COLORKEY LWA_ALPHA return TRUE; // return TRUE unless you set the focus to a control // EXCEPTION: OCX Property Pages should return FALSE }
画图处
例如在点(100,100)处画一个十字图形
void TopLayerdlg::OnPaint() { CPaintDC dc(this); // device context for painting // TODO: Add your message handler code here // Do not call CDialogEx::OnPaint() for painting messages //SetBackgroundColor(RGB(255,255,255)); CRect rect; GetClientRect(&rect); CBrush bs; bs.CreateSolidBrush(RGB(255,255,255)); dc.FillRect(rect,&bs); CPen pen; pen.CreatePen(PS_SOLID,1,RGB(255,0,0)); dc.SelectObject(&pen); // 100,100 afd9 dc.MoveTo(100-20,100); dc.LineTo(100+20,100); dc.MoveTo(100,100-20); dc.LineTo(100,100+20); }
2使用透明窗体
.h文件中private: Layerdlg m_dlg; int m_bInit;
.cpp文件中
DLg::OnInitDialog()函数中添加
m_dlg.Create(IDD_DIALOG1,this); m_bInit = TRUE;
Dlg::OnMove(int x, int y)函数中添加
if (!m_bInit) { return; } GetDlgItem(IDC_STATIC_2)->GetWindowRect(&m_DialogChild); CPoint pt(100,100);//透明窗体放置在窗口中的位置 ClientToScreen(&pt); //m_dlg.MoveWindow(&m_DialogChild); ::SetWindowPos(m_dlg.m_hWnd ,HWND_TOP ,pt.x,pt.y,0,0,SWP_NOSIZE); m_dlg.ShowWindow(SW_SHOW);
最终状态
红色十字是透明窗体画的,TODO:是主窗体中字符串
可调成半透明状态,查看覆盖窗口的位置
半透明状态
相关文章推荐
- jsp页面div浮动弹出
- FusionCharts在Java中的基本使用
- Python 装饰器
- C/C++的字符串操作(一)
- Pyhon2.7.8内建函数
- HDU 5621 KK's Point (组合数学)
- AIDL 进程间通信
- sharepreferences
- vb中的十六进制
- centos6.7升级svn1.6到1.8
- Android开发常识
- Web debug技巧汇总
- 集合的理解
- Android基础之十七使用网络技术
- XPO开发指南简要
- 地理坐标与投影坐标
- 线程和进程
- drawRect和layoutSubviews的区别
- Centos7 PostgreSQL安装
- SQL学习笔记1——用代码创建、删除数据库