#include <vcl.h>
#include <windows.h> // windows GUI and services
#include <vfw.h> // video for windows library
#include <commdlg.h> // common dialogs
#pragma hdrstop
#include "main.h"
#include "about.h"
#include "snapshots.h"
//---------------------------------------------------------------------------
/* NOTE!
This program has been built on a previous example that demonstrated
the usage of Video For Windows. So far this is the most comprehensive
version for Borland C++ Builder 5.0 and above (IMHO). One might recognize
different common variables and constants, and they have been copyied and
pasted directly to the new source.
Credits for previous writings / Help source:
Adam Berger <email not found>
MSDN
VFW documentation
I, Richard, do not take responsibility for how you use this program
or how you modify it. This programs intention is NOT to remove nor
damage any data that is essential to you and your computer.
Main tasks of this program is to demonstrate how to use Video For Windows
and its primary properties. NOTE! I removed the capability of storing video-
clips because compression is quite bad so videoclips will be in bad quality
as well as leaving the filesize too large. ( An update of this program
will contain video recording, and not just snapshots! )
For any bugfixes, updates or more examples, check out the oblivion creations
website.
The icons contained except for the Nuclear icon are parts of Microsoft(c)
Windows(tm) XP(r) and they have been used to ensure that this program is
fully compatible.
---------------------------------------------
Keep this note no matter what!
---------------------------------------------
By the Richard of oblivion Creations, 2002
http://oblivion.lunamorena.net/ (bugfixes, updates and/or more examples)
Contact Richard directly on
oblivion@lunamorena.net
+46 (0) 736 849 531
*/
//---------------------------------------------------------------------------
// main window procedure
LRESULT WINAPI MainWndProc( HWND, UINT, WPARAM, LPARAM );
// Select Capture Driver Procedure
LRESULT WINAPI SelCapDrvProc( HWND, UINT, WPARAM, LPARAM );
// DECLARE 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 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 snapshot
//---------------------------------------------------------------------------
#pragma package(smart_init)
#pragma resource "*.dfm"
TForm1 *Form1;
//---------------------------------------------------------------------------
__fastcall TForm1::TForm1(TComponent* Owner)
: TForm(Owner)
{
// Get cameras within system
EnumCapDrv();
hwndMain = Form1->Handle;
}
//---------------------------------------------------------------------------
void __fastcall TForm1::MyNotify(TMessage& Msg)
{
switch( Msg.Msg ) {
// obsolete in this example.
}
}
//---------------------------------------------------------------------------
LRESULT CALLBACK SelCapDrvProc( HWND hWnd, UINT msg, /*callback procedure */
WPARAM wParam, LPARAM lParam )
{
switch(msg)
{
// dialog created
case WM_INITDIALOG:
return TRUE;
// command
case WM_COMMAND:
switch ( wParam )
{
// user clicked the select driver button
case SELCAPDRVDLG_BUTTON:
int sel = 0;
// get the selected driver
SendMessage( hwndSelCapDrvDlg_LBox, LB_GETSELITEMS, 1, sel);
// connect to the driver
SendMessage( hwndVideo, WM_CAP_DRIVER_CONNECT, sel, 0L);
// then close this dialog
SendMessage( hwndSelCapDrvDlg, WM_CLOSE, 0, 0);
// update the driver capabilities
SendMessage( hwndVideo, WM_CAP_DRIVER_GET_CAPS,
sizeof(CAPDRIVERCAPS), (LONG) (LPVOID) &CapDrvCaps);
// set preview rate to XXX miliseconds
capPreviewRate( hwndVideo, 50 );
// start preview video
capPreview( hwndVideo, TRUE );
}
return TRUE;
// user wants to close dialog
case WM_CLOSE:
DestroyWindow(hwndSelCapDrvDlg);
return TRUE;
}
return( 0L );
}
//---------------------------------------------------------------------------
void __fastcall TForm1::btnEnableClick(TObject *Sender)
{
btnEnable->Enabled=false;
if (btnEnable->Caption=="Enable") {
btnSnap->Enabled=true;
btnEnable->Caption="Disable";
hwndVideo = capCreateCaptureWindow(
(LPSTR) "Capture Window",
WS_CHILD | WS_VISIBLE,
2, 2, 250, 250,
(HWND) scBox1->Handle,
(int) 1);
// Activate (with the Default/first device)
SelCapDrvProc(hwndMain,WM_COMMAND,SELCAPDRVDLG_BUTTON,0);
// Display size and resize to saved size
GetCamSize();
ResizePCam();
// Hide warning label
lblWarnOpen->Visible=false;
}else if (btnEnable->Caption=="Disable") {
btnSnap->Enabled=false;
// Show warning label and re-position enlarger
lblWarnOpen->Visible=true;
lblEnlarger->Top = lblWarnOpen->Top-lblWarnOpen->Height; lblEnlarger->Left = lblWarnOpen->Left;
capPreview(hwndVideo,FALSE);
DestroyWindow(hwndVideo);
hwndVideo = NULL;
btnEnable->Caption="Enable";
}
btnEnable->Enabled=true;
}
//---------------------------------------------------------------------------
int TForm1::EnumCapDrv() // enumerate the installed capture drivers
{
char szDeviceName[80]; // driver name
char szDeviceVersion[80]; // driver version
char item[161]; // concatinated string
int i; // counter
for (i=0; i<10; i++)
{
if ( capGetDriverDescription(i, szDeviceName, sizeof(szDeviceName),
szDeviceVersion, sizeof(szDeviceVersion)) )
{
strcpy(item, szDeviceName);
strcat(item, " ");
strcat(item, szDeviceVersion);
// add item to list box
SendMessage(hwndSelCapDrvDlg_LBox, LB_ADDSTRING, 0, (LPARAM) item);
SendMessage(hwndSelCapDrvDlg_LBox, LB_SETITEMDATA, i, (LPARAM) i);
// Notify user
lblCam1->Caption = szDeviceName;
lblCam2->Caption = szDeviceVersion;
}
}
return 0;
}
//---------------------------------------------------------------------------
void __fastcall TForm1::Choosecamera1Click(TObject *Sender)
{
if (capDlgVideoSource(hwndVideo)==TRUE) {
}else{
Application->MessageBox("Error while trying to modify camera and extended settings.",NULL,MB_ICONSTOP |MB_OK);
}
}
//---------------------------------------------------------------------------
void __fastcall TForm1::Setformat1Click(TObject *Sender)
{
if (capDlgVideoFormat(hwndVideo)==TRUE){
ResizePCam();
GetCamSize();
}else{
Application->MessageBox("Error occured when trying to change video size.",NULL,MB_ICONSTOP |MB_OK);
}
}
//---------------------------------------------------------------------------
void __fastcall TForm1::Compression1Click(TObject *Sender)
{
if (capDlgVideoCompression(hwndVideo)==TRUE) {
}else{
Application->MessageBox("Error while setting compression quality.",NULL,MB_ICONSTOP |MB_OK);
}
}
//--------------------------------------------------