佳礼资讯网

 找回密码
 注册

ADVERTISEMENT

查看: 1249|回复: 1

怎样设计一个Dialog显示Webcam?

[复制链接]
发表于 18-6-2009 12:19 AM | 显示全部楼层 |阅读模式
以下是我用的方法,但是就是行不通?可以教教在下吗?
1)我先在我的GUI上画出一个Group Box,ID命名为IDC_STATIC_FRAME,并在Properties->Extended Styles上点上Client edge 和 Modal frame
2)#include <vfw.h>
     #include <winuser.h>
     #include <Windows.h>
3)link 上 vfw32.lib, user32.lib, winmm.lib
4)OnInitDialog上加上
CStatic* pst=(CStatic*)GetDlgItem(IDC_STATIC_FRAME);
pst->GetWindowRect(&m_rectFrame);
ScreenToClient(&m_rectFrame);
5)OnPaint上加上
m_bmp.GetBitmap(&bm);

dcMem.DeleteDC();
dcMem.CreateCompatibleDC(&dc);
dcMem.SelectObject(&m_bmp);

dc.StretchBlt(m_rectFrame.left, m_rectFrame.top,
                     m_rectFrame.Width(),m_rectFrame.Height(),
                     &dcMem,0,0,bm.bmWidth,bm.bmHeight, SRCCOPY);
6)我的Preview func
hWndC = capCreateCaptureWindow ( "Capture Window", WS_CHILD|WS_DLGFRAME,m_rectFrame.TopLeft().x, m_rectFrame.TopLeft().y,320, 240, GetSafeHwnd()/*hwndParent*/, 11011);
  
  if(hWndC)
     capDriverConnect (hWndC, 0);
  else
  {
     AfxMessageBox("Error Cammera is not connected!");
     exit(1);
  }
  SetTimer(1,66,NULL);
7)以下是我的OnTimer func
void CYourProject::OnTimer(UINT nIDEvent)
{
if(nIDEvent==1)// First Timer
{
   capGrabFrame(hWndC); // simple macro that sample a single frame from the
                        // camera.
   capEditCopy(hWndC);  // simple macro that edit a copy of the frame.
   OpenClipboard();     //like virtual memory.

   //m_hBmp is a Handle to Bitmap.
   m_hBmp = (HBITMAP)::GetClipboardData(CF_BITMAP);
   CloseClipboard();

   m_bmp.Detach();       //cleaning the bitmap.
   m_bmp.Attach(m_hBmp); //connecting the bitmap throw the handle.


   InvalidateRect(m_rectFrame,false); // m_rectFrame is the frame that the
                                      // video stream will be present in.
   OnPaint();            // calling to paint function to paint the bitmap
                         // into the frame on the dialog.

}
CDialog::OnTimer(nIDEvent);
}

我试了很多方法还是不行,有哪一位大大可以帮帮我吗?谢谢
回复

使用道具 举报


ADVERTISEMENT

发表于 18-6-2009 06:44 PM | 显示全部楼层
Direct Show 不很熟.

你要確定你的WebCam是 First Available Input Device. 要不然你得從 Device List 裡找出你的 WebCam.

你應該不能夠直接 copy 到 Clipboard. Copy 到都是黑色的一片.
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 注册

本版积分规则

 

ADVERTISEMENT



ADVERTISEMENT



ADVERTISEMENT

ADVERTISEMENT


版权所有 © 1996-2023 Cari Internet Sdn Bhd (483575-W)|IPSERVERONE 提供云主机|广告刊登|关于我们|私隐权|免控|投诉|联络|脸书|佳礼资讯网

GMT+8, 7-12-2025 09:30 PM , Processed in 0.130509 second(s), 24 queries , Gzip On.

Powered by Discuz! X3.4

Copyright © 2001-2021, Tencent Cloud.

快速回复 返回顶部 返回列表