//VideoCapture.cpp
#include <windows.h>
#include <stdio.h>
#include <commdlg.h>
#include <vfw.h>
#include "VideoCapture.h"
#include "resource.h"
char
TempName[256];
HWND hwndCap;
HWND hwndSetCapStutas;
CAPDRIVERCAPS CapDriver;
CAPSTATUS
CapStat;
int WINAPI WinMain(HINSTANCE hInstance,HINSTANCE hPrevInstance,LPSTR lpCmdLine,int nShowCmd)
{
if(DialogBox(hInstance,(LPCSTR)IDD_DIALOG1,NULL,DlgProc)==-1)
MessageBox(NULL,"对话框建立错误!","错
误",MB_OK);
return 0;
}
BOOL CALLBACK DlgProc(HWND hdlg,UINT message,WPARAM wParam,LPARAM lParam)
{
RECT rect;
switch(message)
{
case WM_INITDIALOG:
GetWindowRect(hdlg,&rect);
hwndCap =capCreateCaptureWindow("人脸录入" ,WS_CHILD| WS_VISIBLE,30,20,320,240,hdlg ,0);
return FALSE;
case WM_COMMAND :
switch (LOWORD (wParam))
{
case
IDOK :
if(capDriverConnect(hwndCap, 0)==TRUE)
{
capDriverGetCaps(hwndCap , &CapDriver ,sizeof (CAPDRIVERCAPS) );
if (CapDriver.fHasOverlay)
capOverlay(hwndCap ,TRUE);
else
{
capPreviewRate (hwndCap ,66) ;
capPreview(hwndCap, TRUE) ;
}
}
else
MessageBox(hdlg,"采集图像错误","提
示",MB_OK);
return 0;
break;
case IDC_BUTTON1:
if(CapDriver.fHasDlgVideoSource)
capDlgVideoSource(hwndCap);
break;
case IDC_BUTTON2:
MessageBox(hdlg,"作者:Steward\n地址:云南大学信息学院","关于作者",MB_OK);
break;
case IDC_BUTTON3:
capGrabFrame( hwndCap);
break;
case IDC_BUTTON4:
MenuOpenDlg(hdlg,"视频采集保存对话框");
capFileSaveDIB(hwndCap,TempName);
break;
case
IDCANCEL :
capCaptureStop(hwndCap);
capDriverDisconnect (hwndCap);
EndDialog (hdlg, 0) ;
return TRUE ;
}
break ;
}
return FALSE ;
}
void MenuOpenDlg(HWND hWnd,char *str1)
{
OPENFILENAME OpenTemp;
DWORD Errval,error;
char buf[5];
char Errstr[50]="GetOpenFileName returned Error #";
char szTemp[] = "BMP文件 (*.bmp;*.BMP)\0*.bmp\0所有文件 (*.*)\0*.*\0";
OpenTemp.lStructSize = sizeof( OPENFILENAME );
OpenTemp.hwndOwner = hWnd;
OpenTemp.hInstance = 0;
OpenTemp.lpstrFilter = (LPSTR)szTemp;
OpenTemp.lpstrCustomFilter = NULL;
OpenTemp.nMaxCustFilter = 0;
OpenTemp.nFilterIndex = 1;
OpenTemp.lpstrFile = (LPSTR)TempName;
OpenTemp.nMaxFile = sizeof( TempName );
OpenTemp.lpstrFileTitle = NULL;
OpenTemp.nMaxFileTitle = 0;
OpenTemp.lpstrInitialDir = NULL;
OpenTemp.lpstrTitle=str1;
OpenTemp.Flags = OFN_FILEMUSTEXIST |
OFN_HIDEREADONLY | OFN_PATHMUSTEXIST;
OpenTemp.nFileOffset = 0;
OpenTemp.nFileExtension = 0;
OpenTemp.lpstrDefExt = "*";
OpenTemp.lCustData = 0L;
OpenTemp.lpfnHook = NULL;
OpenTemp.lpTemplateName = NULL;
error=0;
if (GetSaveFileName( &OpenTemp ) != TRUE)
error=1;
if (error==1) {
Errval=CommDlgExtendedError();
if (Errval!=0) {
sprintf(buf,"%ld",Errval);
strcat(Errstr,buf);
MessageBox(hWnd,Errstr,"WARNING",MB_OK|MB_ICONSTOP);
}
}
InvalidateRect( hWnd, NULL, TRUE );
}