zomgistania

Main page | About | Articles | Previous Posts | Archives

Tuesday, June 27, 2006

C# snippets - create a "transparent" click-through window

I ran into this at the C# channel today.. One guy wanted to create a window, which would be on top of another app and if you clicked that window, the window would not get activated and the event would be sent to the app below it instead.

Here's the code you need to accomplish this:

These two WinAPI functions are required

[DllImport("user32.dll")]
static extern int SetWindowLong(IntPtr hWnd, int nIndex, int dwNewLong);

[DllImport("user32.dll")]
static extern long GetWindowLong(IntPtr hWnd, int nIndex);


Then the actual form/window is made "transparent" with this call (this.Handle being the forms' handle)

SetWindowLong(this.Handle,-20,GetWindowLong(this.Handle,-20) | 0x00000020)

The values (-20, -20 and 0x00000020) are respectively the following from winuser.h: GWL_EXSTYLE, WS_EXSTYLE and WS_EX_TRANSPARENT



And as a side note, I did end up installing SC4... and what have I been doing?... Well, playing it. Not coding like I should be! :]

Labels:

5 Comments:

Post a Comment

<< Home