Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

io.WantCaptureMouse is not working. So im using an alternative bool. But i still want to understand what im doing wrong. #4593

Closed
whiskasdietgirl opened this issue Sep 28, 2021 · 1 comment

Comments

@whiskasdietgirl
Copy link

whiskasdietgirl commented Sep 28, 2021

I have been beating my head against a wall with the io.WantMouseCapture.
There must be something simple im doing wrong.
Im working with version v1.76, its a old project.
I read the faq about io.WantCaptureMouse and tried it in multiple ways.
But im a beginner so maybe there is something wrong im doing.
This is my imgui code:


 ImGui::SetNextWindowPos(ImVec2(x(200), y(260)));
		ImGui::SetNextWindowBgAlpha(0.50F);
		ImGui::Begin("test", 0, ImGuiWindowFlags_NoCollapse | ImGuiWindowFlags_NoScrollbar );
		ImGui::SetWindowSize(ImVec2(x(250), y(350)));
		if (ImGui::IsItemHovered() || ImGui::IsWindowHovered()) {
	ImGuiIO& io = ImGui::GetIO();
	io.WantCaptureMouse = true;    }
		ImGui::End();

This is my hookedproc:

LRESULT __stdcall HookedWndProc(const HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam) {
    if (true && ImGui_ImplWin32_WndProcHandler(hWnd, uMsg, wParam, lParam))
        return true;
	ImGuiIO& io = ImGui::GetIO();
	if (io.WantCaptureMouse)
	return 0;
    return CallWindowProc(g_DrawingApp.WndProc, hWnd, uMsg, wParam, lParam);
} 

This doesnt work. Although it does block the clicks, when its hovering on my test window, and it works when clicking on the menu of the application, it ALSO blocks clicks on all other windows that i created (so those other windows dont work now).

If i remove this code and instead use this then it works:
Make a global bool g_eatMouse :).


`		ImGui::SetNextWindowPos(ImVec2(x(200), y(260)));
		ImGui::SetNextWindowBgAlpha(0.50F);
		ImGui::Begin("test", 0, ImGuiWindowFlags_NoCollapse | ImGuiWindowFlags_NoScrollbar );
		ImGui::SetWindowSize(ImVec2(x(250), y(350)));
	g_eatMouse = false;
		if (ImGui::IsItemHovered() || ImGui::IsWindowHovered())
	g_eatMouse = true;
	ImGui::End();`

LRESULT __stdcall HookedWndProc(const HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam) {

    if (true && ImGui_ImplWin32_WndProcHandler(hWnd, uMsg, wParam, lParam))
        return true;

if(g_eatMouse) 
return 0;

    return CallWindowProc(g_DrawingApp.WndProc, hWnd, uMsg, wParam, lParam);
}
`

This works perfectly. All windows work, and the clicks are blocked to the application when clicking on a window.
However i know this is not the offical way to do things. So i would prefer to do it like you do officially.
But it does seem more simple to me, because its using only 1 bool :).
Help please

@ocornut
Copy link
Owner

ocornut commented Sep 29, 2021

This is my imgui code:

	ImGuiIO& io = ImGui::GetIO();
	io.WantCaptureMouse = true;    }

You should never write to this value yourself.

if (io.WantCaptureMouse)
	return 0;
return CallWindowProc(g_DrawingApp.WndProc, hWnd, uMsg, wParam, lParam);

This will prevent CallWindowProc() from being called at all. Since this is a low-level function used by many things you should probably always forward all events.

You should read io.WantCaptureMouse at the location where mouse inputs are forwarded or handled by the underlying application and not forward or not handle them when the value is true. We are lacking enough context.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants