Closed visualFatigue closed 3 months ago
You are not posting enough details about the code. Did you omit the Win32 event loop from your code? (PeekMessage(), TranslateMessage(), DispatchMessage(), as showcased in our examples).
while (g_ApplicationRunning)
{
// 1. initizalize
// 2. render loop
// 3. release
}
This looks very sketchy. Initialization and shutdown should be before and after the update/render loop respectively, not within the loop.
Thanks for your timely reply , I omitted some codes that seem irrelevant to the topic, here are their complete contents
while (g_ApplicationRunning) { XXX::InitializeCore(); XXX::Application* app = Respawn::CreateApplication(hwnd); // initialize app->Run(); // process loop delete app; // release XXX::ShutdownCore(); }
and I execute the Win32 event loop inside the app loop
app->Run();
This is what it looks like inside
` void Application::Run()
{
OnInit();
while (m_Running)
{
m_Window->ProcessEvents(); // the event loop is here
if (!m_Minimized)
{
// render
}
}
OnShutdown();
}`
and the ProcessEvents() is
void WindowsWindow::ProcessEvents() { MSG msg = { 0 }; while (PeekMessage(&msg, m_Window, 0, 0, PM_REMOVE)) { TranslateMessage(&msg); DispatchMessage(&msg); } }
by the way I replace the outside WndProc function in the initialize stage using this way
SetWindowLongPtr(m_Window, GWLP_USERDATA, reinterpret_cast<LONG_PTR>(&m_Data)); SetWindowLongPtr(m_Window, GWLP_WNDPROC, (LONG_PTR)WindowProc);
and this is the actual WindowProc function ` static LRESULT CALLBACK WindowProc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam) { auto& data = ((WindowsWindow::WindowData)GetWindowLongPtr(hwnd, GWLP_USERDATA));
switch (uMsg)
{
case WM_CLOSE:
OnWindowClose(data);
break;
//case WM_CREATE:
// OnWindowCreate(hwnd);
// break;
case WM_SIZE:
OnWindowResize(data, LOWORD(lParam), HIWORD(lParam));
break;
case WM_MOUSEMOVE:
OnMouseMove(data, GET_X_LPARAM(lParam), GET_Y_LPARAM(lParam));
break;
case WM_LBUTTONDOWN:
OnLButtonDown(data, wParam);
break;
case WM_LBUTTONUP:
OnLButtonUp(data, wParam);
break;
case WM_MOUSEWHEEL:
OnMouseWheel(data, GET_WHEEL_DELTA_WPARAM(wParam));
break;
case WM_KEYDOWN:
OnKeyDown(data, wParam);
break;
case WM_KEYUP:
OnKeyUp(data, wParam);
break;
case WM_CHAR:
OnChar(data, wParam);
break;
case WM_DESTROY:
PostQuitMessage(0);
break;
default:
return DefWindowProc(hwnd, uMsg, wParam, lParam);
}
return 0;
}`
The purpose of all these designs is to mimic how the GLFW platform binding operates, to make platform binding replacement as transparent as possible.
by the way I replace the outside WndProc function in the initialize stage using this way
There is your problem. The function you replaced was the one that delegated messages to ImGui_ImplWin32_WndProcHandler()
, which is required for working interactions. Your replacement doesn't do that, but it needs to.
I find the problem!
I forget call the
if (ImGui_ImplWin32_WndProcHandler(hwnd, uMsg, wParam, lParam)) return true;
in the internal WindowProc().
After that, everything is normal. But when I move any element out of the main window, it seems like all UI elements stop responding.
Glad it fixed it for you.
But.... you have posted a "complete and verifiable example code" that used a different proc handler that called ImGui_ImplWin32_WndProcHandler()
. Your template has other contradictions too. I am tired of people making lazy/erroneous support request and stealing our time this way, it is not very respectful of our time.
by the way I replace the outside WndProc function in the initialize stage using this way
There is your problem. The function you replaced was the one that delegated messages to
ImGui_ImplWin32_WndProcHandler()
, which is required for working interactions. Your replacement doesn't do that, but it needs to.
yeah I discovered the problem almost immediately when I posted the reply
Glad it fixed it for you.
But.... you have posted a "complete and verifiable example code" that used a different proc handler that called
ImGui_ImplWin32_WndProcHandler()
. Your template has other contradictions too. I am tired of people making lazy/erroneous support request and stealing our time this way, it is not very respectful of our time.
So sorry, this is my bad
Version/Branch of Dear ImGui:
Version 1.79 (1.90.4-docking is the same)
Back-ends:
imgui_impl_win32.cpp + imgui_impl_vulkan.cpp
Compiler, OS:
Windows10 + MSVC 2022
Full config/build information:
The following info is from the example_win32_directx12
Details:
Hi all, The problem that all UI elements (including the main window) became uninteractive (like the drag drop operation, but the interactions within these UI are normal) occurred when I changed the platform binding of my engine from the GLFW to the Win32 (the GLFW version is all normal). I'll try to post all the relevant code (maybe I can provide source code if someone insterested).
Screenshots/Video:
Minimal, Complete and Verifiable Example code: