Beispiel #1
0
static
void
initMainWindow(HWND hwnd)
{
	// append version number to title
	CString titleFormat = getString(IDS_TITLE);
	setWindowText(hwnd, CStringUtil::format(titleFormat.c_str(), kApplication, kVersion));

	// load configuration
	bool configLoaded =
		loadConfig(ARG->m_config, s_configTime, s_userConfig);
	if (configLoaded) {
		s_lastConfig = ARG->m_config;
	}

	// get settings from registry
	bool isServer = configLoaded;
	int debugLevel = s_defaultDebug;
	CString server;
	HKEY key = CArchMiscWindows::openKey(HKEY_CURRENT_USER, getSettingsPath());
	if (key != NULL) {
		if (isServer && CArchMiscWindows::hasValue(key, "isServer")) {
			isServer = (CArchMiscWindows::readValueInt(key, "isServer") != 0);
		}
		if (CArchMiscWindows::hasValue(key, "debug")) {
			debugLevel = static_cast<int>(
								CArchMiscWindows::readValueInt(key, "debug"));
			if (debugLevel < 0) {
				debugLevel = 0;
			}
			else if (debugLevel > kDEBUG2) {
				debugLevel = kDEBUG2;
			}
		}
		server = CArchMiscWindows::readValueString(key, "server");
		CArchMiscWindows::closeKey(key);
	}

	// choose client/server radio buttons
	HWND child;
	child = getItem(hwnd, IDC_MAIN_CLIENT_RADIO);
	setItemChecked(child, !isServer);
	child = getItem(hwnd, IDC_MAIN_SERVER_RADIO);
	setItemChecked(child, isServer);

	// set server name
	child = getItem(hwnd, IDC_MAIN_CLIENT_SERVER_NAME_EDIT);
	setWindowText(child, server);

	// debug level
	child = getItem(hwnd, IDC_MAIN_DEBUG);
	for (unsigned int i = 0; i < sizeof(s_debugName) /
								sizeof(s_debugName[0]); ++i) {
		SendMessage(child, CB_ADDSTRING, 0, (LPARAM)s_debugName[i][0]);
	}
	SendMessage(child, CB_SETCURSEL, debugLevel, 0);

	// update controls
	enableMainWindowControls(hwnd);
}
Beispiel #2
0
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);
}
Beispiel #3
0
static
void
initMainWindow(HWND hwnd)
{
	// append version number to title
	CString titleFormat = getString(IDS_TITLE);
	setWindowText(hwnd, CStringUtil::format(titleFormat.c_str(), VERSION));

	// load configuration
	bool configLoaded = loadConfig(ARG->m_config);
	ARG->m_oldConfig = ARG->m_config;
	enableSaveControls(hwnd);

	// get settings from registry
	bool isServer = configLoaded;
	int debugLevel = s_defaultDebug;
	CString server;
	HKEY key = CArchMiscWindows::openKey(HKEY_CURRENT_USER, getSettingsPath());
	if (key != NULL) {
		if (isServer && CArchMiscWindows::hasValue(key, "isServer")) {
			isServer = (CArchMiscWindows::readValueInt(key, "isServer") != 0);
		}
		if (CArchMiscWindows::hasValue(key, "debug")) {
			debugLevel = static_cast<int>(
								CArchMiscWindows::readValueInt(key, "debug"));
			if (debugLevel < 0) {
				debugLevel = 0;
			}
			else if (debugLevel > CLog::kDEBUG2) {
				debugLevel = CLog::kDEBUG2;
			}
		}
		server = CArchMiscWindows::readValueString(key, "server");
		CArchMiscWindows::closeKey(key);
	}

	// choose client/server radio buttons
	HWND child;
	child = getItem(hwnd, IDC_MAIN_CLIENT_RADIO);
	setItemChecked(child, !isServer);
	child = getItem(hwnd, IDC_MAIN_SERVER_RADIO);
	setItemChecked(child, isServer);

	// set server name
	child = getItem(hwnd, IDC_MAIN_CLIENT_SERVER_NAME_EDIT);
	setWindowText(child, server);

	// if config is loaded then initialize server controls
	if (configLoaded) {
		int i = 1;
		child = getItem(hwnd, IDC_MAIN_SERVER_SCREENS_LIST);
		for (CConfig::const_iterator index = ARG->m_config.begin();
								index != ARG->m_config.end(); ++i, ++index) {
			ARG->m_screens.push_back(*index);
			CString item = CStringUtil::print("%d. %s", i, index->c_str());
			SendMessage(child, LB_ADDSTRING, 0, (LPARAM)item.c_str());
		}
	}

	// debug level
	child = getItem(hwnd, IDC_MAIN_DEBUG);
	for (unsigned int i = 0; i < sizeof(s_debugName) /
								sizeof(s_debugName[0]); ++i) {
		SendMessage(child, CB_ADDSTRING, 0, (LPARAM)s_debugName[i][0]);
	}
	SendMessage(child, CB_SETCURSEL, debugLevel, 0);

	// update neighbor combo boxes
	enableMainWindowControls(hwnd);
	updateNeighbors(hwnd);
}
Beispiel #4
0
static
LRESULT CALLBACK
mainWndProc(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
{
	switch (message) {
	case WM_COMMAND:
		switch (LOWORD(wParam)) {
		case IDCANCEL:
			// test for unsaved data
			if (ARG->m_config != ARG->m_oldConfig) {
				if (!askVerify(hwnd, getString(IDS_UNSAVED_DATA_REALLY_QUIT))) {
					return 0;
				}
			}

			// 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 (ARG->m_config != ARG->m_oldConfig) {
				if (!saveConfig(ARG->m_config, false)) {
					showError(hwnd, CStringUtil::format(
								getString(IDS_SAVE_FAILED).c_str(),
								getErrorString(GetLastError()).c_str()));
					return 0;
				}
				ARG->m_oldConfig = ARG->m_config;
				enableSaveControls(hwnd);
			}

			// 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: {
			// construct command line
			CString cmdLine = getCommandLine(hwnd, false);
			if (!cmdLine.empty()) {
				// run dialog
				CAutoStart autoStart(hwnd,
							isClientChecked(hwnd) ? NULL : &ARG->m_config,
							cmdLine);
				autoStart.doModal();
				if (autoStart.wasUserConfigSaved()) {
					ARG->m_oldConfig = ARG->m_config;
					enableSaveControls(hwnd);
				}
			}
			return 0;
		}

		case IDC_MAIN_SAVE:
			if (!saveConfig(ARG->m_config, false)) {
				showError(hwnd, CStringUtil::format(
								getString(IDS_SAVE_FAILED).c_str(),
								getErrorString(GetLastError()).c_str()));
			}
			else {
				ARG->m_oldConfig = ARG->m_config;
				enableSaveControls(hwnd);
			}
			return 0;

		case IDC_MAIN_CLIENT_RADIO:
		case IDC_MAIN_SERVER_RADIO:
			enableMainWindowControls(hwnd);
			return 0;

		case IDC_MAIN_SERVER_ADD_BUTTON:
			addScreen(hwnd);
			return 0;

		case IDC_MAIN_SERVER_EDIT_BUTTON:
			editScreen(hwnd);
			return 0;

		case IDC_MAIN_SERVER_REMOVE_BUTTON:
			removeScreen(hwnd);
			return 0;

		case IDC_MAIN_SERVER_SCREENS_LIST:
			if (HIWORD(wParam) == LBN_SELCHANGE) {
				enableScreensControls(hwnd);
				updateNeighbors(hwnd);
			}
			else if (HIWORD(wParam) == LBN_DBLCLK) {
				editScreen(hwnd);
				return 0;
			}
			break;

		case IDC_MAIN_SERVER_LEFT_COMBO:
			if (HIWORD(wParam) == CBN_SELENDOK) {
				changeNeighbor(hwnd, (HWND)lParam, kLeft);
				return 0;
			}
			break;

		case IDC_MAIN_SERVER_RIGHT_COMBO:
			if (HIWORD(wParam) == CBN_SELENDOK) {
				changeNeighbor(hwnd, (HWND)lParam, kRight);
				return 0;
			}
			break;

		case IDC_MAIN_SERVER_TOP_COMBO:
			if (HIWORD(wParam) == CBN_SELENDOK) {
				changeNeighbor(hwnd, (HWND)lParam, kTop);
				return 0;
			}
			break;

		case IDC_MAIN_SERVER_BOTTOM_COMBO:
			if (HIWORD(wParam) == CBN_SELENDOK) {
				changeNeighbor(hwnd, (HWND)lParam, kBottom);
				return 0;
			}
			break;

		case IDC_MAIN_OPTIONS:
			s_globalOptions->doModal();
			enableSaveControls(hwnd);
			break;

		case IDC_MAIN_ADVANCED:
			s_advancedOptions->doModal(isClientChecked(hwnd));
			enableSaveControls(hwnd);
			break;
		}

	default:
		break;
	}
	return DefDlgProc(hwnd, message, wParam, lParam);
}
Beispiel #5
0
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);
}