Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Transparent window application to overlay in Windows

Tags:

c#

windows

wpf

I want to write an application to process certain user actions.

The application will be always transparent and should be click through. So, the window behind will be seen and as the transparent application is click through I should be able to click on the window behind. Only certain user actions(like double click) I want to handle in my transparent application.

Is it possible to achieve this? Any guidelines are appreciated.

like image 401
Jimmy Avatar asked Feb 29 '12 14:02

Jimmy


2 Answers

You can make fake window click from your app:

[DllImport("user32.dll",CharSet=CharSet.Auto, CallingConvention=CallingConvention.StdCall)]
   public static extern void mouse_event(uint dwFlags, uint dx, uint dy, uint cButtons, uint dwExtraInfo);

   private const int MOUSEEVENTF_LEFTDOWN = 0x02;
   private const int MOUSEEVENTF_LEFTUP = 0x04;
   private const int MOUSEEVENTF_RIGHTDOWN = 0x08;
   private const int MOUSEEVENTF_RIGHTUP = 0x10;

private void Form_MouseClick(object sender, MouseEventArgs e)
{
   this.Hide();
   Point p = this.PointToScreen(e.Location);
   mouse_event(MOUSEEVENTF_LEFTDOWN , p.X, p.Y, 0, 0);
   mouse_event(MOUSEEVENTF_LEFTUP, p.X, p.Y, 0, 0);
   this.Show();//since this.opacity = 0; form will never be really visible
}

Now on double click you can set what ever you want.

like image 91
Amen Ayach Avatar answered Oct 12 '22 23:10

Amen Ayach


You can make a window that is transparent and click through. However, it's all or nothing. You can't be click through apart from double clicks.

So, to do what you want I believe you will need to use a global mouse hook to handle the double clicks. But that's going to require native code.

In fact, come to think of it, why do you need the transparent click through window at all?

like image 29
David Heffernan Avatar answered Oct 12 '22 23:10

David Heffernan