Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C#
  4. MouseWheel events without focus

MouseWheel events without focus

Scheduled Pinned Locked Moved C#
question
5 Posts 3 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • C Offline
    C Offline
    cnurse
    wrote on last edited by
    #1

    Has anybody found a way to implement a global message trap, so that no matte what window/control has focus, and no matte where the mouse is pointing, you can listen to the mouse wheel roll messages? I have seen mouse driver settings that say send messsages to the window being pointed at, rather than the window with focus. I want to develop several controls that respond to mouse wheel events without having focus, and I dont want to set focus to them just so that I can "hear" the mouse wheel messages either. Any input, pardon the pun, would be great. Nursey

    D H 2 Replies Last reply
    0
    • C cnurse

      Has anybody found a way to implement a global message trap, so that no matte what window/control has focus, and no matte where the mouse is pointing, you can listen to the mouse wheel roll messages? I have seen mouse driver settings that say send messsages to the window being pointed at, rather than the window with focus. I want to develop several controls that respond to mouse wheel events without having focus, and I dont want to set focus to them just so that I can "hear" the mouse wheel messages either. Any input, pardon the pun, would be great. Nursey

      D Offline
      D Offline
      Dave Kreskowiak
      wrote on last edited by
      #2

      It's exactly the same as a keyboard hook, except it looks at mouse messages. Create an implementation of IMessageFilter and call Application.AddMessageFilter[^] to start it. All you have to do is add the code to watch for the mouse wheel message, documented here[^]. Look through the Windows C++ header files (*.h) for MW_MOUSEWHEEL to find what the constant value is for the message. RageInTheMachine9532 "...a pungent, ghastly, stinky piece of cheese!" -- The Roaming Gnome

      1 Reply Last reply
      0
      • C cnurse

        Has anybody found a way to implement a global message trap, so that no matte what window/control has focus, and no matte where the mouse is pointing, you can listen to the mouse wheel roll messages? I have seen mouse driver settings that say send messsages to the window being pointed at, rather than the window with focus. I want to develop several controls that respond to mouse wheel events without having focus, and I dont want to set focus to them just so that I can "hear" the mouse wheel messages either. Any input, pardon the pun, would be great. Nursey

        H Offline
        H Offline
        Heath Stewart
        wrote on last edited by
        #3

        Please note that what Dave said is only for the message pump for your application. You could also set Control.Capture to true to capture mouse events that you could handle either in WndProc or even the events that are exposed on the Control on which you set its Capture property to true. You could also implement a system hook, but this is very dangerous and not something to be taken lightly - you're hooking every group of messages for the entire platform and your code has to be clean, efficient, and must be unloaded and gracefully fail should any problems occur. There are several articles here on CodeProject about that. Search for SetWindowsHook to find articles on this site.

        Software Design Engineer Developer Division Sustained Engineering, Microsoft My Articles

        C 1 Reply Last reply
        0
        • H Heath Stewart

          Please note that what Dave said is only for the message pump for your application. You could also set Control.Capture to true to capture mouse events that you could handle either in WndProc or even the events that are exposed on the Control on which you set its Capture property to true. You could also implement a system hook, but this is very dangerous and not something to be taken lightly - you're hooking every group of messages for the entire platform and your code has to be clean, efficient, and must be unloaded and gracefully fail should any problems occur. There are several articles here on CodeProject about that. Search for SetWindowsHook to find articles on this site.

          Software Design Engineer Developer Division Sustained Engineering, Microsoft My Articles

          C Offline
          C Offline
          cnurse
          wrote on last edited by
          #4

          Thank you both for your advice, that was just what I needed to hear. I've done quite a bit with subclassing in the past, but as its been a while, and as I would like to know if there is a more ".NET" like way in which this should be done, then it was well worth asking. If I hook into the application message pump, then presumably, as controls run "in process" I will be able to hook into every Windows Forms App that utilises my controls? Many thanks once again. Nursey

          H 1 Reply Last reply
          0
          • C cnurse

            Thank you both for your advice, that was just what I needed to hear. I've done quite a bit with subclassing in the past, but as its been a while, and as I would like to know if there is a more ".NET" like way in which this should be done, then it was well worth asking. If I hook into the application message pump, then presumably, as controls run "in process" I will be able to hook into every Windows Forms App that utilises my controls? Many thanks once again. Nursey

            H Offline
            H Offline
            Heath Stewart
            wrote on last edited by
            #5

            cnurse wrote: If I hook into the application message pump, then presumably, as controls run "in process" I will be able to hook into every Windows Forms App that utilises my controls? Most likely, yes. It greatly depends on the container application, though. I don't forsee you having any The ".NET" way of things has nothing to do with Windows Forms or anything else, actually. .NET is Microsoft's brand of the CLI, or Common Language Infrastructure. Windows Forms is part of the BCL and actually encapsulates the Common Controls (like Edit, Rich Edit, Static, etc.) and many, many other Windows APIs and other Win32 APIs. Handling messages in this way is nothing different from what Microsoft is doing. That's why the Control class defines the WndProc method (among other Windows Platform-related members) - not just so you can use it but so that they can use it to encapsulates the Common Controls.

            Software Design Engineer Developer Division Sustained Engineering, Microsoft My Articles

            1 Reply Last reply
            0
            Reply
            • Reply as topic
            Log in to reply
            • Oldest to Newest
            • Newest to Oldest
            • Most Votes


            • Login

            • Don't have an account? Register

            • Login or register to search.
            • First post
              Last post
            0
            • Categories
            • Recent
            • Tags
            • Popular
            • World
            • Users
            • Groups