⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 unit4.~cpp

📁 射频卡发卡管理系统的PC端软件
💻 ~CPP
字号:
//---------------------------------------------------------------------------

#include <vcl.h>
#include <windows.h>
#include <vfw.h>
#pragma hdrstop

#include "Unit1.h"
#include "Unit2.h"
#include "Unit3.h"
#include "Unit4.h"
#include "Unit5.h"
//---------------------------------------------------------------------------
#pragma package(smart_init)
#pragma resource "*.dfm"
#define GEN_ID 1
TForm4 *Form4;

//---------------------------------------------------------------------------
// 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


//---------------------------------------------------------------------------
__fastcall TForm4::TForm4(TComponent* Owner)
        : TForm(Owner)
{
    // Get cameras within system
    EnumCapDrv();
    hwndMain = Form1->Handle;
    Button3->Enabled=false;
}
//---------------------------------------------------------------------------




void __fastcall TForm4::BitBtn1Click(TObject *Sender)
{
//检查输入是否为空
if ((DBEdit1->Text=="")|(DBEdit2->Text=="")|(DBEdit3->Text==""))
{
ShowMessage("学号或姓名或卡号不能为空值");
}
else
{
        Form1->IBTable2->Edit();
        if(Form1->IBTable2->FieldByName("STUID")->AsInteger == 0)
        {
                Form1->IBTable2->FieldByName("STUID")->AsInteger = GEN_ID;
        }
BitBtn2->Enabled=True;

DBEdit1->Enabled=False;
DBEdit2->Enabled=False;
DBEdit3->Enabled=False;
//DBEdit4->Enabled=False;
//DBEdit5->Enabled=False;
//DBEdit6->Enabled=False;
//RadioButton1->Enabled=False;
//Button1->Enabled=False;
DBEdit1->Color=clSkyBlue;
DBEdit2->Color=clSkyBlue;
DBEdit3->Color=clSkyBlue;
//DBEdit4->Color=clSkyBlue;
//DBEdit5->Color=clSkyBlue;
//DBEdit6->Color=clSkyBlue;
Form1->IBTable2->Edit();
Form1->IBTable2->Post();
BitBtn1->Enabled=False;
}




}
//---------------------------------------------------------------------------

void __fastcall TForm4::BitBtn2Click(TObject *Sender)
{
BitBtn2->Enabled=False;
BitBtn1->Enabled=True;
DBEdit1->Enabled=True;
DBEdit2->Enabled=True;
DBEdit3->Enabled=True;
//DBEdit4->Enabled=True;
//DBEdit5->Enabled=True;
//DBEdit6->Enabled=True;
//RadioButton1->Enabled=True;
//Button1->Enabled=True;
DBEdit1->Color=clWindow;
DBEdit2->Color=clWindow;
DBEdit3->Color=clWindow;
//DBEdit4->Color=clWindow;
//DBEdit5->Color=clWindow;
//DBEdit6->Color=clWindow;
Form1->IBTable2->Edit();

}
//---------------------------------------------------------------------------


void __fastcall TForm4::FormClose(TObject *Sender, TCloseAction &Action)
{

Form1->IBTable2->Cancel();
}
/*---------------------------------------------------------------------------



void __fastcall TForm4::RadioButton1Click(TObject *Sender)
{
if (RadioButton1->Checked)
{
RadioButton1->Font->Color=clBlue;
Form1->IBTable2->Edit();
Form1->IBTable2->FieldByName("LOCK_FLAG")->AsInteger=1;
RadioButton1->Checked=False;
}
else
{

RadioButton1->Font->Color=clWindow;
RadioButton1->Checked=True;
}


} */
//---------------------------------------------------------------------------






void __fastcall TForm4::BitBtn3Click(TObject *Sender)
{
Form1->IBTable2->Delete();
}
//---------------------------------------------------------------------------


void __fastcall TForm4::Button2Click(TObject *Sender)
{
bool FindResult=false;
Form1->IBTable2->Cancel();
BitBtn1->Enabled=False;
BitBtn2->Enabled=True;


if(Edit1->Text=="")
ShowMessage("请确认输入不为空");
else FindResult=Form5->FindByStu_NO(Edit1->Text);
}
//---------------------------------------------------------------------------









void __fastcall TForm4::btnEnableClick(TObject *Sender)
{
btnEnable->Enabled=false;
Form1->Label12->Caption="开";

    if (btnEnable->Caption=="启用") {
        btnSnap->Enabled=true;
        Button3->Enabled=true;
        btnEnable->Caption="禁用";

        hwndVideo = capCreateCaptureWindow(
    	    (LPSTR) "Capture Window",
             WS_CHILD | WS_VISIBLE,
    	  	 1, 1, 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=="禁用") {
        Form1->Label12->Caption="关";
        btnSnap->Enabled=false;
        Button3->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="启用";

    }

btnEnable->Enabled=true;


}
//---------------------------------------------------------------------------
void TForm4::GetCamSize()
{
    // NOTIFY USER OF THE CAMERA SIZES
    CAPSTATUS CapStatus;
    capGetStatus(hwndVideo, &CapStatus, sizeof(CapStatus));
    //lblCamSize->Caption = "Proportions: " + IntToStr(CapStatus.uiImageWidth)+"x"+IntToStr(CapStatus.uiImageHeight)+"x"+IntToStr(CapStatus.fScale);

    // Check for audio hardware capabilities
    if (CapStatus.fAudioHardware==TRUE) {
        //ilsProp->Draw(imgSound->Canvas,1,1,0,true);
        //lblSound->Caption = "Audio detected on system.";
    }else{
        //ilsProp->Draw(imgSound->Canvas,1,1,1,true);
        //lblSound->Caption = "Audio not available on system.";
    }


}
//---------------------------------------------------------------------------
void TForm4::ResizePCam() {
    // RESIZE PREVIEW CAM.
    CAPSTATUS CapStatus;
    capGetStatus(hwndVideo, &CapStatus, sizeof(CapStatus));
    SetWindowPos(hwndVideo, NULL, 0, 0, CapStatus.uiImageWidth, CapStatus.uiImageHeight, SWP_NOZORDER | SWP_NOMOVE);

    // Fix the scrollbars
    //lblEnlarger->Left = 0;
    //lblEnlarger->Width = CapStatus.uiImageWidth+10;
    //lblEnlarger->Top = CapStatus.uiImageHeight+10;



}
//---------------------------------------------------------------------------


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 );
}
//---------------------------------------------------------------------------
int TForm4::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 TForm4::Button3Click(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 TForm4::btnSnapClick(TObject *Sender)
{
  if (hwndVideo) {
    btnSnap->Enabled=false;

    // Create filename
    // Based on current time (minute and second)
    AnsiString TotTime = TimeToStr(Time());
    AnsiString Minute = TotTime.SubString(TotTime.Length()-4,2);
    AnsiString Second = TotTime.SubString(TotTime.Length()-1,2);

    AnsiString totFile = AnsiString("Pictrue\\") + "_Snap"+Minute+"."+Second+".bmp";
    // Compiled filename is "_SnapXX.XX.bmp"

    strcpy(recordFile, totFile.c_str());

    if (capFileSetCaptureFile(hwndVideo,recordFile)) {
        // Filename successfully set.
    }else{ ShowMessage("Filename not approved."); }

    if (capFileSaveDIB(hwndVideo,recordFile)){
        // File successfully stored.

        // Refresh view in Snapshots collection
       // Files1->Update();

        // Select the new file
   /*     for (int i=0; i < Files1->Count;i++) {
            if (Files1->Items->Strings[i]==totFile) {
                Files1->ItemIndex=i;
            }
        }       */
        // Show the image
        DBImage1->Picture->LoadFromFile(ExtractFilePath(Application->ExeName)+totFile);

    }else{ ShowMessage("Snapshot was not saved.\nCheck your Root for CAPTURE.AVI"); }

    btnSnap->Enabled=true;
  }else{
    ShowMessage("Preview window not created.\nPress Enable to start video.");
  }

}
//---------------------------------------------------------------------------





⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -