C # Implementation of the mask layer on the desktop (mouse penetration) mainly through a few API functions to achieve: getwindowlong,setwindowlong,setlayeredwindowattributes. One of the Windows message Ws_ex_transparent is more important, which implements the mouse penetration function. Here's a look at the complete implementation code:
Using System;
Using System.Drawing;
Using System.Windows.Forms;
Using System.Runtime.InteropServices;
Namespace WindowsApplication40
{
Public Partia Lclass Form1:form
{
Public Form1 ()
{
InitializeComponent ();
}
[DllImport ("User32.dll", entrypoint= "GetWindowLong")]
public static extern long GetWindowLong (IntPtr hwnd,int nIndex);
[DllImport ("User32.dll", entrypoint= "SetWindowLong")]
public static extern long SetWindowLong (IntPtr hwnd,int nindex,long dwnewlong);
[DllImport ("user32", entrypoint= "SetLayeredWindowAttributes")]
public static extern int SetLayeredWindowAttributes (IntPtr handle,int crkey,byte balpha,int dwFlags);
const int gwl_exstyle=-20;
const int ws_ex_transparent=0x20;
const int ws_ex_layered=0x80000;
const int lwa_alpha=2;
private void Form1_Load (Objec Tsender,eventargs e)
{
This. Backcolor=color.silver;
This. Topmost=true;
This. Formborderstyle=formborderstyle.none;
This. windowstate=formwindowstate.maximized;
SetWindowLong (Handle,gwl_exstyle,getwindowlong (Handle,gwl_exstyle) | Ws_ex_transparent| ws_ex_layered);
SetLayeredWindowAttributes (Handle,0,128,lwa_alpha);
}
}
}
The above is the introduction of C # using the Windows API to implement the mask layer on the desktop (mouse penetration), I hope to help you.
C # uses the Windows API to implement a masking layer on the desktop (mouse penetration)