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

来源:互联网 发布:mac os x镜像下载iso 编辑:程序博客网 时间:2024/06/05 00:24
原本是想在显示图像的地方直接画需要的图形,最后发现显示图像的地方在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,100dc.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:是主窗体中字符串
这里写图片描述

可调成半透明状态,查看覆盖窗口的位置
半透明状态
这里写图片描述

0 0
原创粉丝点击