To continue recording, the second step is to develop camera photo function.
Using vfw.h to develop camera photo function, there are many articles about VFW online, many code can refer to
Reference: http://blog.163.com/huangqiao_8/blog/static/33900492008017111847364/
Vedio for Windows is the video development tool for the Multimedia programming SDK in the WIN32 SDK. Vedio for Windows header file vfw.h and library file Vfw32.lib are available in Microsoft Visual C + +.
Add a picture control to the dialog displayed in ActiveX, set the ID to idc_video, add a button, turn on the camera, take a photo, etc., and paste the key code into the following:
1. Introduction of Vfw.h
#include <vfw.h>#pragma comment (lib, "Vfw32.lib")
If Afxcmn.h is not introduced , add it in stdafx.h:
#include <afxcmn.h>
2. Add the following variables to the header file of the dialog box
Public : friend UINT Vproc (LPVOID pparam); Friend LRESULT CALLBACK Backproc (HWND hwnd,lpvideohdr lpvhdr); Private : HWND Videohwnd; CEvent e; CStatic capvideo; *MapInfo; Pbitmapinfo Tran;
//Supplement under the dialog box Add the following code to the DoDataExchange method:
DDX_Control (PDX, Idc_capvideo, capvideo);//Bound Control Idc_capvideo and variables
3. Open the code inside the camera button
CRect RC; Capvideo. GetWindowRect (&RC); ScreenToClient (RC); Capdrivercaps CAPD; Capstatus caps; Tran=NULL; E.resetevent (); AfxBeginThread (Vproc, (void*) This); :: WaitForSingleObject (E,infinite); if(Capdriverconnect (Videohwnd,0)==TRUE) {Capdrivergetcaps (Videohwnd,sizeof(capdrivercaps),&CAPD); Capgetstatus (Videohwnd,&caps,sizeof(Capstatus)); :: SetParent (Videohwnd,* This); :: SetWindowLong (Videohwnd,gwl_style,ws_child); :: SetWindowPos (Videohwnd,null,rc.left,rc.top, RC. Width (), RC. Height (), swp_nozorder); :: ShowWindow (Videohwnd,sw_show); //Cappreviewscale (Videohwnd, 1); Cappreviewrate (Videohwnd, the); Cappreview (Videohwnd,true); } Else{AfxMessageBox ("creation failed"); }
4.Vproc Method
Static UINT Vproc (LPVOID pparam)
{
Cviewdialog *p= (cviewdialog*) Pparam;
HWND Hwnd=capcreatecapturewindow (null,ws_popup,0,0,10,10,0,0);
if (HWND)
{
p->videohwnd=hwnd;
P->e.setevent ();
}
MSG msg;
while (GetMessage (&msg,null,0,0))
{
TranslateMessage (&MSG);
DispatchMessage (&MSG);
}
return msg.wparam;
}
5. The code inside the camera button
LPWSTR picurl=_t ("d:/123.bmp"); Capfilesavedib (Videohwnd,picurl);
Now you can save the diagram, but the BMP format is not commonly used, the next record clipping BMP and converting BMP to JPG.
There is a detour, the image control ID default is idc_static, start without modifying the initialization of the times wrong because the ID duplicate, after the modification is good ...