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

📄 airguard_c.cpp

📁 用vc编写的视频采集端口编成
💻 CPP
📖 第 1 页 / 共 5 页
字号:
// AirGuard_C.cpp : Defines the entry point for the application.
//

#include "stdafx.h"
#include "resource.h"
#include "AirGuard_C.h"




int APIENTRY WinMain(HINSTANCE hInstance,
                     HINSTANCE hPrevInstance,
                     LPSTR     lpCmdLine,
                     int       nCmdShow)
{
 	// TODO: Place code here.
	MSG msg;
	HACCEL hAccelTable;

	// Initialize global strings
	LoadString(hInstance, IDS_APP_TITLE, szTitle, MAX_LOADSTRING);
	LoadString(hInstance, IDC_AIRGUARD_C, szWindowClass, MAX_LOADSTRING);
	MyRegisterClass(hInstance);

	// Perform application initialization:
	if (!InitInstance (hInstance, nCmdShow)) 
	{
		return FALSE;
	}

	hAccelTable = LoadAccelerators(hInstance, (LPCTSTR)IDC_AIRGUARD_C);

	// Main message loop:
	while (GetMessage(&msg, NULL, 0, 0)) 
	{
		if (!TranslateAccelerator(msg.hwnd, hAccelTable, &msg)) 
		{
			TranslateMessage(&msg);
			DispatchMessage(&msg);
		}
	}

	return msg.wParam;
}



//
//  FUNCTION: MyRegisterClass()
//
//  PURPOSE: Registers the window class.
//
//  COMMENTS:
//
//    This function and its usage is only necessary if you want this code
//    to be compatible with Win32 systems prior to the 'RegisterClassEx'
//    function that was added to Windows 95. It is important to call this function
//    so that the application will get 'well formed' small icons associated
//    with it.
//
ATOM MyRegisterClass(HINSTANCE hInstance)
// Function:		Register some window class that will be used in the program
// Return Value:	If there is an error in this procedure return 0
//					else return an atom that uniquely identifies the last class being registered.
{
	//-------------------------------------
	// Register Main Window
	WNDCLASSEX wcex;
	ATOM RtnValue;
	
	wcex.cbSize = sizeof(WNDCLASSEX); 

	wcex.style			= CS_HREDRAW | CS_VREDRAW;
	wcex.lpfnWndProc	= (WNDPROC)WndProc;
	wcex.cbClsExtra		= 0;
	wcex.cbWndExtra		= 0;
	wcex.hInstance		= hInstance;
	wcex.hIcon			= LoadIcon(hInstance, (LPCTSTR)IDI_AIRGUARD_C);
	wcex.hCursor		= LoadCursor(NULL, IDC_ARROW);
	wcex.hbrBackground	= (HBRUSH)GetStockObject(LTGRAY_BRUSH);
	wcex.lpszMenuName	= (LPCSTR)IDC_AIRGUARD_C;
	wcex.lpszClassName	= szWindowClass;
	wcex.hIconSm		= LoadIcon(wcex.hInstance, (LPCTSTR)IDI_SMALL);
	RtnValue = RegisterClassEx(&wcex);
	if(!RtnValue)
		return 0;
	//----------------------------------------	
	// Register Startup Window
	wcex.lpfnWndProc = StartupWndProc;
	wcex.lpszMenuName = NULL;
	wcex.lpszClassName = "StartupWindow";
	RtnValue = RegisterClassEx(&wcex);
	if(!RtnValue)
		return 0;

	//----------------------------------------
	// Register Video Window
	wcex.style	= CS_HREDRAW | CS_VREDRAW | CS_DBLCLKS;
	wcex.lpfnWndProc = VideoWndProc;
	wcex.lpszClassName = "VideoWindow";
	RtnValue = RegisterClassEx(&wcex);
	if(!RtnValue)
		return 0;

	wcex.style	= CS_HREDRAW | CS_VREDRAW | CS_DBLCLKS;
	wcex.lpfnWndProc = Video_MPEGWndProc;
	wcex.lpszClassName = "Video_MPEGWindow";
	RtnValue = RegisterClassEx(&wcex);
	if(!RtnValue)
		return 0;

	wcex.style	= CS_HREDRAW | CS_VREDRAW | CS_DBLCLKS;
	wcex.lpfnWndProc = Video_JIMUWndProc;
	wcex.lpszClassName = "Video_JIMUWindow";
	RtnValue = RegisterClassEx(&wcex);
	if(!RtnValue)
		return 0;

	//----------------------------------------
	// Register Logo Window
	wcex.style	= CS_HREDRAW | CS_VREDRAW | CS_DBLCLKS;
	wcex.lpfnWndProc = LogoWndProc;
	wcex.lpszClassName = "LogoWindow";
	RtnValue = RegisterClassEx(&wcex);
	if(!RtnValue)
		return 0;

	//----------------------------------------
	// Register SiteSettings Window
	wcex.style	= CS_HREDRAW | CS_VREDRAW | CS_DBLCLKS;
	wcex.lpfnWndProc = SiteSettingsWndProc;
	wcex.lpszClassName = "SiteSettingsWindow";
	RtnValue = RegisterClassEx(&wcex);
	if(!RtnValue)
		return 0;

	//----------------------------------------
	// Register Up Button Class
	wcex.cbSize = sizeof(WNDCLASSEX);
	wcex.style = CS_HREDRAW |	CS_VREDRAW	;                       // Class style.
	wcex.lpfnWndProc = (WNDPROC)UpButtonWndProc; // Window procedure for this class.
    wcex.cbClsExtra = 0;                  // No per-class extra data.
    wcex.cbWndExtra = 0;                  // No per-window extra data.
    wcex.hInstance = hInstance;           // Application that owns the class.
    wcex.hIcon = LoadIcon(NULL, IDI_APPLICATION);
    wcex.hCursor = LoadCursor(NULL, IDC_ARROW);
    wcex.hbrBackground = (HBRUSH)GetStockObject(LTGRAY_BRUSH);
    wcex.lpszMenuName = NULL;   // Name of menu resource in .RC file.
    wcex.lpszClassName = "UpBtnCls"; // Name used in call to CreateWindow.
	wcex.hIconSm = LoadIcon(NULL, IDI_APPLICATION);
	RtnValue = RegisterClassEx(&wcex);
	if(!RtnValue)
		return 0;
	
	//----------------------------------------
	// Register Left Button Class
	wcex.lpfnWndProc = (WNDPROC)LeftButtonWndProc;
	wcex.lpszClassName = "LeftButtonWndClass";
	RtnValue = RegisterClassEx(&wcex);
	if(!RtnValue)
		return 0;

	//----------------------------------------
	// Register Right Button Class
	wcex.lpfnWndProc = (WNDPROC)RightButtonWndProc;
	wcex.lpszClassName = "RightButtonWndClass";
	RtnValue = RegisterClassEx(&wcex);
	if(!RtnValue)
		return 0;

	//----------------------------------------
	// Register Down Button Class
	wcex.lpfnWndProc = (WNDPROC)DownButtonWndProc;
	wcex.lpszClassName = "DownButtonWndClass";
	RtnValue = RegisterClassEx(&wcex);
	if(!RtnValue)
		return 0;

	//----------------------------------------
	// Register Pie Button Class
	wcex.lpfnWndProc = (WNDPROC)PieButtonWndProc;
	wcex.lpszClassName = "PieButtonWndClass";
	RtnValue = RegisterClassEx(&wcex);
	if(!RtnValue)
		return 0;

	//----------------------------------------
	// Register Plus Button Class
	wcex.lpfnWndProc = (WNDPROC)PlusButtonWndProc;
	wcex.lpszClassName = "PlusButtonWndClass";
	RtnValue = RegisterClassEx(&wcex);
	if(!RtnValue)
		return 0;

	//----------------------------------------
	// Register Minus Button Class
	wcex.lpfnWndProc = (WNDPROC)MinusButtonWndProc;
	wcex.lpszClassName = "MinusButtonWndClass";
	RtnValue = RegisterClassEx(&wcex);
	return RtnValue;

}

//
//   FUNCTION: InitInstance(HANDLE, int)
//
//   PURPOSE: Saves instance handle and creates main window
//
//   COMMENTS:
//
//        In this function, we save the instance handle in a global variable and
//        create and display the main program window.
//
BOOL InitInstance(HINSTANCE hInstance, int nCmdShow)
{
   HWND hWnd;
   HANDLE hThreadStartup;
   DWORD dwThreadStartupId;

   g_hInst = hInstance; // Store instance handle in our global variable
   InitCommonControls();

   hThreadStartup = CreateThread(NULL, 0, ThreadStartupFunc, 0, 0, &dwThreadStartupId);
   WaitForSingleObject(hThreadStartup, 60000);

   hWnd = CreateWindowEx(0, szWindowClass, szTitle, WS_VISIBLE | WS_OVERLAPPED | WS_CAPTION | WS_SYSMENU | WS_MINIMIZEBOX ,
      //200, 150, 520, 423, 
	  0, 0, 920, 680,
	  NULL, NULL, hInstance, NULL);

   if (!hWnd)
   {
      return FALSE;
   }

   g_hwndMainWindow = hWnd;		

   ShowWindow(hWnd, nCmdShow);
   UpdateWindow(hWnd);

   return TRUE;
}

//
//  FUNCTION: WndProc(HWND, unsigned, WORD, LONG)
//
//  PURPOSE:  Processes messages for the main window.
//
//  WM_COMMAND	- process the application menu
//  WM_PAINT	- Paint the main window
//  WM_DESTROY	- post a quit message and return
//
//
LRESULT CALLBACK WndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
{

	switch (message) 
	{
		case WM_CREATE:
			MainWindow_OnCreate(hWnd);
			break;
		case WM_COMMAND:
			MainWindow_OnCommand(hWnd, message, wParam, lParam);
			break;
		case WM_HSCROLL:
			MainWindow_OnHScroll(hWnd, wParam, lParam);
			break;
		case WM_ACK:
			MainWindow_OnACK(hWnd, wParam, lParam);
			break;
		case WM_CLIENT_ACCEPT:
			g_myCamera.mySocket.ClientAccept(hWnd, wParam, lParam);
			break;
		case WM_PAINT:
			MainWindow_OnPaint(hWnd, message, wParam, lParam);
			break;
		case WM_MOVE:
			PostMessage(g_hwndVideo_MPEG, WM_PARENTMOVED, wParam, lParam);
			break;
		case WM_TIMER:
			MainWindow_OnTimer(hWnd, message, wParam, lParam);
		case WM_DESTROY:
			PostQuitMessage(0);
			break;
		default:
			return DefWindowProc(hWnd, message, wParam, lParam);
   }
   return 0;
}

bool MainWindow_OnHScroll(HWND hWnd, WPARAM wParam, LPARAM lParam)
{

	int iSelMin = 0;
	int iSelMax = 10;
	int nNotificationCode = LOWORD(wParam);
	int nPosition = HIWORD(wParam);
	HRGN hrgnStandardBar;
	switch (nNotificationCode){
		case TB_THUMBTRACK :
			break;
		case TB_THUMBPOSITION:
			if(g_myCamera.m_iIllumination != nPosition * 10){

				g_myCamera.m_iIllumination = nPosition * 10;

				hrgnStandardBar = (HRGN)CreateRectRgn(45, 35, 95, 155);
				InvalidateRgn(g_hwndMainWindow, hrgnStandardBar, 1);
				UpdateWindow(hWnd);					
				DeleteObject(hrgnStandardBar);
			}
			break;

		case TB_ENDTRACK: 
			nPosition = SendMessage(g_TrackbarIllumination, TBM_GETPOS, 0, 0); 
			if (nPosition > iSelMax) 
			SendMessage(g_TrackbarIllumination, TBM_SETPOS, 
				(WPARAM) TRUE,       // redraw flag 
				(LPARAM) iSelMax);             
			else if (nPosition < iSelMin) 
			SendMessage(g_TrackbarIllumination, TBM_SETPOS, 
				(WPARAM) TRUE,       // redraw flag 
				(LPARAM) iSelMin);             
			break;          
		default: 

			nPosition = (SendMessage(g_TrackbarIllumination, TBM_GETPOS, 0, 0));
			if (g_myCamera.m_iIllumination != nPosition * 10){

				g_myCamera.m_iIllumination = nPosition * 10;
				hrgnStandardBar = (HRGN)CreateRectRgn(45, 35, 95, 155);
				InvalidateRgn(g_hwndMainWindow, hrgnStandardBar, 1);
				UpdateWindow(hWnd);
				DeleteObject(hrgnStandardBar);
			}
			break;  
	}
	return 1;
}

// Mesage handler for about box.
LRESULT CALLBACK About(HWND hDlg, UINT message, WPARAM wParam, LPARAM lParam)
{
	switch (message)
	{
		case WM_INITDIALOG:
				return TRUE;

		case WM_COMMAND:
			if (LOWORD(wParam) == IDOK || LOWORD(wParam) == IDCANCEL) 
			{
				EndDialog(hDlg, LOWORD(wParam));
				return TRUE;
			}
			break;
	}
    return FALSE;
}


// Mesage handler for video window.
LRESULT CALLBACK VideoWndProc(HWND hWnd, UINT wMessage, WPARAM wParam, LPARAM lParam)
{
	HDC hDc;
	PAINTSTRUCT ps;
	static HCURSOR hCursor;
	WORD wTimerID;	
	switch (wMessage)
	{

		case WM_CREATE:
			break;
   		case WM_PAINT:
			hDc = BeginPaint( hWnd, &ps);
			EndPaint( hWnd, &ps);
      		break;
		case WM_SETCURSOR:
			hCursor = LoadCursor(NULL, MAKEINTRESOURCE(IDC_CROSS));
			SetCursor(hCursor);
			return true;

		case WM_RBUTTONDOWN:
			break;
		case WM_TIMER:
			wTimerID = wParam;
			switch (wTimerID){
				case 1:
					break;
				case TIMER_AUTODETECT_CLICK:
					if(g_mySysState.bIsReadyForNextAutoDetecting){
						DetectChimney();
					}
					break;
				case TIMER_AUTODETECT_CAMERAPOSITION:
					switch (g_myCamera.pCameraList[g_myCamera.m_iCurrentCamera].iType){
						case INVALID:
							break;
						case JIMU:
							JIMU_DetectChimneyOnTimer();
							break;
						case MPEG:
							MPEG_DetectChimneyOnTimer1();
							break;
						default:
							break;
					}
					break;

			}
			break;

		case WM_DESTROY:
			PostQuitMessage(0);
			break;
		default:
			return DefWindowProc(hWnd, wMessage, wParam, lParam);
   }
   return 0;
}
LRESULT CALLBACK Video_JIMUWndProc(HWND hWnd, UINT wMessage, WPARAM wParam, LPARAM lParam)
{
	HDC hDc;
	PAINTSTRUCT ps;
	COLORREF crPointColor;
	RECT rect;
	WORD xPos, yPos;
	WORD wGrayValue, r, g, b;
	float fBlackness;
	char lpszMessage[100];
	static HCURSOR hCursor;
	static WORD wButtonState;
	static CDib Dib;
	LONG Disp_X = 0, Disp_Y = 0, Disp_W = 320, Disp_H = 240;

	switch (wParam & 0xff0000)
	{
		// IMG_VLD:
		case 0x10000:
			g_myCamera.JIMU_GetFrame();
			if(g_mySysState.bIsAmplified_JIMU)
				g_myCamera.JIMU_DrawFrame(hWnd, g_myCamera.JIMU_GetEncodedBuf(), 640, 480);
			else
				g_myCamera.JIMU_DrawFrame(hWnd, g_myCamera.JIMU_GetEncodedBuf(), 320, 240);
			break;

		// NO_VIDEO:
		case 0x20000:
			if ((wParam & 0xfff0) == 0x0040)
			{
				MessageBox(hWnd, "No video input !", "error", MB_OK);
			}
			break;
	}

⌨️ 快捷键说明

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