I have a winforms app that runs on a PC connected to an industrial machine. There are multiple computers connected trough a display channel switching device and a USB input switching device. This means that the computer starts without a screen or any input devices connected.
The problem we have is with a hosted WPF component. This component is initialised before a touch device is connected. After a touch device is connected everything can be controlled except the WPF component (it responds to a normal mouse).
As such the solution seems simple, reinitialize the WPF component after the touch device is connected. So we tried overriding the WndProc
method like below. Using the WindowsMessage
enum from pinvoke.net.
protected override void WndProc(ref Message m)
{
DateTime currentTime = DateTime.Now;
Console.WriteLine($"#{currentTime.Minute}:{currentTime.Second}.{currentTime.Millisecond} WndProc: {m.Msg} ==> {(WindowsMessage)m.Msg}");
Console.WriteLine($"#Number of touches: {GetSystemMetrics(SystemMetric.MAXIMUMTOUCHES)}.");
Console.WriteLine($"#TabletMode: {GetSystemMetrics(SystemMetric.TABLETPC)}.");
base.WndProc(ref m);
}
Connecting a touch device generates multiple (4-5) DEVICECHANGE
messages as well as mixed results for number of touches
ranging from all 0, all 1 or in the best case a mix with the last one a 10. Tabletmode
is either off or in the best case on. Often times before number of touches
is greater then 0. It just seems all semi random and unreliable.
Example output:
#36.810 WndProc: 537 ==> DEVICECHANGE
#Number of touches: 0.
#TabletMode: 0.
#36.827 WndProc: 537 ==> DEVICECHANGE
#Number of touches: 0.
#TabletMode: 0.
#36.866 WndProc: 537 ==> DEVICECHANGE
#Number of touches: 0.
#TabletMode: 0.
#36.876 WndProc: 537 ==> DEVICECHANGE
#Number of touches: 0.
#TabletMode: 0.
#36.976 WndProc: 712 ==> 712
#Number of touches: 0.
#TabletMode: 0.
Fortunatly, everytime I plug and unplug the touch device I also get message 0x02c8 (712)
and 0x02c9 (713)
. This feels like some kind of touch device connected
and touch device disconnected
messages, but the windows message
enum doesn't have these messages. Looking around, I can't actually find a windows message
list that has them. I even looked in my WinUser.h
files.
So per the title, does anyone know what these windows messages are?
My suspicion was correct, from tpcshrd.h:
#define WM_TABLET_DEFBASE 0x02C0
#define WM_TABLET_MAXOFFSET 0x20
#define WM_TABLET_ADDED (WM_TABLET_DEFBASE + 8)
#define WM_TABLET_DELETED (WM_TABLET_DEFBASE + 9)
#define WM_TABLET_FLICK (WM_TABLET_DEFBASE + 11)
#define WM_TABLET_QUERYSYSTEMGESTURESTATUS (WM_TABLET_DEFBASE + 12)