summaryrefslogtreecommitdiff
path: root/pugl/pugl_win.cpp
diff options
context:
space:
mode:
authorDavid Robillard <d@drobilla.net>2015-11-11 15:41:12 -0500
committerDavid Robillard <d@drobilla.net>2015-11-11 15:41:12 -0500
commit95a42df7a459fb089d2d55b52c7c84f2a296c0f4 (patch)
treeee94d5047914497d0322a53626d74fcd7b24e41e /pugl/pugl_win.cpp
parentb10540d1ffddb487e8dacb6dc77d4e0d8bdf6be0 (diff)
Add API to set window class name
Diffstat (limited to 'pugl/pugl_win.cpp')
-rw-r--r--pugl/pugl_win.cpp34
1 files changed, 14 insertions, 20 deletions
diff --git a/pugl/pugl_win.cpp b/pugl/pugl_win.cpp
index 849decb..251dd9b 100644
--- a/pugl/pugl_win.cpp
+++ b/pugl/pugl_win.cpp
@@ -112,31 +112,25 @@ puglLeaveContext(PuglView* view, bool flush)
int
puglCreateWindow(PuglView* view, const char* title)
{
+ static const TCHAR* DEFAULT_CLASSNAME = "Pugl";
+
PuglInternals* impl = view->impl;
if (!title) {
title = "Window";
}
- // FIXME: This is nasty, and pugl should not have static anything.
- // Should class be a parameter? Does this make sense on other platforms?
- static int wc_count = 0;
- char classNameBuf[256];
- _snprintf(classNameBuf, sizeof(classNameBuf), "x%d%s", wc_count++, title);
- classNameBuf[sizeof(classNameBuf) - 1] = '\0';
-
- impl->wc.style = CS_OWNDC;
- impl->wc.lpfnWndProc = wndProc;
- impl->wc.cbClsExtra = 0;
- impl->wc.cbWndExtra = 0;
- impl->wc.hInstance = 0;
- impl->wc.hIcon = LoadIcon(NULL, IDI_APPLICATION);
- impl->wc.hCursor = LoadCursor(NULL, IDC_ARROW);
- impl->wc.hbrBackground = (HBRUSH)GetStockObject(BLACK_BRUSH);
- impl->wc.lpszMenuName = NULL;
- impl->wc.lpszClassName = strdup(classNameBuf);
-
- if (!RegisterClass(&impl->wc)) {
+ 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 = view->windowClass ? view->windowClass : DEFAULT_CLASSNAME;
+ if (!RegisterClassEx(&wc)) {
free((void*)impl->wc.lpszClassName);
free(impl);
free(view);
@@ -161,7 +155,7 @@ puglCreateWindow(PuglView* view, const char* title)
impl->hwnd = CreateWindowEx(
WS_EX_TOPMOST,
- classNameBuf, title,
+ wc.lpszClassName, title,
(view->parent ? WS_CHILD : winFlags),
CW_USEDEFAULT, CW_USEDEFAULT, wr.right-wr.left, wr.bottom-wr.top,
(HWND)view->parent, NULL, NULL, NULL);