Yes, you could disable mouse events by installing low level mouse hook. Your LowLevelMouseProc
callback should return nonzero value if nCode
is greater or equal zero. Also you should block not only WM_RBUTTONDOWN
windows message, but WM_RBUTTONUP
as well, or target application may work incorrectly.
This code is pretty strange:
if (wParam == WM_RBUTTONDOWN) {
cout << "OOO";
if (WM_RBUTTONDOWN) {
return -1; // Make this click be ignored
}
Second if
clause will always be true. Perhaps you mean
if((WM_RBUTTONDOWN == wParam)||(WM_RBUTTONDOWN == wParam))
return(-1);
Also, callback is running in the context of your thread by processing a windows message, so your code must have a message queue, it could not be simple console application
This hook is called in the context of the thread that installed it.
The call is made by sending a message to the thread that installed the
hook. Therefore, the thread that installed the hook must have a
message loop.
However system wide hooks could be pretty dangerous. One small error could easily make entire system unstable. Install hook only for the target application by specifying its message thread id in the SetWindowsHookEx
call. Your other option would be subclassing target window by replacing its message processing routine and filtering mouse event messages.
solved Disabling the right-click button [C++]