From 4fa2b3a6e99bbb11abc68d1b1e87a6c71cc09f54 Mon Sep 17 00:00:00 2001 From: David Rowe Date: Mon, 9 Feb 2015 22:07:12 -0800 Subject: [PATCH 1/2] Fix maximized Windows window unintentionally changing to windowed This stops a maximized Windows window changing to being windowed when you click on a menu item. --- interface/src/Application.cpp | 13 +++++++++++-- interface/src/Application.h | 2 ++ interface/src/main.cpp | 3 +-- 3 files changed, 14 insertions(+), 4 deletions(-) diff --git a/interface/src/Application.cpp b/interface/src/Application.cpp index 95b8cbb835..aa24711509 100644 --- a/interface/src/Application.cpp +++ b/interface/src/Application.cpp @@ -156,18 +156,27 @@ public: bool nativeEventFilter(const QByteArray &eventType, void* msg, long* result) Q_DECL_OVERRIDE { if (eventType == "windows_generic_MSG") { MSG* message = (MSG*)msg; + if (message->message == UWM_IDENTIFY_INSTANCES) { *result = UWM_IDENTIFY_INSTANCES; return true; } - if (message->message == WM_SHOWWINDOW) { - Application::getInstance()->getWindow()->showNormal(); + + if (message->message == UWM_SHOW_APPLICATION) { + MainWindow* applicationWindow = Application::getInstance()->getWindow(); + if (applicationWindow->isMinimized()) { + applicationWindow->showNormal(); // Restores to windowed or maximized state appropriately. + } + Application::getInstance()->setActiveWindow(applicationWindow); // Flashes the taskbar icon if not focus. + return true; } + if (message->message == WM_COPYDATA) { COPYDATASTRUCT* pcds = (COPYDATASTRUCT*)(message->lParam); QUrl url = QUrl((const char*)(pcds->lpData)); if (url.isValid() && url.scheme() == HIFI_URL_SCHEME) { DependencyManager::get()->handleLookupString(url.toString()); + return true; } } } diff --git a/interface/src/Application.h b/interface/src/Application.h index e131766309..d015d09035 100644 --- a/interface/src/Application.h +++ b/interface/src/Application.h @@ -117,6 +117,8 @@ static const QString INFO_EDIT_ENTITIES_PATH = "html/edit-entities-commands.html #ifdef Q_OS_WIN static const UINT UWM_IDENTIFY_INSTANCES = RegisterWindowMessage("UWM_IDENTIFY_INSTANCES_{8AB82783-B74A-4258-955B-8188C22AA0D6}"); +static const UINT UWM_SHOW_APPLICATION = + RegisterWindowMessage("UWM_SHOW_APPLICATION_{71123FD6-3DA8-4DC1-9C27-8A12A6250CBA}"); #endif class Application; diff --git a/interface/src/main.cpp b/interface/src/main.cpp index 4881bd4ff4..61278821ee 100644 --- a/interface/src/main.cpp +++ b/interface/src/main.cpp @@ -46,8 +46,7 @@ int main(int argc, const char * argv[]) { HWND otherInstance = NULL; EnumWindows(enumWindowsCallback, (LPARAM)&otherInstance); if (otherInstance) { - ShowWindow(otherInstance, SW_RESTORE); - SetForegroundWindow(otherInstance); + SendMessage(otherInstance, UWM_SHOW_APPLICATION, 0, 0); QUrl url = QUrl(argv[1]); if (url.isValid() && url.scheme() == HIFI_URL_SCHEME) { From 45c0d0e6a963d3def1e2e59d6ee50f9d996ac6ec Mon Sep 17 00:00:00 2001 From: David Rowe Date: Mon, 9 Feb 2015 23:50:43 -0800 Subject: [PATCH 2/2] Fix Windows --url command line parameter handling --- interface/src/main.cpp | 33 ++++++++++++++++++++++++++------- 1 file changed, 26 insertions(+), 7 deletions(-) diff --git a/interface/src/main.cpp b/interface/src/main.cpp index 61278821ee..64ecb2b9e7 100644 --- a/interface/src/main.cpp +++ b/interface/src/main.cpp @@ -8,6 +8,7 @@ // See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html // +#include #include #include #include @@ -36,7 +37,7 @@ static BOOL CALLBACK enumWindowsCallback(HWND hWnd, LPARAM lParam) { #endif -int main(int argc, const char * argv[]) { +int main(int argc, const char* argv[]) { #ifdef Q_OS_WIN // Run only one instance of Interface at a time. HANDLE mutex = CreateMutex(NULL, FALSE, "High Fidelity Interface"); @@ -46,14 +47,32 @@ int main(int argc, const char * argv[]) { HWND otherInstance = NULL; EnumWindows(enumWindowsCallback, (LPARAM)&otherInstance); if (otherInstance) { + // Show other instance. SendMessage(otherInstance, UWM_SHOW_APPLICATION, 0, 0); - QUrl url = QUrl(argv[1]); - if (url.isValid() && url.scheme() == HIFI_URL_SCHEME) { - COPYDATASTRUCT cds; - cds.cbData = strlen(argv[1]) + 1; - cds.lpData = (PVOID)argv[1]; - SendMessage(otherInstance, WM_COPYDATA, 0, (LPARAM)&cds); + // Send command line --url value to other instance. + if (argc >= 3) { + QStringList arguments; + for (int i = 0; i < argc; i += 1) { + arguments << argv[i]; + } + + QCommandLineParser parser; + QCommandLineOption urlOption("url", "", "value"); + parser.addOption(urlOption); + parser.process(arguments); + + if (parser.isSet(urlOption)) { + QUrl url = QUrl(parser.value(urlOption)); + if (url.isValid() && url.scheme() == HIFI_URL_SCHEME) { + QByteArray urlBytes = url.toString().toLatin1(); + const char* urlChars = urlBytes.data(); + COPYDATASTRUCT cds; + cds.cbData = urlBytes.length() + 1; + cds.lpData = (PVOID)urlChars; + SendMessage(otherInstance, WM_COPYDATA, 0, (LPARAM)&cds); + } + } } } return 0;