From ddf878c13a08dd212e3dcc3ce1bd708ea2373dbb Mon Sep 17 00:00:00 2001 From: falkTX Date: Sat, 19 Mar 2022 17:52:40 +0000 Subject: [PATCH] Add WINDOWS_ICON_ID build macro, show msgbox on windows on error Signed-off-by: falkTX --- Makefile.base.mk | 4 ++++ dgl/src/pugl.cpp | 25 ++++++++++++++++++++++++- distrho/src/DistrhoPluginJACK.cpp | 8 ++++++-- 3 files changed, 34 insertions(+), 3 deletions(-) diff --git a/Makefile.base.mk b/Makefile.base.mk index 62b6c2cd..908171e7 100644 --- a/Makefile.base.mk +++ b/Makefile.base.mk @@ -444,6 +444,10 @@ ifeq ($(FILE_BROWSER_DISABLED),true) BUILD_CXX_FLAGS += -DDGL_FILE_BROWSER_DISABLED endif +ifneq ($(WINDOWS_ICON_ID),) +BUILD_CXX_FLAGS += -DDGL_WINDOWS_ICON_ID=$(WINDOWS_ICON_ID) +endif + ifeq ($(USE_OPENGL3),true) BUILD_CXX_FLAGS += -DDGL_USE_OPENGL3 endif diff --git a/dgl/src/pugl.cpp b/dgl/src/pugl.cpp index bf21d2c6..154d8a68 100644 --- a/dgl/src/pugl.cpp +++ b/dgl/src/pugl.cpp @@ -567,7 +567,30 @@ void puglWin32ShowCentered(PuglView* const view) } else { - ShowWindow(impl->hwnd, SW_SHOWNORMAL); +#ifdef DGL_WINDOWS_ICON_ID + WNDCLASSEX wClass; + std::memset(&wClass, 0, sizeof(wClass)); + + const HINSTANCE hInstance = GetModuleHandle(nullptr); + + if (GetClassInfoEx(hInstance, view->world->className, &wClass)) + wClass.hIcon = LoadIcon(nullptr, MAKEINTRESOURCE(DGL_WINDOWS_ICON_ID)); + + SetClassLongPtr(impl->hwnd, GCLP_HICON, (LONG_PTR) LoadIcon(hInstance, MAKEINTRESOURCE(DGL_WINDOWS_ICON_ID))); +#endif + + MONITORINFO mInfo; + std::memset(&mInfo, 0, sizeof(mInfo)); + mInfo.cbSize = sizeof(mInfo); + + if (GetMonitorInfo(MonitorFromWindow(impl->hwnd, MONITOR_DEFAULTTOPRIMARY), &mInfo)) + SetWindowPos(impl->hwnd, + HWND_TOP, + mInfo.rcWork.left + (mInfo.rcWork.right - view->frame.width) / 2, + mInfo.rcWork.top + (mInfo.rcWork.bottom - view->frame.height) / 2, + 0, 0, SWP_SHOWWINDOW|SWP_NOSIZE); + else + ShowWindow(impl->hwnd, SW_NORMAL); } SetFocus(impl->hwnd); diff --git a/distrho/src/DistrhoPluginJACK.cpp b/distrho/src/DistrhoPluginJACK.cpp index 0b417fc1..f9423543 100644 --- a/distrho/src/DistrhoPluginJACK.cpp +++ b/distrho/src/DistrhoPluginJACK.cpp @@ -944,11 +944,15 @@ int main(int argc, char* argv[]) if (errorString.isNotEmpty()) { errorString[errorString.length()-2] = '.'; - d_stderr("Failed to create jack client, reason was:\n%s", errorString.buffer()); + d_stderr("Failed to create the JACK client, reason was:\n%s", errorString.buffer()); } else - d_stderr("Failed to create jack client, cannot continue!"); + d_stderr("Failed to create the JACK client, cannot continue!"); + #if defined(DISTRHO_OS_WINDOWS) && DISTRHO_PLUGIN_HAS_UI + const String win32error = "Failed to create JACK client, reason was:\n" + errorString; + MessageBoxA(nullptr, win32error.buffer(), "", MB_ICONERROR); + #endif return 1; }