Вопрос

I have written an application that currently handles clicks from multiple mouse devices.

I used this project and modified to handle mouse clicks as apposed to keyboards.

This is working fine, however now I need to know if there is a way to suppress a click event if it has been handled by my app. The app is a quiz game so the idea is that the quiz master will have (and still be able to use) 1 mouse, and the other contestants will have their own mouse (as buzzers). So when they buzz in, I don't want the mouse click events to fire in the operating system (or at least this application).

The concept is the familiar override of void WndProc(ref Message message), and so I have tried not calling base.WndProc(ref Message) when I don't want the click events to fire, but this has not worked.

Can anybody point me in the right direction here?

Should I be going down the windows hook route? I have looked at this, but I can't seem to work out how I could hook to each mouse device individually.

Any help would be greatly appreciated.

Edit:

This is a Windows Form UI project, and not WPF. So the MultiPoint SDK from Microsoft won't work.

Это было полезно?

Решение

The solution to this lies within not WndProc, but PreFilterMessage(). By intercepting messages before they even reach the form, you can remove them from the message pump causing them to never reach the control that was clicked. This also works for child controls within the form.

I answered this and posted the full source in the following question:

C# Get Mouse handle (GetRawInputDeviceInfo)

Лицензировано под: CC-BY-SA с атрибуция
Не связан с StackOverflow
scroll top