470,593 Members | 2,374 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 470,593 developers. It's quick & easy.

Blocking the MouseMove message WPF/C#

464 Expert 256MB
I have an application which has two mice devices. One is a trackball and the other is your standard computer mouse. I am using raw input (WM_INPUT) and I am able to identify both computer mice, distinguish between them and know which one sent the mouse message. Now, what I want to do is if i detect (preferably within WM_INPUT) that the trackball moved (MouseMove) I want to prevent the mouse from moving and do something else; currently the trackball does both (my function plus move the mouse cursor). Any ideas on how i can do this?

I have tried in both the WndProc under WM_MOUSEMOVE and WM_INPUT to set the handled flag to true. I have also within the window itself handled the previewmousemove event and set the handled to true but it still the cursor moves when I move the trackball (see code below).

Expand|Select|Wrap|Line Numbers
  1. private void OnMouseMove(object sender, MouseEventArgs e)
  2. {
  3.      if (TrackBallMessage == true) //set by the WM_INPUT in WndProc
  4.      {
  5.           e.Handled = true; //still moves the mouse :(
  6.           TrackBallMessage = false; //reset our flag.
  7.      }
  8.  }
  10. IntPtr WndProc(IntPtr hwnd, int msg, IntPtr wParam, IntPtr lParam, ref bool handled)
  11. {
  12.      switch (msg)
  13.      {
  14.           case WM_INPUT:
  15.           {
  16.                if (<message came from trackball>)
  17.                {
  18.                     handled = true; //this doesn't prevent the mouse move :(
  19.                     TrackBallMessage = true; //tried to signal to mouse move not to do anything, but it still does (global var)
  20.                     <do my function>
  21.                }
  22.           }
  23.           break;
  25.           case WM_MOUSEMOVE:
  26.           {
  27.                if (TrackBallMessage == true)
  28.                {
  29.                     handled = true; //still does a mousemove :(
  30.                }
  31.           }
  32.           break;
  33.      }
  35.      return IntPtr.Zero;
  36. }
Is there some way to block this message from moving pass the WM_INPUT stage? or a way to push it out of the message queue so windows thinks that the message has resolved?
Nov 5 '09 #1
1 5404
464 Expert 256MB
*UPDATE* Well, after some searching and trial and error I still have been unable to do what I want to do, but I did provide an acceptable work around (at least as far as the company is concerned). I am posting my workaround for others to see and I am still open for suggestions, but I'll only be able to test them when I have free time. In WM_INPUT if I detect the trackball moved I saved the mouse cursor position, hide the mouse cursor and then perform the desired action from the trackball (scrolling around on a map). After the track ball has stopped moving I restore the mouse cursor position and then show the mouse cursor. This works and gets the job done, but it isn't the most ideal situation. I'll post again in the future if I figure anything else out.

For the record I tried various types of hooks to try and block the messages from being passed, but with no success. Also from most of the hooks I wasn't able to detect which device sent the message (mouse or trackball) so even if I could block the message I wouldn't know which ones to block.
Nov 13 '09 #2

Post your reply

Sign in to post your reply or Sign up for a free account.

Similar topics

3 posts views Thread by Tim Mulholland | last post: by
3 posts views Thread by Crucifix | last post: by
3 posts views Thread by TyBreaker | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.