views:

84

answers:

2

I am looking for a way to pass mouse events through a winform without using Form.TransparencyKey. If there is no simple way to do this, is there a way to send a mouse event to a given window handle using Win32 API?

Edit By pass through the winform I do not mean to a parent window, I mean to other applications that reside behind mine.

+2  A: 

This may sound overkill, as I saw SLaks's answer..

You would need

  1. The handle of the Window using Handle property
  2. Use pinvoke on the SendMessage Win32API
  3. One of the parameters to SendMessage is WM_LBUTTONDOWN

Here's a declaration for the SendMessage

[DllImport("user32")] static extern IntPtr SendMessage(IntPtr hWnd, UInt32 Msg, IntPtr wParam, IntPtr lParam);

Here's the constants used:

public const int WM_LBUTTONDOWN = 0x201;
public const int WM_LBUTTONUP = 0x202;

Typical Invocation:

SendMessage(someWindow.Handle, WM_LBUTTONDOWN, IntPtr.Zero, IntPtr.Zero);
SendMessage(someWindow.Handle, WM_LBUTTONUP, IntPtr.Zero, IntPtr.Zero);

The invocation is an example of how to send a mouse left-click to a specified window.

I used pinvoke.net to obtain the correct API.

Hope this helps, Best regards, Tom.

tommieb75
A: 

The answer is actually much easier than I thought it would be. This SO answer got me where I needed to be: http://stackoverflow.com/questions/318327/transparent-window-or-draw-to-screen-no-mouse-capture Also found what looks like a c++ implementation if you want some working code: http://stackoverflow.com/questions/318327/transparent-window-or-draw-to-screen-no-mouse-capture

Samuel