aboutsummaryrefslogtreecommitdiffstats
path: root/pugl
diff options
context:
space:
mode:
authorDavid Robillard <d@drobilla.net>2019-07-31 21:05:52 +0200
committerDavid Robillard <d@drobilla.net>2019-07-31 21:18:17 +0200
commita865ca522f56feb5573f26d668270ce3b721e382 (patch)
tree7e66aa7b4cc7971f6847a62b7351e73eca33a0e3 /pugl
parentbb0834637c7620870d784180436c90492c89db9b (diff)
downloadpugl-a865ca522f56feb5573f26d668270ce3b721e382.tar.gz
pugl-a865ca522f56feb5573f26d668270ce3b721e382.tar.bz2
pugl-a865ca522f56feb5573f26d668270ce3b721e382.zip
Windows: Support UTF8 in window titles
Diffstat (limited to 'pugl')
-rw-r--r--pugl/detail/win.c20
1 files changed, 19 insertions, 1 deletions
diff --git a/pugl/detail/win.c b/pugl/detail/win.c
index 6b56c07..6e176b6 100644
--- a/pugl/detail/win.c
+++ b/pugl/detail/win.c
@@ -52,6 +52,19 @@ typedef BOOL (WINAPI *PFN_SetProcessDPIAware)(void);
static const TCHAR* DEFAULT_CLASSNAME = "Pugl";
+static wchar_t*
+puglUtf8ToWideChar(const char* const utf8)
+{
+ const int len = MultiByteToWideChar(CP_UTF8, 0, utf8, -1, NULL, 0);
+ if (len > 0) {
+ wchar_t* result = (wchar_t*)calloc(len, sizeof(wchar_t));
+ MultiByteToWideChar(CP_UTF8, 0, utf8, -1, result, len);
+ return result;
+ }
+
+ return NULL;
+}
+
LRESULT CALLBACK
wndProc(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam);
@@ -117,7 +130,12 @@ puglCreateWindow(PuglView* view, const char* title)
return 3;
}
- SetWindowText(impl->hwnd, title);
+ wchar_t* wtitle = puglUtf8ToWideChar(title);
+ if (wtitle) {
+ SetWindowTextW(impl->hwnd, wtitle);
+ free(wtitle);
+ }
+
SetWindowLongPtr(impl->hwnd, GWLP_USERDATA, (LONG_PTR)view);
return 0;