473,406 Members | 2,404 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,406 software developers and data experts.

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.  }
  9.  
  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;
  24.  
  25.           case WM_MOUSEMOVE:
  26.           {
  27.                if (TrackBallMessage == true)
  28.                {
  29.                     handled = true; //still does a mousemove :(
  30.                }
  31.           }
  32.           break;
  33.      }
  34.  
  35.      return IntPtr.Zero;
  36. }
  37.  
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 5799
Studlyami
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

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

Similar topics

3
by: David Sworder | last post by:
This message was already cross-posted to C# and ADO.NET, but I forgot to post to this "general" group... sorry about that. It just occured to me after my first post that the "general" group readers...
1
by: DraguVaso | last post by:
Hi, I need to know the Lenght of the Text in a DataGridTextBoxColumn when I move with the mouse over it, and show it in a ToolTip. I have something that works, but it works only when the...
3
by: Tim Mulholland | last post by:
i posted this a while ago and never got a response, but i'm still having problems, so i thought i'd see if anyone had any sudden realizations this time Thanks in advance! Tim I have...
3
by: Crucifix | last post by:
Hello, I'm writing a small C# app, and part of what I'm trying to do involves the dragging of PictureBox controls on a form. Unfortunately, MouseMove seems to be behaving very oddly, causing...
3
by: TyBreaker | last post by:
I'm writing a screen saver using Visual Studio 2005 (Basic) and I have a Form which contains a PictureBox. I have two events, Click and MouseMove that I'd like to cause the program to end (see...
0
missinglinq
by: missinglinq | last post by:
Having been asked, for the umpteenth time, how to use the MouseMove property to change the appearance of an object, I put together this short tutorial and sample database today. Perhaps it will be of...
4
by: info | last post by:
Hello everybody, I hope you can help me with my problem. I want to add the mousemove event to a class that doesn't have it (specifically it is the nationalinstruments.ui.xycursor from measurement...
1
by: scf1984 | last post by:
I am writing a drag-and-drop interface for a page that I built. In this page, I have an object containing a "div" as a temporary container for my items, between the "mousedown" and the "mouseup". ...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.