diff options
author | David Robillard <d@drobilla.net> | 2015-11-11 15:41:12 -0500 |
---|---|---|
committer | David Robillard <d@drobilla.net> | 2015-11-11 15:41:12 -0500 |
commit | 95a42df7a459fb089d2d55b52c7c84f2a296c0f4 (patch) | |
tree | ee94d5047914497d0322a53626d74fcd7b24e41e | |
parent | b10540d1ffddb487e8dacb6dc77d4e0d8bdf6be0 (diff) |
Add API to set window class name
-rw-r--r-- | pugl/pugl.h | 6 | ||||
-rw-r--r-- | pugl/pugl_internal.h | 8 | ||||
-rw-r--r-- | pugl/pugl_win.cpp | 34 | ||||
-rw-r--r-- | pugl_test.c | 1 |
4 files changed, 29 insertions, 20 deletions
diff --git a/pugl/pugl.h b/pugl/pugl.h index 074297c..4d5467a 100644 --- a/pugl/pugl.h +++ b/pugl/pugl.h @@ -153,6 +153,12 @@ PUGL_API PuglView* puglInit(int* pargc, char** argv); /** + Set the window class name before creating a window. +*/ +PUGL_API void +puglInitWindowClass(PuglView* view, const char* name); + +/** Set the parent window before creating a window (for embedding). */ PUGL_API void diff --git a/pugl/pugl_internal.h b/pugl/pugl_internal.h index 1006c90..7dc9cfa 100644 --- a/pugl/pugl_internal.h +++ b/pugl/pugl_internal.h @@ -47,6 +47,7 @@ struct PuglViewImpl { PuglInternals* impl; + char* windowClass; PuglNativeWindow parent; PuglContextType ctx_type; uintptr_t transient_parent; @@ -117,6 +118,13 @@ puglInitWindowAspectRatio(PuglView* view, } void +puglInitWindowClass(PuglView* view, const char* name) +{ + free(view->windowClass); + view->windowClass = strdup(name); +} + +void puglInitWindowParent(PuglView* view, PuglNativeWindow parent) { view->parent = parent; 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); diff --git a/pugl_test.c b/pugl_test.c index eb192c9..b534162 100644 --- a/pugl_test.c +++ b/pugl_test.c @@ -173,6 +173,7 @@ main(int argc, char** argv) } PuglView* view = puglInit(NULL, NULL); + puglInitWindowClass(view, "PuglTest"); puglInitWindowSize(view, 512, 512); puglInitWindowMinSize(view, 256, 256); puglInitResizable(view, resizable); |