diff --git a/examples/directx10_example/imgui_impl_dx10.cpp b/examples/directx10_example/imgui_impl_dx10.cpp index 816e56211..06171250b 100644 --- a/examples/directx10_example/imgui_impl_dx10.cpp +++ b/examples/directx10_example/imgui_impl_dx10.cpp @@ -234,35 +234,38 @@ static bool IsAnyMouseButtonDown() return false; } +// We use the Win32 capture API (GetCapture/SetCapture/ReleaseCapture) to be able to read mouse coordinations when dragging mouse outside of our window bounds. IMGUI_API LRESULT ImGui_ImplWin32_WndProcHandler(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam) { ImGuiIO& io = ImGui::GetIO(); switch (msg) { case WM_LBUTTONDOWN: - if (!IsAnyMouseButtonDown()) ::SetCapture(hwnd); - io.MouseDown[0] = true; - return 0; case WM_RBUTTONDOWN: - if (!IsAnyMouseButtonDown()) ::SetCapture(hwnd); - io.MouseDown[1] = true; - return 0; case WM_MBUTTONDOWN: - if (!IsAnyMouseButtonDown()) ::SetCapture(hwnd); - io.MouseDown[2] = true; + { + int button = 0; + if (msg == WM_LBUTTONDOWN) button = 0; + if (msg == WM_RBUTTONDOWN) button = 1; + if (msg == WM_MBUTTONDOWN) button = 2; + if (!IsAnyMouseButtonDown() && GetCapture() == NULL) + SetCapture(hwnd); + io.MouseDown[button] = true; return 0; + } case WM_LBUTTONUP: - io.MouseDown[0] = false; - if (!IsAnyMouseButtonDown()) ::ReleaseCapture(); - return 0; case WM_RBUTTONUP: - io.MouseDown[1] = false; - if (!IsAnyMouseButtonDown()) ::ReleaseCapture(); - return 0; case WM_MBUTTONUP: - io.MouseDown[2] = false; - if (!IsAnyMouseButtonDown()) ::ReleaseCapture(); + { + int button = 0; + if (msg == WM_LBUTTONUP) button = 0; + if (msg == WM_RBUTTONUP) button = 1; + if (msg == WM_MBUTTONUP) button = 2; + io.MouseDown[button] = false; + if (!IsAnyMouseButtonDown() && GetCapture() == hwnd) + ReleaseCapture(); return 0; + } case WM_MOUSEWHEEL: io.MouseWheel += GET_WHEEL_DELTA_WPARAM(wParam) > 0 ? +1.0f : -1.0f; return 0; diff --git a/examples/directx11_example/imgui_impl_dx11.cpp b/examples/directx11_example/imgui_impl_dx11.cpp index 7b3a3ba83..1f69bd727 100644 --- a/examples/directx11_example/imgui_impl_dx11.cpp +++ b/examples/directx11_example/imgui_impl_dx11.cpp @@ -241,35 +241,38 @@ static bool IsAnyMouseButtonDown() return false; } +// We use the Win32 capture API (GetCapture/SetCapture/ReleaseCapture) to be able to read mouse coordinations when dragging mouse outside of our window bounds. IMGUI_API LRESULT ImGui_ImplWin32_WndProcHandler(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam) { ImGuiIO& io = ImGui::GetIO(); switch (msg) { case WM_LBUTTONDOWN: - if (!IsAnyMouseButtonDown()) ::SetCapture(hwnd); - io.MouseDown[0] = true; - return 0; case WM_RBUTTONDOWN: - if (!IsAnyMouseButtonDown()) ::SetCapture(hwnd); - io.MouseDown[1] = true; - return 0; case WM_MBUTTONDOWN: - if (!IsAnyMouseButtonDown()) ::SetCapture(hwnd); - io.MouseDown[2] = true; + { + int button = 0; + if (msg == WM_LBUTTONDOWN) button = 0; + if (msg == WM_RBUTTONDOWN) button = 1; + if (msg == WM_MBUTTONDOWN) button = 2; + if (!IsAnyMouseButtonDown() && GetCapture() == NULL) + SetCapture(hwnd); + io.MouseDown[button] = true; return 0; + } case WM_LBUTTONUP: - io.MouseDown[0] = false; - if (!IsAnyMouseButtonDown()) ::ReleaseCapture(); - return 0; case WM_RBUTTONUP: - io.MouseDown[1] = false; - if (!IsAnyMouseButtonDown()) ::ReleaseCapture(); - return 0; case WM_MBUTTONUP: - io.MouseDown[2] = false; - if (!IsAnyMouseButtonDown()) ::ReleaseCapture(); + { + int button = 0; + if (msg == WM_LBUTTONUP) button = 0; + if (msg == WM_RBUTTONUP) button = 1; + if (msg == WM_MBUTTONUP) button = 2; + io.MouseDown[button] = false; + if (!IsAnyMouseButtonDown() && GetCapture() == hwnd) + ReleaseCapture(); return 0; + } case WM_MOUSEWHEEL: io.MouseWheel += GET_WHEEL_DELTA_WPARAM(wParam) > 0 ? +1.0f : -1.0f; return 0; diff --git a/examples/directx9_example/imgui_impl_dx9.cpp b/examples/directx9_example/imgui_impl_dx9.cpp index fc05c9ce5..02d2fd593 100644 --- a/examples/directx9_example/imgui_impl_dx9.cpp +++ b/examples/directx9_example/imgui_impl_dx9.cpp @@ -180,36 +180,38 @@ static bool IsAnyMouseButtonDown() return false; } -// We use Win32 SetCapture/ReleaseCapture() API to enable reading the mouse outside our Windows bounds. +// We use the Win32 capture API (GetCapture/SetCapture/ReleaseCapture) to be able to read mouse coordinations when dragging mouse outside of our window bounds. IMGUI_API LRESULT ImGui_ImplWin32_WndProcHandler(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam) { ImGuiIO& io = ImGui::GetIO(); switch (msg) { case WM_LBUTTONDOWN: - if (!IsAnyMouseButtonDown()) ::SetCapture(hwnd); - io.MouseDown[0] = true; - return 0; case WM_RBUTTONDOWN: - if (!IsAnyMouseButtonDown()) ::SetCapture(hwnd); - io.MouseDown[1] = true; - return 0; case WM_MBUTTONDOWN: - if (!IsAnyMouseButtonDown()) ::SetCapture(hwnd); - io.MouseDown[2] = true; + { + int button = 0; + if (msg == WM_LBUTTONDOWN) button = 0; + if (msg == WM_RBUTTONDOWN) button = 1; + if (msg == WM_MBUTTONDOWN) button = 2; + if (!IsAnyMouseButtonDown() && GetCapture() == NULL) + SetCapture(hwnd); + io.MouseDown[button] = true; return 0; + } case WM_LBUTTONUP: - io.MouseDown[0] = false; - if (!IsAnyMouseButtonDown()) ::ReleaseCapture(); - return 0; case WM_RBUTTONUP: - io.MouseDown[1] = false; - if (!IsAnyMouseButtonDown()) ::ReleaseCapture(); - return 0; case WM_MBUTTONUP: - io.MouseDown[2] = false; - if (!IsAnyMouseButtonDown()) ::ReleaseCapture(); + { + int button = 0; + if (msg == WM_LBUTTONUP) button = 0; + if (msg == WM_RBUTTONUP) button = 1; + if (msg == WM_MBUTTONUP) button = 2; + io.MouseDown[button] = false; + if (!IsAnyMouseButtonDown() && GetCapture() == hwnd) + ReleaseCapture(); return 0; + } case WM_MOUSEWHEEL: io.MouseWheel += GET_WHEEL_DELTA_WPARAM(wParam) > 0 ? +1.0f : -1.0f; return 0;