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

MPColorTrackerApp.cpp

Go to the documentation of this file.
00001 // MPColorTrackerApp.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_MPCOLORTRACKERAPP, 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_MPCOLORTRACKERAPP);
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_MPCOLORTRACKERAPP);
00110         wcex.hCursor            = LoadCursor(NULL, IDC_ARROW);
00111         wcex.hbrBackground      = (HBRUSH)(COLOR_WINDOW+1);
00112         wcex.lpszMenuName       = (LPCSTR)IDC_MPCOLORTRACKERAPP;
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          m_directShow.SetProject(ds_colorTracker);       
00145          m_directShow.SetInput(320, 240);
00146          m_directShow.RunDirectShow(hWnd);
00147    SetThreadPriority(GetCurrentThread(), THREAD_PRIORITY_NORMAL-1);
00148 
00149    ShowWindow(hWnd, nCmdShow);
00150    UpdateWindow(hWnd);
00151 
00152    return TRUE;
00153 }
00154 
00155 // ================================================================
00156 
00157 //
00158 //  FUNCTION: WndProc(HWND, unsigned, WORD, LONG)
00159 //
00160 //  PURPOSE:  Processes messages for the main window.
00161 //
00162 //  WM_COMMAND  - process the application menu
00163 //  WM_PAINT    - Paint the main window
00164 //  WM_DESTROY  - post a quit message and return
00165 //
00166 //
00167 void HandleEvent()
00168 {
00169 
00170 }
00171 
00172 // ================================================================
00173 
00174 LRESULT CALLBACK WndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
00175 {
00176         int wmId, wmEvent;
00177 //      PAINTSTRUCT ps;
00178 //      HDC hdc;
00179         TCHAR szHello[MAX_LOADSTRING];
00180         LoadString(hInst, IDS_HELLO, szHello, MAX_LOADSTRING);
00181 
00182         switch (message)
00183         {
00184                 case WM_GRAPHNOTIFY:
00185                     HandleEvent();
00186                         break;
00187                 case WM_COMMAND:
00188                         wmId    = LOWORD(wParam);
00189                         wmEvent = HIWORD(wParam);
00190                         // Parse the menu selections:
00191                         switch (wmId)
00192                         {
00193                                 case IDM_ABOUT:
00194                                    DialogBox(hInst, (LPCTSTR)IDD_ABOUTBOX, hWnd, (DLGPROC)About);
00195                                    break;
00196                                 case IDM_EXIT:
00197 
00198                                    DestroyWindow(hWnd);
00199                                    break;
00200                                 default:
00201                                    return DefWindowProc(hWnd, message, wParam, lParam);
00202                         }
00203                         break;
00204 
00205 
00206                 case WM_PAINT:
00207 //                      hdc = BeginPaint(hWnd, &ps);
00208 //                      // TODO: Add any drawing code here...
00209 //                      RECT rt;
00210 //                      GetClientRect(hWnd, &rt);
00211 //                      DrawText(hdc, szHello, strlen(szHello), &rt, DT_CENTER);
00212 //                      EndPaint(hWnd, &ps);
00213                         break;
00214 //              case WM_SIZE:
00215 //              {
00216 //                      int nWidth = LOWORD(lParam);  // width of client area
00217 //                      int nHeight = HIWORD(lParam); // height of client area
00218 //                      switch(wParam)
00219 //                      {
00220 //                      case SIZE_MINIMIZED:
00221 //                              pWindow->put_Visible(OAFALSE);
00222 //                              break;
00223 //                      default:
00224 //                              pWindow->put_Visible(OATRUE);
00225 //                              break;
00226 //                      }
00227 //                      break;
00228 //              }
00229                 case WM_DESTROY:
00230                         PostQuitMessage(0);
00231                         break;
00232                 default:
00233                         return DefWindowProc(hWnd, message, wParam, lParam);
00234    }
00235    return 0;
00236 }
00237 
00238 // ================================================================
00239 
00240 // Mesage handler for about box.
00241 LRESULT CALLBACK About(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
00242 {
00243         switch (message)
00244         {
00245                 case WM_INITDIALOG:
00246                                 return TRUE;
00247 
00248                 case WM_COMMAND:
00249                         if (LOWORD(wParam) == IDOK || LOWORD(wParam) == IDCANCEL)
00250                         {
00251                                 EndDialog(hWnd, LOWORD(wParam));
00252                                 return TRUE;
00253                         }
00254                         break;
00255         }
00256     return FALSE;
00257 }
00258 
00259 // ================================================================
00260 
00261 void Msg(TCHAR *szFormat, ...)
00262 {
00263     TCHAR szBuffer[1024];  // Large buffer for very long filenames (like HTTP)
00264 
00265     // Format the input string
00266 
00267         va_list pArgs;
00268     va_start(pArgs, szFormat);
00269     _vstprintf(szBuffer, szFormat, pArgs);
00270     va_end(pArgs);
00271 
00272     // Display a message box with the formatted string
00273     MessageBox(NULL, szBuffer, TEXT("First Grab Sample"), MB_OK);
00274 }
00275 
00276 // ================================================================
00277 

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