locked
Mouse Hook and Transparent to Mouse. RRS feed

  • Question

  • Old time Win32 programmer here. I know how this would be done in a standard Windows app, but would like to know how it would be done in WPF. I suspect I'll have to handle windows messages, which will be a real pisser because I then have to declare the Windows API functions and constants and might as well just do all my stuff the old way.

    Here is what I want:

    A chromeless window which remains hidden until I move my mouse near the edge of the screen or some other special screen area (normally handled through a mouse hook).

    This window then has partially translucent areas which do not capture mouse clicks, but allow them to be passed to the window/application beneath my application (normally handled by WM_HITTEST and HTTRANSPARENT).

    Other areas of my window are fully opaque, and those areas do capture mouse events, but they do not cause the my app to steal the focus from any other app.

    So how do I do a mouse hook type thing in WPF, return transparent hit testing in areas which are not fully transparent, and allow mouse clicks and dragging my content but not change focus to my app ... in WPF?

    If I have to use the Windows API to do all of these tasks then I'll have a hard time justifying the use of WPF at all.
    Friday, October 16, 2009 1:38 AM

Answers

  • Hi Sysrpl,

    >This window then has partially translucent areas which do not capture mouse clicks, but allow them to be passed to the window/application beneath my application

    In WPF, we can set the IsHitTestVisible property to false on the partially translulcent areas so that the areas won't receive mouse input; instead, input will be delivered to whatever is under the element on the window. However, if you'd like the mouse input to be passed to another window or application beneath your application, setting the IsHitTestVisible property doesn't help.

    >Other areas of my window are fully opaque, and those areas do capture mouse events, but they do not cause the my app to steal the focus from any other app.

    You have to use Windows API to do this.

    Sincerely,
    Linda Liu
    Please remember to mark the replies as answers if they help and unmark them if they provide no help.
    Welcome to the All-In-One Code Framework! If you have any feedback, please tell us.
    • Marked as answer by Linda Liu Friday, October 23, 2009 3:33 AM
    Monday, October 19, 2009 7:47 AM

All replies

  • /bump anyone?
    Friday, October 16, 2009 12:13 PM
  • Hi Sysrpl,

    >This window then has partially translucent areas which do not capture mouse clicks, but allow them to be passed to the window/application beneath my application

    In WPF, we can set the IsHitTestVisible property to false on the partially translulcent areas so that the areas won't receive mouse input; instead, input will be delivered to whatever is under the element on the window. However, if you'd like the mouse input to be passed to another window or application beneath your application, setting the IsHitTestVisible property doesn't help.

    >Other areas of my window are fully opaque, and those areas do capture mouse events, but they do not cause the my app to steal the focus from any other app.

    You have to use Windows API to do this.

    Sincerely,
    Linda Liu
    Please remember to mark the replies as answers if they help and unmark them if they provide no help.
    Welcome to the All-In-One Code Framework! If you have any feedback, please tell us.
    • Marked as answer by Linda Liu Friday, October 23, 2009 3:33 AM
    Monday, October 19, 2009 7:47 AM