The Machine Perception Toolbox

[Introduction]- [News]- [Download]- [Screenshots]- [Manual (pdf)]- [Forums]- [API Reference]- [Repository ]

 

Main Page | Namespace List | Class Hierarchy | Alphabetical List | Class List | Directories | File List | Namespace Members | Class Members | File Members | Related Pages

MPFaceDetectorApp.cpp

Go to the documentation of this file.
00001 // MPFaceDetectorApp.cpp : Defines the entry point for the application.
00002 //
00003 
00004 #include "stdafx.h"
00005 #include "resource.h"
00006 #include <atlbase.h>
00007 #include <streams.h>
00008 #include <initguid.h>
00009 #include "DirectShow/MPDirectShow.h"
00010 #include <cstdio>
00011 
00012 #define MAX_LOADSTRING 100
00013 
00014 // Global Variables:
00015 HINSTANCE hInst;                                                                // current instance
00016 TCHAR szTitle[MAX_LOADSTRING];                                                          // The title bar text
00017 TCHAR szWindowClass[MAX_LOADSTRING];                                                            // The title bar text
00018 
00019 // Foward declarations of functions included in this code module:
00020 ATOM                            MyRegisterClass(HINSTANCE hInstance);
00021 BOOL                            InitInstance(HINSTANCE, int);
00022 LRESULT CALLBACK        WndProc(HWND, UINT, WPARAM, LPARAM);
00023 LRESULT CALLBACK        About(HWND, UINT, WPARAM, LPARAM);
00024 
00025 //
00026 //HWND WINAPI CreateTrackbar(
00027 //       HWND hwndDlg,
00028 //       UINT iMin,
00029 //       UINT iMax,
00030 //       UINT iSelMin,
00031 //       UINT iSelMAx,
00032 //       UINT iXPosition,
00033 //       UINT iYPosition,
00034 //       UINT iLength);
00035 
00036 //LRESULT CALLBACK DlgProc(HWND hGlg, UINT message, WPARAM wParam, LPARAM lParam);
00037 #define WM_GRAPHNOTIFY   WM_APP + 1
00038 
00039 MPDirectShow m_directShow;
00040 
00041 //return from callback 'cause graph is stopping
00042 BYTE bReturnImmediatelyFromCallback = 0;
00043 
00045 
00046 // ================================================================
00047 
00048 int APIENTRY WinMain(HINSTANCE hInstance,
00049                      HINSTANCE hPrevInstance,
00050                      LPSTR     lpCmdLine,
00051                      int       nCmdShow)
00052 {
00053         // TODO: Place code here.
00054         MSG msg;
00055         HACCEL hAccelTable;
00056 
00057         // Initialize global strings
00058         LoadString(hInstance, IDS_APP_TITLE, szTitle, MAX_LOADSTRING);
00059         LoadString(hInstance, IDC_MPFACEDETECTORAPP, szWindowClass, MAX_LOADSTRING);
00060         MyRegisterClass(hInstance);
00061 
00062         // Perform application initialization:
00063         if (!InitInstance (hInstance, nCmdShow))
00064         {
00065                 return FALSE;
00066         }
00067 
00068         hAccelTable = LoadAccelerators(hInstance, (LPCTSTR)IDC_MPFACEDETECTORAPP);
00069 
00070         // Main message loop:
00071         while (GetMessage(&msg, NULL, 0, 0))
00072         {
00073                 if (!TranslateAccelerator(msg.hwnd, hAccelTable, &msg))
00074                 {
00075                         TranslateMessage(&msg);
00076                         DispatchMessage(&msg);
00077                 }
00078         }
00079 
00080         return msg.wParam;
00081 }
00082 
00083 // ================================================================
00084 
00085 //
00086 //  FUNCTION: MyRegisterClass()
00087 //
00088 //  PURPOSE: Registers the window class.
00089 //
00090 //  COMMENTS:
00091 //
00092 //    This function and its usage is only necessary if you want this code
00093 //    to be compatible with Win32 systems prior to the 'RegisterClassEx'
00094 //    function that was added to Windows 95. It is important to call this function
00095 //    so that the application will get 'well formed' small icons associated
00096 //    with it.
00097 //
00098 ATOM MyRegisterClass(HINSTANCE hInstance)
00099 {
00100         WNDCLASSEX wcex;
00101 
00102         wcex.cbSize = sizeof(WNDCLASSEX);
00103 
00104         wcex.style                      = CS_HREDRAW | CS_VREDRAW;
00105         wcex.lpfnWndProc        = (WNDPROC)WndProc;
00106         wcex.cbClsExtra         = 0;
00107         wcex.cbWndExtra         = 0;
00108         wcex.hInstance          = hInstance;
00109         wcex.hIcon                      = LoadIcon(hInstance, (LPCTSTR)IDI_MPFACEDETECTORAPP);
00110         wcex.hCursor            = LoadCursor(NULL, IDC_ARROW);
00111         wcex.hbrBackground      = (HBRUSH)(COLOR_WINDOW+1);
00112         wcex.lpszMenuName       = (LPCSTR)IDC_MPFACEDETECTORAPP;
00113         wcex.lpszClassName      = szWindowClass;
00114         wcex.hIconSm            = LoadIcon(wcex.hInstance, (LPCTSTR)IDI_SMALL);
00115 
00116         return RegisterClassEx(&wcex);
00117 }
00118 
00119 // ================================================================
00120 
00121 //
00122 //   FUNCTION: InitInstance(HANDLE, int)
00123 //
00124 //   PURPOSE: Saves instance handle and creates main window
00125 //
00126 //   COMMENTS:
00127 //
00128 //        In this function, we save the instance handle in a global variable and
00129 //        create and display the main program window.
00130 //
00131 BOOL InitInstance(HINSTANCE hInstance, int nCmdShow)
00132 {
00133    HWND hWnd;
00134 
00135    hInst = hInstance; // Store instance handle in our global variable
00136 
00137    hWnd = CreateWindow(szWindowClass, szTitle, WS_DLGFRAME|WS_SYSMENU|WS_MINIMIZEBOX,
00138       CW_USEDEFAULT, 0, CW_USEDEFAULT, 0, NULL, NULL, hInstance, NULL);
00139 
00140    if (!hWnd)
00141    {
00142       return FALSE;
00143    }
00144 #ifdef USE_ADA
00145          m_directShow.SetProject(ds_mpisearchAda);
00146 #else
00147          m_directShow.SetProject(ds_mpisearch);
00148 #endif
00149          m_directShow.SetInput(320, 240);
00150          m_directShow.RunDirectShow(hWnd);
00151    SetThreadPriority(GetCurrentThread(), THREAD_PRIORITY_NORMAL-1);
00152 
00153    ShowWindow(hWnd, nCmdShow);
00154    UpdateWindow(hWnd);
00155 
00156    return TRUE;
00157 }
00158 
00159 // ================================================================
00160 
00161 //
00162 //  FUNCTION: WndProc(HWND, unsigned, WORD, LONG)
00163 //
00164 //  PURPOSE:  Processes messages for the main window.
00165 //
00166 //  WM_COMMAND  - process the application menu
00167 //  WM_PAINT    - Paint the main window
00168 //  WM_DESTROY  - post a quit message and return
00169 //
00170 //
00171 void HandleEvent()
00172 {
00173 
00174 }
00175 
00176 // ================================================================
00177 
00178 LRESULT CALLBACK WndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
00179 {
00180         int wmId, wmEvent;
00181 //      PAINTSTRUCT ps;
00182 //      HDC hdc;
00183         TCHAR szHello[MAX_LOADSTRING];
00184         LoadString(hInst, IDS_HELLO, szHello, MAX_LOADSTRING);
00185 
00186         switch (message)
00187         {
00188                 case WM_GRAPHNOTIFY:
00189                     HandleEvent();
00190                         break;
00191                 case WM_COMMAND:
00192                         wmId    = LOWORD(wParam);
00193                         wmEvent = HIWORD(wParam);
00194                         // Parse the menu selections:
00195                         switch (wmId)
00196                         {
00197                                 case IDM_ABOUT:
00198                                    DialogBox(hInst, (LPCTSTR)IDD_ABOUTBOX, hWnd, (DLGPROC)About);
00199                                    break;
00200                                 case IDM_EXIT:
00201 
00202                                    DestroyWindow(hWnd);
00203                                    break;
00204                                 default:
00205                                    return DefWindowProc(hWnd, message, wParam, lParam);
00206                         }
00207                         break;
00208 
00209 
00210                 case WM_PAINT:
00211 //                      hdc = BeginPaint(hWnd, &ps);
00212 //                      // TODO: Add any drawing code here...
00213 //                      RECT rt;
00214 //                      GetClientRect(hWnd, &rt);
00215 //                      DrawText(hdc, szHello, strlen(szHello), &rt, DT_CENTER);
00216 //                      EndPaint(hWnd, &ps);
00217                         break;
00218 //              case WM_SIZE:
00219 //              {
00220 //                      int nWidth = LOWORD(lParam);  // width of client area
00221 //                      int nHeight = HIWORD(lParam); // height of client area
00222 //                      switch(wParam)
00223 //                      {
00224 //                      case SIZE_MINIMIZED:
00225 //                              pWindow->put_Visible(OAFALSE);
00226 //                              break;
00227 //                      default:
00228 //                              pWindow->put_Visible(OATRUE);
00229 //                              break;
00230 //                      }
00231 //                      break;
00232 //              }
00233                 case WM_DESTROY:
00234                         PostQuitMessage(0);
00235                         break;
00236                 default:
00237                         return DefWindowProc(hWnd, message, wParam, lParam);
00238    }
00239    return 0;
00240 }
00241 
00242 // ================================================================
00243 
00244 // Mesage handler for about box.
00245 LRESULT CALLBACK About(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
00246 {
00247         switch (message)
00248         {
00249                 case WM_INITDIALOG:
00250                                 return TRUE;
00251 
00252                 case WM_COMMAND:
00253                         if (LOWORD(wParam) == IDOK || LOWORD(wParam) == IDCANCEL)
00254                         {
00255                                 EndDialog(hWnd, LOWORD(wParam));
00256                                 return TRUE;
00257                         }
00258                         break;
00259         }
00260     return FALSE;
00261 }
00262 
00263 // ================================================================
00264 
00265 void Msg(TCHAR *szFormat, ...)
00266 {
00267     TCHAR szBuffer[1024];  // Large buffer for very long filenames (like HTTP)
00268 
00269     // Format the input string
00270 
00271         va_list pArgs;
00272     va_start(pArgs, szFormat);
00273     _vstprintf(szBuffer, szFormat, pArgs);
00274     va_end(pArgs);
00275 
00276     // Display a message box with the formatted string
00277     MessageBox(NULL, szBuffer, TEXT("First Grab Sample"), MB_OK);
00278 }
00279 
00280 // ================================================================
00281 

Generated on Mon Nov 8 17:07:43 2004 for MPT by  doxygen 1.3.9.1