aboutsummaryrefslogtreecommitdiffstats
path: root/pugl
diff options
context:
space:
mode:
Diffstat (limited to 'pugl')
-rw-r--r--pugl/pugl.h6
-rw-r--r--pugl/pugl_internal.h8
-rw-r--r--pugl/pugl_win.cpp34
3 files changed, 28 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);