/********************************************************************\
* CapPicture.c: Source code for generic *
* *
* Comments: Video capture and display with some processing *
* *
* Functions: *
* WinMain - Application entry point *
* MainWndProc - main window procedure *
* *
* *
\********************************************************************/
/********************* Header Files *********************/
#include <windows.h> // windows GUI and services
#include <vfw.h> // video for windows library
#include <commdlg.h> // common dialogs
#include "CapPicture.h" // resource header
/********************* Prototypes ***********************/
// main window procedure
LRESULT WINAPI MainWndProc( HWND, UINT, WPARAM, LPARAM );
// Select Capture Driver Procedure
LRESULT WINAPI SelCapDrvProc( HWND, UINT, WPARAM, LPARAM );
// Enumerate Capture Drivers
int EnumCapDrv();
// Create the buttons on the main window
//int CreateWndButtons(); this doesnt work
// handle the right click popup menu
VOID APIENTRY HandlePopupMenu(HWND, POINT);
// video thread procedure
DWORD WINAPI videoThreadProc(LPVOID lParam);
/******************* Global Variables ********************/
HANDLE ghInstance; // application instance
HWND hwndMain; // main window handle
HWND hwndVideo; // video capture window
HWND hwndSelCapDrvDlg; // Select the capture driver dialog
HWND hwndSelCapDrvDlg_LBox; // list box for select capture driver dialog
HWND hwndExit; // exit button
HWND hwndMin; // minimize button
HWND hwndHelp; // help button
HWND hwndRecord; // record button
HANDLE hVideoThread; // thread to stop the hang when recording video
HRGN hRegion1; // region for window shaping
CAPDRIVERCAPS CapDrvCaps; // driver capabilities
bool isRecordFileOpen = false; // flag set if record file is open
char recordFile[260]; // file to hold recording
bool isPicFileOpen = false; // flag set if snapshot file is open
char pictureFile[260]; // file to hold snapshot
bool isRecording = false; // are we recording?
bool threadEnd = false; // should the video thread end?
/********************************************************************\
* *
* CLASSES, ENUMS, & STRUCTS *
* *
/********************************************************************/
/********************************************************************\
* Function: int PASCAL WinMain(HINSTANCE, HINSTANCE, LPSTR, int) *
* *
* Purpose: Initializes Application *
* *
* Comments: Register window class, create and display the main *
* window, and enter message loop. *
* *
* *
\********************************************************************/
int PASCAL WinMain( HINSTANCE hInstance,
HINSTANCE hPrevInstance,
LPSTR lpszCmdLine,
int nCmdShow )
{
WNDCLASS wc;
MSG msg;
if( !hPrevInstance )
{
wc.lpszClassName = "GenericAppClass";
wc.lpfnWndProc = MainWndProc;
wc.style = CS_OWNDC | CS_VREDRAW | CS_HREDRAW;
wc.hInstance = hInstance;
wc.hIcon = LoadIcon( NULL, IDI_APPLICATION );
wc.hCursor = LoadCursor( NULL, IDC_ARROW );
wc.hbrBackground = CreateSolidBrush (RGB(0, 64, 128));
wc.lpszMenuName = "GenericAppMenu";
wc.cbClsExtra = 0;
wc.cbWndExtra = 0;
RegisterClass( &wc );
}
ghInstance = hInstance;
hwndMain = CreateWindow( "GenericAppClass",
"Super Video",
WS_POPUP,
0,
0,
500,
500,
NULL,
NULL,
hInstance,
NULL
);
ShowWindow( hwndMain, nCmdShow );
//Set the main window to the region
SetWindowRgn(hwndMain,hRegion1,1);
while( GetMessage( &msg, NULL, 0, 0 ) ) {
TranslateMessage( &msg );
DispatchMessage( &msg );
}
return msg.wParam;
}
/********************************************************************\
* Function: LRESULT CALLBACK MainWndProc(HWND, UINT, WPARAM, LPARAM) *
* *
* Purpose: Processes Application Messages *
* *
* Comments: The following messages are processed *
* *
* WM_PAINT *
* WM_CREATE *
* WM_DESTROY *
* *
* *
\********************************************************************/
LRESULT CALLBACK MainWndProc( HWND hwndMain, UINT msg, WPARAM wParam,
LPARAM lParam )
{
HDC hDC = GetDC(hwndMain);
RECT rc; // client area
POINT pt; // location of mouse click
switch( msg ) {
/**************************************************************\
* WM_LBUTTONDBLCLK: *
\**************************************************************/
case WM_LBUTTONDBLCLK:
SetFocus(hwndMain);
break;
/**************************************************************\
* WM_LBUTTONDOWN: *
\**************************************************************/
case WM_RBUTTONDOWN:
// Get the bounding rectangle of the client area.
GetClientRect(hwndMain, (LPRECT) &rc);
// Get the client coordinates for the mouse click.
pt.x = LOWORD(lParam);
pt.y = HIWORD(lParam);
// If the mouse click took place inside the client
// area, execute the application-defined function
// that displays the shortcut menu.
if (PtInRect((LPRECT) &rc, pt))
HandlePopupMenu(hwndMain, pt);
break;
/**************************************************************\
* WM_PAINT: *
\**************************************************************/
case WM_PAINT:
//Give the region a red border
FrameRgn(hDC,hRegion1,CreateSolidBrush(RGB(0,0,0)),2,2);
// brung our dialog to the foreground
BringWindowToTop(hwndSelCapDrvDlg);
return( DefWindowProc( hwndMain, msg, wParam, lParam ));
/**************************************************************\
* WM_COMMAND: *
\**************************************************************/
case WM_COMMAND:
CAPSTATUS CapStatus;
switch( wParam ) {
case SOURCE:
if(CapDrvCaps.fHasDlgVideoSource)
capDlgVideoSource(hwndVideo);
break;
case FORMAT://why doesnt this work
//if(CapDrvCaps.fHasDlgVideoFormat)
//{
capDlgVideoFormat(hwndMain);
// Are there new image dim