From 3064e6d10cf1acd1030de24d6c213d4d1308c5fa Mon Sep 17 00:00:00 2001 From: Marius PvW Date: Fri, 21 Feb 2025 22:37:51 +0100 Subject: [PATCH] Viewports + Backends: Win32: Fixed setting title bar text when application is compiled without UNICODE. (#7979, #5725) --- backends/imgui_impl_win32.cpp | 7 ++++++- docs/CHANGELOG.txt | 2 ++ 2 files changed, 8 insertions(+), 1 deletion(-) diff --git a/backends/imgui_impl_win32.cpp b/backends/imgui_impl_win32.cpp index 30776608dd77..8bc9b29be42a 100644 --- a/backends/imgui_impl_win32.cpp +++ b/backends/imgui_impl_win32.cpp @@ -1272,7 +1272,12 @@ static void ImGui_ImplWin32_SetWindowTitle(ImGuiViewport* viewport, const char* ImVector title_w; title_w.resize(n); ::MultiByteToWideChar(CP_UTF8, 0, title, -1, title_w.Data, n); - ::SetWindowTextW(vd->Hwnd, title_w.Data); + + // Calling SetWindowTextW() in a project where UNICODE is not set doesn't work but there's a trick + // which is to pass it directly to the DefWindowProcW() handler. + // See: https://stackoverflow.com/questions/9410681/setwindowtextw-in-an-ansi-project + //::SetWindowTextW(vd->Hwnd, title_w.Data); + ::DefWindowProcW(vd->Hwnd, WM_SETTEXT, 0, (LPARAM)title_w.Data); } static void ImGui_ImplWin32_SetWindowAlpha(ImGuiViewport* viewport, float alpha) diff --git a/docs/CHANGELOG.txt b/docs/CHANGELOG.txt index 15fe4b8e7a8e..3b2aad28df8a 100644 --- a/docs/CHANGELOG.txt +++ b/docs/CHANGELOG.txt @@ -105,6 +105,8 @@ Docking+Viewports Branch: - Viewports: fixed an assert when a window load settings with a position outside monitor bounds, when there are multiple monitors. (#8393, #8385) [@gaborodriguez] +- Viewports + Backends: Win32: Fixed setting title bar text when application + is compiled without UNICODE. (#7979, #5725) [@lailoken] - Backends: GLFW, SDL2/SDL3: Update monitors and work areas information every frame, as the later may change regardless of monitor/display changes. (#8415) - Backends: Win32: WM_SETTINGCHANGE's SPI_SETWORKAREA message also triggers a refresh