//============================================================================================ // MAIN //============================================================================================ extern "C" int WINAPI WinMain( HINSTANCE hInstance, // handle to current instance HINSTANCE hPrevInstance, // handle to previous instance LPSTR lpCmdLine, // command line int nCmdShow ){ // show state HANDLE hMutex; TCHAR szTokens[] = "-/"; LPCTSTR lpszToken; int iRes; HWND hDlgWnd; UINT uiTimerID; HRESULT hr; // Check for another instance hMutex = OpenMutex( SYNCHRONIZE, // requested access (lowest possible) FALSE, // allow inheritance (does not matter) x_szMutexName); // unique name if(hMutex){ MessageBox( NULL, "Cannot start the application because another instance is already running.\n", x_szTitle, MB_OK | MB_ICONERROR ); return 1; } hMutex = CreateMutex( NULL, // default security TRUE, // obtain ownership x_szMutexName); // unique name if(!hMutex){ MessageBox( NULL, "Cannot create application mutex.\n", x_szTitle, MB_OK | MB_ICONERROR ); return 1; } // Parse the command line for options lpszToken = FindOneOf(lpCmdLine, szTokens); while (lpszToken != NULL) { if (lstrcmpi(lpszToken, "UnregServer")==0) { iRes = g_UnregisterCOM(); if( iRes != 0 ) { MessageBox( NULL, "Error: Can't unregister server. g_UnregisterCOM() failed.", x_szTitle, MB_OK); } else { MessageBox( NULL, "Success: the server is unregistered.", x_szTitle, MB_OK); } return iRes; } if (lstrcmpi(lpszToken, "RegServer")==0) { iRes = g_RegisterCOM(); if( iRes != 0 ) { MessageBox( NULL, "Error: Can't register server. g_RegisterCOM() failed.", x_szTitle, MB_OK); } else { MessageBox( NULL, "Success: the server is registered.", x_szTitle, MB_OK); } return iRes; } lpszToken = FindOneOf(lpszToken, szTokens); } // while there are tokens //------- Windows staff starts here CP_printfCreate(x_szTitle); // create console window hDlgWnd=CreateDialog(hInstance, MAKEINTRESOURCE(IDD_MAIN_DIALOG), NULL, x_DialogProc); g_hWnd = hDlgWnd; SetWindowText(hDlgWnd, x_szTitle); SendMessage(hDlgWnd, WM_SETICON, ICON_BIG, (LPARAM)LoadIcon(hInstance, MAKEINTRESOURCE(IDI_ICON_APPL))); SendMessage(hDlgWnd, WM_SETICON, ICON_SMALL, (LPARAM)LoadImage(hInstance, MAKEINTRESOURCE(IDI_ICON_APPL), IMAGE_ICON, 16, 16, 0)); ShowWindow(hDlgWnd, SW_SHOW); CP_printf(g_szVersion); CP_printf("\n\n"); uiTimerID = SetTimer( hDlgWnd, TIMER_ID, TIMER_PERIOD_MS, NULL ); if ( uiTimerID == 0){ CP_printf("Error: could not create timer!"); // don't exit we are still functional } CP_printfHide(); // default is no log window // Init COM using single-thread apartment model hr = CoInitialize(NULL); if( hr != S_OK) { MessageBox( NULL, "Error in CoInitializeEx()", x_szTitle, MB_OK); return 1; } iRes = g_Init_LibertyTrack( ); if( iRes != 0 ) { MessageBox( NULL, "Error: g_Init_LibertyTrack() failed.", x_szTitle, MB_OK); return 1; } // Message loop MSG msg; while (GetMessage(&msg, 0, 0, 0)) { // IsDialogMessage() processes keyboard events for the dialog and // passes others to translate/dispatch if(!IsDialogMessage(hDlgWnd,&msg)){ TranslateMessage(&msg); DispatchMessage(&msg); } } // end of uMsg loop KillTimer( hDlgWnd, TIMER_ID); CoUninitialize(); ReleaseMutex(hMutex); return 0; }
//============================================================================================ // MAIN //============================================================================================ extern "C" int WINAPI WinMain( HINSTANCE hInstance, // handle to current instance HINSTANCE hPrevInstance, // handle to previous instance LPSTR lpCmdLine, // command line int nCmdShow ){ // show state TCHAR szTokens[] = "-/"; int iRes; HWND hDlgWnd; UINT uiTimerID; HRESULT hr; // Parse the command line for options LPCTSTR lpszToken = FindOneOf(lpCmdLine, szTokens); while (lpszToken != NULL) { if (lstrcmpi(lpszToken, "UnregServer")==0) { iRes = g_UnregisterCOM(); if( iRes != 0 ) { MessageBox( NULL, "Error: Can't unregister server. g_UnregisterCOM() failed.", x_szTitle, MB_OK); } else { MessageBox( NULL, "Success: the server is unregistered.", x_szTitle, MB_OK); } return iRes; } if (lstrcmpi(lpszToken, "RegServer")==0) { iRes = g_RegisterCOM(); if( iRes != 0 ) { MessageBox( NULL, "Error: Can't register server. g_RegisterCOM() failed.", x_szTitle, MB_OK); } else { MessageBox( NULL, "Success: the server is registered.", x_szTitle, MB_OK); } return iRes; } lpszToken = FindOneOf(lpszToken, szTokens); } // while there are tokens //------- Windows staff starts here CP_printfCreate(x_szTitle); // create console window hDlgWnd=CreateDialog(hInstance, MAKEINTRESOURCE(IDD_MAIN_DIALOG), NULL, x_DialogProc); SetWindowText(hDlgWnd, x_szTitle); SendMessage(hDlgWnd, WM_SETICON, ICON_BIG, (LPARAM)LoadIcon(hInstance, MAKEINTRESOURCE(IDI_ICON_APPL))); SendMessage(hDlgWnd, WM_SETICON, ICON_SMALL, (LPARAM)LoadImage(hInstance, MAKEINTRESOURCE(IDI_ICON_APPL), IMAGE_ICON, 16, 16, 0)); // SetWindowText(GetDlgItem(hDlgWnd, IDC_LBL_VERSION ) , g_szVersion); ShowWindow(hDlgWnd, SW_SHOW); CP_printf(g_szVersion); CP_printf("\n\n"); uiTimerID = SetTimer( hDlgWnd, TIMER_ID, TIMER_PERIOD_MS, NULL ); if ( uiTimerID == 0){ CP_printf("Error: could not create timer!"); // don't exit we are still functional } // Init COM using multi-threaded model hr = CoInitializeEx(NULL, COINIT_MULTITHREADED); //COINIT_APARTMENTTHREADED if( hr != S_OK) { MessageBox( NULL, "Error in CoInitializeEx()", x_szTitle, MB_OK); return 1; } iRes = g_Init_EyeTrack( ); if( iRes != 0 ) { MessageBox( NULL, "Error: g_Init_EyeTrack() failed.", x_szTitle, MB_OK); return 1; } // Message loop MSG msg; while (GetMessage(&msg, 0, 0, 0)) { // Process dialog messages in IsDialogMessage() pass others to translate/dispatch if(!IsDialogMessage(hDlgWnd,&msg)){ TranslateMessage(&msg); DispatchMessage(&msg); } } // end of message loop KillTimer( hDlgWnd, TIMER_ID); CoUninitialize(); return 0; }
//============================================================================================ // MAIN //============================================================================================ extern "C" int WINAPI WinMain( HINSTANCE hInstance, // handle to current instance HINSTANCE hPrevInstance, // handle to previous instance LPSTR lpCmdLine, // command line int nCmdShow ){ // show state HANDLE hMutex; TCHAR szTokens[] = "-/"; LPCTSTR lpszToken; int iRes; HRESULT hRes; x_hInstance = hInstance; // Check for another instance hMutex = OpenMutex( SYNCHRONIZE, // requested access (lowest possible) FALSE, // allow inheritance (does not matter) x_szMutexName); // unique name if(hMutex){ MessageBox( NULL, "Cannot start the application because another instance is already running.\n", x_szTitle, MB_OK | MB_ICONERROR ); return 1; } hMutex = CreateMutex( NULL, // default security TRUE, // obtain ownership x_szMutexName); // unique name if(!hMutex){ MessageBox( NULL, "Cannot create application mutex.\n", x_szTitle, MB_OK | MB_ICONERROR ); return 1; } // Parse the command line for options lpszToken = FindOneOf(lpCmdLine, szTokens); while (lpszToken != NULL) { if (lstrcmpi(lpszToken, "UnregServer")==0) { iRes = g_UnregisterCOM(); if( iRes != 0 ) { MessageBox( NULL, "Error: Can't unregister server. g_UnregisterCOM() failed.", x_szTitle, MB_OK); } else { MessageBox( NULL, "Success: the server is unregistered.", x_szTitle, MB_OK); } return iRes; } if (lstrcmpi(lpszToken, "RegServer")==0) { iRes = g_RegisterCOM(); if( iRes != 0 ) { MessageBox( NULL, "Error: Can't register server. g_RegisterCOM() failed.", x_szTitle, MB_OK); } else { MessageBox( NULL, "Success: the server is registered.", x_szTitle, MB_OK); } return iRes; } lpszToken = FindOneOf(lpszToken, szTokens); } // while there are tokens //------- Regular run starts here // Init COM using single-threaded model hRes = CoInitializeEx(NULL, COINIT_APARTMENTTHREADED); if( hRes != S_OK) { MessageBox( NULL, "Error in CoInitializeEx()", x_szTitle, MB_OK); return 1; } CP_printfCreate(x_szTitle); // create console window CP_printf(g_szVersion); CP_printf("\n\n"); CP_printfHide(); // hide console window //------- Windows main loop is here DialogBox(hInstance, MAKEINTRESOURCE(IDD_MAIN_DIALOG), NULL, x_DialogProc); CP_printfDestroy(); CoUninitialize(); return 0; }