views:

397

answers:

1

Hi,

I am trying to create an application that makes a window (external to the app) transparent when it loses focus. Most of things (getting window id, seting transparent, etc.) would be easy, except one thing - how do I hook windows?

+1  A: 

You can use interop. Use SendMessage() function to send your window a custom message. The window can then call SetLayeredWindowAttributes() once your receive that message to change its transparency.

The other thing is you really should be able to make the window turn ITSELF transparent when it loses focus by listening for WM_KILLFOCUS

EDIT:

Latch onto the Deactivate and Activated events in C#.

    private void Form1_Deactivate( object sender, EventArgs e )
    {
      this.Opacity = 0.5 ;
    }

    private void Form1_Activated( object sender, EventArgs e )
    {
      this.Opacity = 1.0 ;
    }
bobobobo