您的位置:首页 > 其它

透明窗体覆盖在视频上画图

2016-05-19 17:41 344 查看
原本是想在显示图像的地方直接画需要的图形,最后发现显示图像的地方在dll中,没有源码,只能够另辟他径了。
于是有了下面想法:
*在窗口上覆盖一个透明窗口,然后对透明窗口进行绘图。根据需要对透明窗口进行刷新重绘。
全部代码上传csdn (还有鼠标点哪(透明窗体范围内),就在哪画图)


代码链接http://download.csdn.net/detail/xuleisdjn/9525884

下面代码是其中部分代码。

*下面是基本流程和基本代码:

1透明窗体创建

Insert Dialog

Border :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:是主窗体中字符串



可调成半透明状态,查看覆盖窗口的位置

半透明状态

内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: