I would like help to create a Windows service that can listen for Multi-touch event occurances, intercept them and then just do something with them (not important). I also need to know how to send Windows Messages to this service and the code to be able to receive those messages from within the service开发者_JAVA技巧.
Anyone have any idea's at all please?
I've been cutting code for 15 years but have never written a Windows Service before and use a little help to get on my way :(
By definition, Windows Services are not supposed to be user-interactive, therefore, if you want to get the multi-touch data, you will have to hook directly into the operating system input messages using a WM_TOUCH windows hook and interpreting that data yourself.
For those interested, I decided to go down the route of a normal Windows Form application, and when the time comes to put it live the for will be invisible so will run in the 'background' when the other application I need it to communicate with starts.
I managed to get WndProc(ref Message m) working and messages are being received by my app and its doing what it needs to do according to the instructions it's sent.
For example, the visible App has a GUI Slider for volume control. When the slider is moved the value of that slider is sent to my 'background' app via a Windows Message, and the 'background' App does the necessaries to change the Volume level of the device/PC, and when the volume level is requested, a Postback Message is sent to the requesting App to tell it what the Volume level is currently set at.
Some sample code below:-
public const int UI_VOLUME_SET = 1101;
public const int UI_VOLUME_GET = 1100;
public const int UI_VOLUME_SET_MUTE_STATUS = 1102;
public const int UI_BRIGHT_GET = 1201;
public const int UI_BRIGHT_SET = 1202;
public const int UI_TERMINATE = 9999;
[System.Security.Permissions.PermissionSet(System.Security.Permissions.SecurityAction.Demand, Name = "FullTrust")]Protected override void WndProc(ref Message m)
{
int _exoUI = MessageHelper.FindWindow(null, "MY UI");
EXOxtenderLibrary.VolumeControl _vol;
switch (m.Msg)
{
case UI_TERMINATE:
this.Close();
break;
case UI_BRIGHT_GET:
//ADD CODE HERE
break;
//case UI_BRIGHT_SET:
// //ADD CODE HERE
// break;
case UI_VOLUME_GET:
_vol = new EXOxtenderLibrary.VolumeControl();
MessageHelper.PostMessage(_exoUI, 32773, _vol.GetVolume(), _vol.isMute);
_vol = null;
break;
case UI_VOLUME_SET:
_vol = new EXOxtenderLibrary.VolumeControl();
_vol.SetVolume(m.WParam.ToInt32());
MessageHelper.PostMessage(_exoUI, 32773, _vol.GetVolume(), _vol.isMute);
_vol = null;
break;
case UI_VOLUME_SET_MUTE_STATUS:
_vol = new EXOxtenderLibrary.VolumeControl();
if (m.WParam == new IntPtr(1))
{ _vol.Mute = true; }
else
{ _vol.Mute = false; }
MessageHelper.PostMessage(_exoUI, 32773, _vol.GetVolume(), _vol.isMute);
_vol = null;
break;
}
base.WndProc(ref m);
}
精彩评论