int main( const int argc , const char ** argv ) { if( flagSpecified(argc,argv,kFlagLogo) ) displayLogo(); initializeRandomGenerator(); initializeSsl(); // Not the most beautiful piece of initialization code :) if( controllerRequested(argc,argv) ) startController(argc,argv); else if( serverRequested(argc,argv) ) startServer(argc,argv); else if( clientRequested(argc,argv) ) startClient(argc,argv); else if( eventStreamRequested(argc,argv) ) startEventStream(argc,argv); else if( generateHashRequested(argc,argv) ) startGenerateHash(argc,argv); else if( addControllerRequested(argc,argv) ) startAddController(argc,argv); else usage(); cleanupSsl(); cleanupLogger(); return EXIT_SUCCESS; }
int APIENTRY _tWinMain(_In_ HINSTANCE hInstance, _In_opt_ HINSTANCE hPrevInstance, _In_ LPTSTR lpCmdLine, _In_ int nCmdShow) { UNREFERENCED_PARAMETER(hPrevInstance); UNREFERENCED_PARAMETER(lpCmdLine); MSG msg; HACCEL hAccelTable; if (duplicateExist()) exit(0); myLpCmdLine = lpCmdLine; // Initialize global strings LoadString(hInstance, IDS_APP_TITLE, szTitle, MAX_LOADSTRING); LoadString(hInstance, IDC_MOVEPOINTBASE, szWindowClass, MAX_LOADSTRING); MyRegisterClass(hInstance); // Perform application initialization: if (!InitInstance (hInstance, SW_HIDE)) { return FALSE; } //start controller process startController(); //system("movepoint.exe"); //system doesn't return a processId //WinExec(TEXT("movepoint.exe"), SW_HIDE); //If launched by WinExec would not access Eye Camera hAccelTable = LoadAccelerators(hInstance, MAKEINTRESOURCE(IDC_MOVEPOINTBASE)); // Main message loop: while (GetMessage(&msg, NULL, 0, 0)) { if (!TranslateAccelerator(msg.hwnd, hAccelTable, &msg)) { TranslateMessage(&msg); DispatchMessage(&msg); } } return (int) msg.wParam; }
// // FUNCTION: WndProc(HWND, UINT, WPARAM, LPARAM) // // 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) { int wmId, wmEvent; PAINTSTRUCT ps; HDC hdc; switch (message) { case WM_COMMAND: wmId = LOWORD(wParam); wmEvent = HIWORD(wParam); // Parse the menu selections: switch (wmId) { case IDM_ABOUT: DialogBox(hInst, MAKEINTRESOURCE(IDD_ABOUTBOX), hWnd, About); break; case IDM_EXIT: DestroyWindow(hWnd); break; default: return DefWindowProc(hWnd, message, wParam, lParam); } break; case WM_PAINT: hdc = BeginPaint(hWnd, &ps); // TODO: Add any drawing code here... EndPaint(hWnd, &ps); break; case WM_DESTROY: UnregisterDeviceNotification(hde); PostQuitMessage(0); break; case WM_WTSSESSION_CHANGE: if (wParam == WTS_SESSION_LOCK || wParam == WTS_CONSOLE_DISCONNECT) { TerminateMovePoint(); } if (wParam == WTS_SESSION_UNLOCK || wParam == WTS_CONSOLE_CONNECT) { startController(); } break; case WM_DEVICECHANGE: if (wParam == DBT_DEVICEARRIVAL || wParam == DBT_DEVICEREMOVECOMPLETE) { PDEV_BROADCAST_HDR pHdr = (PDEV_BROADCAST_HDR)lParam; PDEV_BROADCAST_DEVICEINTERFACE pDevInf = (PDEV_BROADCAST_DEVICEINTERFACE)pHdr; //MessageBox(hWnd, pDevInf->dbcc_name, TEXT("WM"), MB_OK); std::string dbcc(pDevInf->dbcc_name); std::transform(dbcc.begin(), dbcc.end(), dbcc.begin(), ::tolower); std::size_t vidPos = dbcc.find("vid_"); std::size_t pidPos = dbcc.find("pid_"); std::string vid, pid; if (vidPos != std::string::npos && pidPos != std::string::npos) { vid = dbcc.substr(vidPos+4, 4); pid = dbcc.substr(pidPos+4, 4); //std::string tid = vid + " " + pid; //MessageBox(hWnd, tid.c_str(), TEXT("WM"), MB_OK); } //Is the device a Move controller? if ((vid=="8888" && pid=="0508") || (vid=="054c" && pid=="03d5")) { if (wParam == DBT_DEVICEARRIVAL) { startController(); } else if (wParam == DBT_DEVICEREMOVECOMPLETE) { TerminateMovePoint(); } } else { return DefWindowProc(hWnd, message, wParam, lParam); } } else { return DefWindowProc(hWnd, message, wParam, lParam); } break; //Move controllers sleep pretty much immediately after system suspend, //so we can simply terminate the actual controller thread case WM_ENDSESSION: if (wParam == TRUE) { //shutting down TerminateMovePoint(); } return DefWindowProc(hWnd, message, wParam, lParam); break; case WM_POWERBROADCAST: if (wParam == PBT_APMSUSPEND) { //System suspending TerminateMovePoint(); } return DefWindowProc(hWnd, message, wParam, lParam); break; default: return DefWindowProc(hWnd, message, wParam, lParam); } return 0; }