@@ -1054,6 +1054,9 @@ static void ImGui_ImplWin32_CreateWindow(ImGuiViewport* viewport)
10541054 vd->HwndOwned = true ;
10551055 viewport->PlatformRequestResize = false ;
10561056 viewport->PlatformHandle = viewport->PlatformHandleRaw = vd->Hwnd ;
1057+
1058+ // Secondary viewports store their imgui context
1059+ ::SetPropA (vd->Hwnd, " IMGUI_CONTEXT" , ImGui::GetCurrentContext());
10571060}
10581061
10591062static void ImGui_ImplWin32_DestroyWindow (ImGuiViewport* viewport)
@@ -1256,10 +1259,16 @@ static void ImGui_ImplWin32_OnChangedViewport(ImGuiViewport* viewport)
12561259
12571260static LRESULT CALLBACK ImGui_ImplWin32_WndProcHandler_PlatformWindow (HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam)
12581261{
1259- if (ImGui_ImplWin32_WndProcHandler (hWnd, msg, wParam, lParam))
1260- return true ;
1262+ // Allow secondary viewport WndProc to be called regardless of current context
1263+ ImGuiContext* hwnd_ctx = (ImGuiContext*)::GetPropA (hWnd, " IMGUI_CONTEXT" );
1264+ ImGuiContext* prev_ctx = ImGui::GetCurrentContext ();
1265+ if (hwnd_ctx != prev_ctx && hwnd_ctx != NULL )
1266+ ImGui::SetCurrentContext (hwnd_ctx);
12611267
1262- if (ImGuiViewport* viewport = ImGui::FindViewportByPlatformHandle ((void *)hWnd))
1268+ LRESULT result = 0 ;
1269+ if (ImGui_ImplWin32_WndProcHandler (hWnd, msg, wParam, lParam))
1270+ result = true ;
1271+ else if (ImGuiViewport* viewport = ImGui::FindViewportByPlatformHandle ((void *)hWnd))
12631272 {
12641273 switch (msg)
12651274 {
@@ -1274,20 +1283,23 @@ static LRESULT CALLBACK ImGui_ImplWin32_WndProcHandler_PlatformWindow(HWND hWnd,
12741283 break ;
12751284 case WM_MOUSEACTIVATE:
12761285 if (viewport->Flags & ImGuiViewportFlags_NoFocusOnClick)
1277- return MA_NOACTIVATE;
1286+ result = MA_NOACTIVATE;
12781287 break ;
12791288 case WM_NCHITTEST:
12801289 // Let mouse pass-through the window. This will allow the backend to call io.AddMouseViewportEvent() correctly. (which is optional).
12811290 // The ImGuiViewportFlags_NoInputs flag is set while dragging a viewport, as want to detect the window behind the one we are dragging.
12821291 // If you cannot easily access those viewport flags from your windowing/event code: you may manually synchronize its state e.g. in
12831292 // your main loop after calling UpdatePlatformWindows(). Iterate all viewports/platform windows and pass the flag to your windowing system.
12841293 if (viewport->Flags & ImGuiViewportFlags_NoInputs)
1285- return HTTRANSPARENT;
1294+ result = HTTRANSPARENT;
12861295 break ;
12871296 }
12881297 }
1289-
1290- return DefWindowProc (hWnd, msg, wParam, lParam);
1298+ if (result == 0 )
1299+ result = DefWindowProc (hWnd, msg, wParam, lParam);
1300+ if (hwnd_ctx != prev_ctx && hwnd_ctx != NULL )
1301+ ImGui::SetCurrentContext (prev_ctx);
1302+ return result;
12911303}
12921304
12931305static void ImGui_ImplWin32_InitPlatformInterface (bool platform_has_own_dc)
0 commit comments