Click here to Skip to main content
15,892,674 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more: , +
I have a Tab Control in my Dialog.
IN myDlg.h file
C++
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;

In myDlg.cpp file
C++
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);
	}
}


In MyTab.h file
C++
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
	};

In MyTab.cpp file
C++
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);

}
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.
Posted

1 solution

The function capDriverConnect() expects a handle to a capture window. Such a window handles the WM_CAP_xxx messages that are send to it. Your window seems not handling these messages. capDriverConnect() is a macro that sends the WM_CAP_DRIVER_CONNECT message to the window. When this message is not handled, FALSE is returned.
 
Share this answer
 
Comments
Member 7909353 31-Oct-12 7:59am    
On Button click
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);
hMyWindow = capCreateCaptureWindow("handle", WS_CHILD | WS_VISIBLE, 50, 150, ImageX, ImageY, hMyWindow,90);
bool xx = capDriverConnect( hMyWindow,0);
if(xx == false)
{
AfxMessageBox("Webcam not found ",0,0);
}
xx is true but no image capturing occurred.
Jochen Arndt 31-Oct-12 8:14am    
A cite from your question: 'it gives a message "Webcam not found".'
This message is shown by your code when capDriverConnect() returns FALSE. Otherwise, you would not see the message box.
Member 7909353 31-Oct-12 8:08am    
When I does not create dynamically, I create at design time it works.
Jochen Arndt 31-Oct-12 8:35am    
What do you mean by this? Using capCreateCaptureWindow()?.

The window created by capCreateCaptureWindow handles the access to the camera. You need such a window. You can't use a normal window. But you can copy data from that window to others. See this CP article for a solution using the clipboard to copy grabbed frames to another window: http://www.codeproject.com/Articles/7882/Easy-Digital-Camera-Connection
Member 7909353 31-Oct-12 8:55am    
I want to use CStatic for image which is dynamically created.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900