On a CE device, when a touch screen is pressed, the running application will receive a mouse click message. This message then gets filtered down through the application and eventually arrives at where it is supposed to be in the application level, i.e. click on a button control.
So to completely disable the touch screen on a Windows CE device you can suppress any mouse button messages that get sent from the device thus preventing them from getting dispatched to you application.
To do this you can add a filter object (that implements IMessageFilter) to the application's message pump, check the message type, if the message is a mouse click message then cancel it.
Unfortunately message filtering with CF 2.0 is not supported out of the box however, luckily for us the clever chaps at OpenNETCF have provided us with the classes we need to complete the task with their excellent Smart Device Framework library.
On to some code...here is my DisableTouchScreenFilter class that implements the IMessageFilter:
public class DisableTouchScreenFilter : IMessageFilter
private const int WM_MBUTTONDBLCLK = 0x0203;
private const int WM_LBUTTONDOWN = 0x0201;
private const int WM_LBUTTONUP = 0x0202;
public bool PreFilterMessage(ref Message message)
bool result = false;
if (message.Msg == WM_LBUTTONUP ||
message.Msg == WM_MBUTTONDBLCLK ||
message.Msg == WM_LBUTTONDOWN)
result = true;
You can actually check any Windows message that arrives at the PreFilterMessage method, however I have only defined the message constants that are required for handling the mouse click message.
For a full list of what all the Windows message are you can check out Windows Message (Enums).
To plumb in the filter to the application message pump you need to call the static AddMessageFilter method on the Application2 object. To remove the filter call the RemoveMessageFilter method passing in the same filter object.
An example of adding the message filter to the Application message pump:
You need to run your application using the Application2 class from the Smart Device Framework library.
The mouse message gets completely cancelled before it gets to any forms or controls. This means that absolutely no mouse click events will fire at all.
There may be a slight performance hit with the application due to the message filter evaluating ever message that gets passed to the application.