aboutsummaryrefslogtreecommitdiffstats
path: root/pugl
diff options
context:
space:
mode:
authorDavid Robillard <d@drobilla.net>2019-08-03 10:38:34 +0200
committerDavid Robillard <d@drobilla.net>2019-09-03 08:32:16 +0200
commite148e8f3646ae756254879f2df015431bbd036ed (patch)
tree8dc20f5b1ce8be732c70a49eb50b663fa101c91e /pugl
parente3b2f305b98747c84fd87eb97e3fa8516acecbfb (diff)
downloadpugl-e148e8f3646ae756254879f2df015431bbd036ed.tar.gz
pugl-e148e8f3646ae756254879f2df015431bbd036ed.tar.bz2
pugl-e148e8f3646ae756254879f2df015431bbd036ed.zip
Windows: Fix class registration for multiple views
Diffstat (limited to 'pugl')
-rw-r--r--pugl/detail/win.c38
1 files changed, 24 insertions, 14 deletions
diff --git a/pugl/detail/win.c b/pugl/detail/win.c
index 3a30814..42b9427 100644
--- a/pugl/detail/win.c
+++ b/pugl/detail/win.c
@@ -52,6 +52,9 @@ typedef BOOL (WINAPI *PFN_SetProcessDPIAware)(void);
static const TCHAR* DEFAULT_CLASSNAME = "Pugl";
+LRESULT CALLBACK
+wndProc(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam);
+
static wchar_t*
puglUtf8ToWideChar(const char* const utf8)
{
@@ -65,8 +68,25 @@ puglUtf8ToWideChar(const char* const utf8)
return NULL;
}
-LRESULT CALLBACK
-wndProc(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam);
+static bool
+puglRegisterWindowClass(const char* name)
+{
+ WNDCLASSEX wc = { 0 };
+ if (GetClassInfoEx(GetModuleHandle(NULL), name, &wc)) {
+ return true; // Already registered
+ }
+
+ wc.cbSize = sizeof(wc);
+ wc.style = CS_OWNDC;
+ wc.lpfnWndProc = wndProc;
+ wc.hInstance = GetModuleHandle(NULL);
+ wc.hIcon = LoadIcon(NULL, IDI_APPLICATION);
+ wc.hCursor = LoadCursor(NULL, IDC_ARROW);
+ wc.hbrBackground = (HBRUSH)GetStockObject(BLACK_BRUSH);
+ wc.lpszClassName = name;
+
+ return RegisterClassEx(&wc);
+}
PuglInternals*
puglInitInternals(void)
@@ -104,18 +124,8 @@ puglCreateWindow(PuglView* view, const char* title)
EnumDisplaySettingsA(NULL, ENUM_CURRENT_SETTINGS, &devMode);
view->impl->refreshRate = devMode.dmDisplayFrequency;
- // Register window class
- WNDCLASSEX wc;
- memset(&wc, 0, sizeof(wc));
- wc.cbSize = sizeof(wc);
- wc.style = CS_OWNDC;
- wc.lpfnWndProc = wndProc;
- wc.hInstance = GetModuleHandle(NULL);
- wc.hIcon = LoadIcon(NULL, IDI_APPLICATION); // TODO: user-specified icon
- wc.hCursor = LoadCursor(NULL, IDC_ARROW);
- wc.hbrBackground = (HBRUSH)GetStockObject(BLACK_BRUSH);
- wc.lpszClassName = className;
- if (!RegisterClassEx(&wc)) {
+ // Register window class if necessary
+ if (!puglRegisterWindowClass(className)) {
return 1;
}