SAMPLE2.C
资源名称:RGBEASY.ZIP [点击查看]
上传用户:guoxiu1214
上传日期:2019-02-27
资源大小:876k
文件大小:6k
源码类别:
多显示器编程
开发平台:
Visual C++
- /*******************************************************************************
- Copyright Datapath Ltd. 2008.
- File: SAMPLE2.C
- Purpose: VisionRGB-PRO and VisionRGB-X example program that shows how to display
- an RGB window and change its capture settings using a dialog.
- History:
- 16 JAN 08 SB Created.
- *******************************************************************************/
- #include <windows.h>
- #include <commctrl.h>
- #include <rgb.h>
- #include <rgbapi.h>
- #include <rgberror.h>
- #include "sample2.h"
- #include "resource.h"
- /* Static Constants ***********************************************************/
- static const TCHAR
- RGBWindowClass[] = { TEXT("RGBSampleWndClass") },
- Property[] = { TEXT("RGB") },
- Caption[] = { TEXT("RGB Sample 2") };
- /* Global Variables ***********************************************************/
- static HWND gHWnd = NULL;
- static HINSTANCE gHInstance = NULL;
- /******************************************************************************/
- LRESULT CALLBACK
- RGBWndProc (
- HWND hWnd,
- UINT message,
- WPARAM wParam,
- LPARAM lParam )
- {
- switch ( message )
- {
- case WM_COMMAND:
- {
- switch ( LOWORD ( wParam ) )
- {
- case IDM_EXIT:
- {
- DestroyWindow ( hWnd );
- break;
- }
- case IDM_INPUTSETTINGS:
- {
- HRGB hRGB = (HRGB)GetProp ( hWnd, Property );
- DoProperties ( gHInstance, hWnd, hRGB, 0 );
- break;
- }
- }
- break;
- }
- case WM_CREATE:
- {
- LPCREATESTRUCT pCreateStruct = (LPCREATESTRUCT) lParam;
- SetProp ( hWnd, Property, pCreateStruct->lpCreateParams );
- break;
- }
- case WM_CLOSE:
- {
- DestroyWindow ( hWnd );
- break;
- }
- case WM_DESTROY:
- {
- HRGB hRGB = (HRGB)RemoveProp ( hWnd, Property );
- if ( hRGB )
- {
- RGBCloseInput ( hRGB );
- }
- PostQuitMessage ( 1 );
- break;
- }
- default:
- {
- return DefWindowProc ( hWnd, message, wParam, lParam );
- }
- }
- return 0;
- }
- /******************************************************************************/
- unsigned long
- RegisterRGBWindowClass (
- HINSTANCE hInstance )
- {
- WNDCLASS wc;
- wc.style = 0;
- wc.lpfnWndProc = (WNDPROC)RGBWndProc;
- wc.cbClsExtra = 0;
- wc.cbWndExtra = 0;
- wc.hInstance = hInstance;
- wc.hIcon = LoadIcon ( hInstance, MAKEINTRESOURCE ( IDI_ICON ));
- wc.hCursor = LoadCursor ( NULL, IDC_ARROW );
- wc.hbrBackground = NULL;
- wc.lpszMenuName = MAKEINTRESOURCE ( IDR_MENU );
- wc.lpszClassName = RGBWindowClass;
- if ( RegisterClass ( &wc ) == 0 )
- {
- return GetLastError ();
- }
- else
- {
- return 0;
- }
- }
- /******************************************************************************/
- unsigned long
- CreateRGBWindow (
- unsigned long input )
- {
- unsigned long error;
- HRGB hRGB;
- error = RGBOpenInput ( input, &hRGB );
- if ( error == 0 )
- {
- /* Create the window. */
- gHWnd = CreateWindow ( RGBWindowClass, Caption,
- WS_OVERLAPPEDWINDOW,
- CW_USEDEFAULT, CW_USEDEFAULT, 640, 480,
- (HWND)NULL, NULL, gHInstance, (LPVOID)hRGB );
- if ( gHWnd )
- {
- RGBSetWindow ( hRGB, gHWnd );
- ShowWindow ( gHWnd, SW_SHOWNORMAL );
- /* Maximise the capture rate. */
- RGBSetFrameDropping ( hRGB, 0 );
- return 0;
- }
- else
- {
- error = GetLastError ( );
- }
- RGBCloseInput ( hRGB );
- }
- return error;
- }
- /******************************************************************************/
- int APIENTRY
- wWinMain (
- HINSTANCE hInstance,
- HINSTANCE hPrevInstance,
- LPSTR lpCmdLine,
- int nShowCmd )
- {
- unsigned long error;
- MSG msg;
- HRGBDLL hRGBDLL = 0;
- gHInstance = hInstance;
- /* Register the RGBWindowClass. */
- error = RegisterRGBWindowClass ( gHInstance );
- if ( error )
- {
- TCHAR buffer[256];
- wsprintf ( buffer, TEXT("Error Registering the window class: 0x%08x"), error );
- MessageBox ( NULL, buffer, Caption, MB_OK | MB_ICONERROR );
- return error;
- }
- error = RGBLoad ( &hRGBDLL );
- if ( error )
- {
- TCHAR buffer[256];
- wsprintf ( buffer, TEXT("Error returned from RGBLoad: 0x%08x"), error );
- MessageBox ( NULL, buffer, Caption, MB_OK | MB_ICONERROR );
- return error;
- }
- /* Create the application window on input 0. */
- error = CreateRGBWindow ( 0 );
- if ( error )
- {
- TCHAR buffer[256];
- wsprintf ( buffer, TEXT("Error creating the application window: 0x%08x"),
- error );
- MessageBox ( NULL, buffer, Caption, MB_OK | MB_ICONERROR );
- return error;
- }
- /* Sit in the message loop until we are stopped. */
- while ( GetMessage ( &msg, NULL, 0,0 ))
- {
- TranslateMessage ( &msg );
- DispatchMessage ( &msg );
- }
- if ( hRGBDLL )
- {
- error = RGBFree ( hRGBDLL );
- }
- return error;
- UNREFERENCED_PARAMETER ( nShowCmd );
- UNREFERENCED_PARAMETER ( lpCmdLine );
- UNREFERENCED_PARAMETER ( hPrevInstance );
- }
- /******************************************************************************/