如何使用Logitech Web Cam在CStatic上捕获图像 [英] how to capture image on CStatic using Logitech Web Cam
问题描述
我的对话框中有一个Tab控件.
在myDlg.h文件中
I have a Tab Control in my Dialog.
IN myDlg.h file
struct DialogItem
{
CWnd* wnd; //our control
int ItemID;
int iTab; //which tab it belongs to
BOOL bTabStop; //does this control allow tabstop
};
afx_msg void CapturePhoto();
MyTab m_cTab;
在myDlg.cpp文件中
In myDlg.cpp file
BOOL myDlg::OnInitDialog()
{
CDialog::OnInitDialog();
m_cTab.Init();
m_cTab.InsertItem(0,"Register new user");
m_cTab.InsertItem(1,"Identify fingerprints");
m_cTab.InsertItem(2,"WebCam");
m_cTab.CreateImageArea("camera",4000,2,0,50,365);
m_cTab.CreateButton("WebCam",27,2,0,704,300,60);
retuen true;
}
//On Button click
void myDlg::CapturePhoto()
{
//hMyWindow = capCreateCaptureWindow("handle", WS_CHILD | WS_VISIBLE, 50, 150, ImageX, ImageY, this->m_hWnd,90);
int id,tabID;
tabID=m_cTab.GetCurFocus();
INT_PTR iCount =m_cTab.obArray.GetCount();
for(INT_PTR i=0; i<iCount; i++)
{
DialogItem* pItem = (DialogItem*)m_cTab.obArray[i];
if(pItem->ItemID==4000&tabID==2)
{
id=pItem->ItemID;
break;
}
}
hMyWindow=::GetDlgItem(m_cTab.GetSafeHwnd(),id);
bool xx = capDriverConnect( hMyWindow,0);
if(xx == false)
{
AfxMessageBox("Webcam not found ",0,0);
}
}
在MyTab.h文件中
In MyTab.h file
public:
void CreateImageArea(LPCTSTR sCaption, int nID, int iTab, UINT uLocation=0, int iX=0, int iY=0);
struct ITEM
{
CWnd* wnd; //our control
int nID;
int iTab; //which tab it belongs to
BOOL bTabStop; //does this control allow tabstop
};
在MyTab.cpp文件中
In MyTab.cpp file
void MyTab::CreateImageArea(LPCTSTR sCaption, int nID, int iTab, UINT uLocation, int iX, int iY)
{
ITEM* pItem = new ITEM;
else if(iTab==2)
{
PicpStatic2=new CStatic(); PicpStatic2->Create(sCaption,WS_CHILD|WS_VISIBLE|SS_BITMAP,CRect(50, 150,ImageX,ImageY),this,nID);
PicpStatic2->SetFont(GetFont());
PicpStatic2->ShowWindow(SW_HIDE);
//save the item struct to the object array
pItem->bTabStop = FALSE;
pItem->nID=nID;
pItem->iTab = iTab;
pItem->wnd = (CWnd*)(PicpStatic2);
}
else
{
PicpStatic->ShowWindow(SW_HIDE);
}
obArray.Add((CObject*)pItem);
}
当我不使用capCreateCaptureWindow()方法时,在单击按钮时,它会显示一条消息找不到网络摄像头".
当我使用capCreateCaptureWindow()方法并注释:: GetDlgItem(m_cTab.GetSafeHwnd(),id);它执行得很好.
我不想使用capCreateCaptureWindow()方法.我想使用在CreateImageArea()方法中动态创建的窗口.
On button click when I does not use capCreateCaptureWindow() method, it gives a message "Webcam not found".
When I use capCreateCaptureWindow() method and comment ::GetDlgItem(m_cTab.GetSafeHwnd(),id); it executes perfectly.
I do not want to use capCreateCaptureWindow() method. I want to use window which is dynamically created in CreateImageArea() method.
推荐答案
函数capDriverConnect()
需要捕获窗口的句柄.这样的窗口处理发送给它的WM_CAP_xxx
消息.您的窗口似乎无法处理这些消息.capDriverConnect()
是将WM_CAP_DRIVER_CONNECT
消息发送到窗口的宏.如果未处理此消息,则返回FALSE
.
The functioncapDriverConnect()
expects a handle to a capture window. Such a window handles theWM_CAP_xxx
messages that are send to it. Your window seems not handling these messages.capDriverConnect()
is a macro that sends theWM_CAP_DRIVER_CONNECT
message to the window. When this message is not handled,FALSE
is returned.
这篇关于如何使用Logitech Web Cam在CStatic上捕获图像的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!