int WINAPI WinMain(HINSTANCE instance, HINSTANCE, LPSTR, int nCmdShow) { CArch arch(instance); CLOG; CArgs args; s_instance = instance; // register main window (dialog) class WNDCLASSEX classInfo; classInfo.cbSize = sizeof(classInfo); classInfo.style = CS_HREDRAW | CS_VREDRAW; classInfo.lpfnWndProc = &mainWndProc; classInfo.cbClsExtra = 0; classInfo.cbWndExtra = DLGWINDOWEXTRA; classInfo.hInstance = instance; classInfo.hIcon = (HICON)LoadImage(instance, MAKEINTRESOURCE(IDI_SYNERGY), IMAGE_ICON, 32, 32, LR_SHARED); classInfo.hCursor = LoadCursor(NULL, IDC_ARROW); classInfo.hbrBackground = reinterpret_cast<HBRUSH>(COLOR_3DFACE + 1); classInfo.lpszMenuName = NULL; classInfo.lpszClassName = s_mainClass; classInfo.hIconSm = (HICON)LoadImage(instance, MAKEINTRESOURCE(IDI_SYNERGY), IMAGE_ICON, 16, 16, LR_SHARED); RegisterClassEx(&classInfo); // create main window HWND mainWindow = CreateDialog(s_instance, MAKEINTRESOURCE(IDD_MAIN), 0, NULL); // prep windows initMainWindow(mainWindow); s_globalOptions = new CGlobalOptions(mainWindow, &ARG->m_config); s_advancedOptions = new CAdvancedOptions(mainWindow, &ARG->m_config); // show window ShowWindow(mainWindow, nCmdShow); // main loop MSG msg; bool done = false; do { switch (GetMessage(&msg, NULL, 0, 0)) { case -1: // error break; case 0: // quit done = true; break; default: if (!IsDialogMessage(mainWindow, &msg)) { TranslateMessage(&msg); DispatchMessage(&msg); } break; } } while (!done); // save values to registry saveMainWindow(mainWindow); return msg.wParam; }
static LRESULT CALLBACK mainWndProc(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam) { switch (message) { case WM_COMMAND: switch (LOWORD(wParam)) { case IDCANCEL: // save data if (saveMainWindow(hwnd, true)) { // quit PostQuitMessage(0); } return 0; case IDOK: case IDC_MAIN_TEST: { // note if testing const bool testing = (LOWORD(wParam) == IDC_MAIN_TEST); // save data if (saveMainWindow(hwnd, false)) { // launch child app DWORD threadID; HANDLE thread = launchApp(hwnd, testing, &threadID); if (thread == NULL) { return 0; } // handle child program if (testing) { // wait for process to stop, allowing the user to kill it waitForChild(hwnd, thread, threadID); // clean up CloseHandle(thread); } else { // don't need thread handle CloseHandle(thread); // notify of success askOkay(hwnd, getString(IDS_STARTED_TITLE), getString(IDS_STARTED)); // quit PostQuitMessage(0); } } return 0; } case IDC_MAIN_AUTOSTART: { CString cmdLine; if (saveMainWindow(hwnd, false, &cmdLine)) { // run dialog CAutoStart autoStart(hwnd, !isClientChecked(hwnd), cmdLine); autoStart.doModal(); } return 0; } case IDC_MAIN_CLIENT_RADIO: case IDC_MAIN_SERVER_RADIO: enableMainWindowControls(hwnd); return 0; case IDC_MAIN_SCREENS: s_screensLinks->doModal(); break; case IDC_MAIN_OPTIONS: s_globalOptions->doModal(); break; case IDC_MAIN_ADVANCED: s_advancedOptions->doModal(isClientChecked(hwnd)); break; } default: break; } return DefDlgProc(hwnd, message, wParam, lParam); }
static LRESULT CALLBACK mainWndProc(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam) { switch (message) { case WM_ACTIVATE: if (LOWORD(wParam) != WA_INACTIVE) { // activated // see if the configuration changed if (isConfigNewer(s_configTime, s_userConfig)) { CString message2 = getString(IDS_CONFIG_CHANGED); if (askVerify(hwnd, message2)) { time_t configTime; bool userConfig; CConfig newConfig; if (loadConfig(newConfig, configTime, userConfig) && userConfig == s_userConfig) { ARG->m_config = newConfig; s_lastConfig = ARG->m_config; } else { message2 = getString(IDS_LOAD_FAILED); showError(hwnd, message2); s_lastConfig = CConfig(); } } } } else { // deactivated; write configuration if (!isShowingDialog()) { saveMainWindow(hwnd, SAVE_QUIET); } } break; case WM_COMMAND: switch (LOWORD(wParam)) { case IDCANCEL: // save data if (saveMainWindow(hwnd, SAVE_QUITING)) { // quit PostQuitMessage(0); } return 0; case IDOK: case IDC_MAIN_TEST: { // note if testing const bool testing = (LOWORD(wParam) == IDC_MAIN_TEST); // save data if (saveMainWindow(hwnd, SAVE_NORMAL)) { // launch child app DWORD threadID; HANDLE thread; if (!launchApp(hwnd, testing, &thread, &threadID)) { return 0; } // handle child program if (testing) { // wait for process to stop, allowing the user to kill it waitForChild(hwnd, thread, threadID); // clean up CloseHandle(thread); } else { // don't need thread handle if (thread != NULL) { CloseHandle(thread); } // notify of success: now disabled - it's silly to notify a success //askOkay(hwnd, getString(IDS_STARTED_TITLE), getString(IDS_STARTED)); // quit PostQuitMessage(0); } } return 0; } case IDC_MAIN_AUTOSTART: { CString cmdLine; if (saveMainWindow(hwnd, SAVE_NORMAL, &cmdLine)) { // run dialog CAutoStart autoStart(hwnd, !isClientChecked(hwnd), cmdLine); autoStart.doModal(); } return 0; } case IDC_MAIN_CLIENT_RADIO: case IDC_MAIN_SERVER_RADIO: enableMainWindowControls(hwnd); return 0; case IDC_MAIN_SCREENS: s_screensLinks->doModal(); break; case IDC_MAIN_OPTIONS: s_globalOptions->doModal(); break; case IDC_MAIN_ADVANCED: s_advancedOptions->doModal(isClientChecked(hwnd)); break; case IDC_MAIN_HOTKEYS: s_hotkeyOptions->doModal(); break; case IDC_MAIN_INFO: s_info->doModal(); break; } default: break; } return DefDlgProc(hwnd, message, wParam, lParam); }