15,980
社区成员
发帖
与我相关
我的任务
分享
BOOL CVideoTestDlg::OnInitDialog()
{
// TODO: Add extra initialization here
g_hDlg = m_hWnd;
m_hWndVideo = capCreateCaptureWindow(NULL,WS_POPUP,0,0,640,480,m_hWnd,0);
m_flag = capDriverConnect(m_hWndVideo,0);//链接驱动程序
if(!m_flag)
MessageBox("请确认USB视频源已连接!");
while(!m_flag)
{
m_flag = capDriverConnect(m_hWndVideo,0);
}
if(m_flag)
{
::SetParent(m_hWndVideo,*this);
::SetWindowLong(m_hWndVideo,GWL_STYLE,WS_CHILD);
//设置窗口过程函数 响应鼠标双击消息 pOldWndProc=(WNDPROC)SetWindowLong(m_hWndVideo,GWL_WNDPROC,(LONG)NewWndProc);
//视频居中显示使用
GetClientRect(wndRC);
x_original = wndRC.Width()/2;
y_original = wndRC.Height()/2; ::SetWindowPos(m_hWndVideo,NULL,x_original-320,y_original-240,640,480,SWP_NOZORDER);
::ShowWindow(m_hWndVideo,SW_SHOW);
capPreviewRate(m_hWndVideo,20);
capPreview(m_hWndVideo,TRUE);
}
return TRUE; // return TRUE unless you set the focus to a control
}
WNDPROC pOldWndProc;
HWND g_hDlg;//当前运行窗口句柄
LRESULT CALLBACK NewWndProc(HWND hWnd,UINT uMsg,WPARAM wParam,LPARAM lParam)
{
switch(uMsg)
{
case WM_LBUTTONDBLCLK:
::PostMessage(g_hDlg,WM_MYDBCLICK,0,0);
break;
default :
break;
}
return pOldWndProc(hWnd,uMsg,wParam,lParam);
}
LRESULT CVideoTestDlg::OnMyLBtnDBClick(WPARAM wParam,LPARAM lParam)
{
if(!m_flagDlg)
{
ShowWindow(SW_MAXIMIZE);
//隐藏对话框的标题栏
ModifyStyle(WS_CAPTION,0,SWP_FRAMECHANGED);
m_flagDlg = TRUE;
Invalidate();
}
else
{
ShowWindow(SW_NORMAL);
//显示
ModifyStyle(0,WS_CAPTION,SWP_FRAMECHANGED);
m_flagDlg = FALSE;
Invalidate();
}
return 0L;
}
BOOL CVideoTestDlg::OnEraseBkgnd(CDC* pDC)
{
GetClientRect(wndRC);
x_original = wndRC.Width()/2;
y_original = wndRC.Height()/2;
::SetWindowPos(m_hWndVideo,NULL,x_original-320,y_original-240,640,480,SWP_NOZORDER);
::ShowWindow(m_hWndVideo,SW_SHOW);
CBitmap bitmap;
bitmap.LoadBitmap(IDB_BITMAP1);
BITMAP bitmapInfo;
bitmap.GetBitmap(&bitmapInfo);
CDC dcMem;
dcMem.CreateCompatibleDC(pDC);
dcMem.SelectObject(&bitmap);
CRect rect;
GetWindowRect(rect);
pDC->StretchBlt(0,0,rect.Width(),rect.Height(),&dcMem,0,0,bitmapInfo.bmWidth,bitmapInfo.bmHeight,SRCCOPY);
//字体及输出位置指定
CFont font;
font.CreatePointFont(300,"华文行楷",NULL);//创建字体
CFont *pOldFont=pDC->SelectObject(&font);
CSize sz = pDC->GetTextExtent("闪亮之星现场");//获取字串的宽 高
pDC->SetTextColor(RGB(255,255,0));
pDC->SetBkMode(TRANSPARENT);//设置透明背景
pDC->TextOut(x_original-sz.cx/2,y_original-250-sz.cy,"闪亮之星现场");
pDC->SelectObject(pOldFont);
ReleaseDC(&dcMem);
return TRUE;
//return CDialog::OnEraseBkgnd(pDC);
}