[Instance description]
To make the desktop more beautiful, you can add a glass-like effect on the desktop. You can use the mouse to operate the desktop through the glass.
This example uses the mouse to penetrate the form to implement the above functions.
[Key Technologies]
In this example, the API functions SetWindowLong and GetWindowLong are used. The following describes them in detail.
(1) SetWindowLong function: This function is mainly used to set information for the specified window in the window structure. The syntax format is as follows:
[DllImport(, EntryPoint = SetWindowLong(IntPtr hwnd, nIndex, dwNewLong);
(2) GetWindowLong function: This function obtains information from the structure of the specified window. The syntax format is as follows:
[DllImport(, EntryPoint = GetWindowLong(IntPtr hwnd, nIndex);
Design Process]
(1) Open Visual Studio, create a WinForm application, and name it MouseThroughForm.
(2) Change the Name attribute of the default form Form1 to Frm_Main, and set the FormBorderStyle attribute of the form to None.
(3) Add a policyicon control in the Frm_Main form and set the Icon attribute to the specified Icon to display the prompt information.
(4) Add a ContextMenuStrip control to serve as the shortcut menu of the program.
(5) In the Frm_Main form, the first method is the CanPenetrate, which is used to implement the mouse penetration through the API functions SetWindowLong and GetWindowLong.
The form implementation code is as follows:
WS_EX_LAYERED = WS_EX_TRANSPARENT = GWL_EXSTYLE = (-Var_genre =; set information for the specified window in the window structure [DllImport (, EntryPoint = SetWindowLong (IntPtr hwnd, nIndex, obtain information from the structure of the specified window [DllImport (, EntryPoint = GetWindowLong (IntPtr hwnd, so that the window has the mouse penetrating function intExTemp = GetWindowLong (oldGWLEx = SetWindowLong (. handle, GWL_EXSTYLE, WS_EX_TRANSPARENT | Frm_Main_Load (. showInTaskbar = ;. topMost =; SetEstate (Form Frm, Var_genre = Tem_Str = (TRIM ()> = Var_genre = Tem_Str.Substring (, Tem_Str.IndexOf (Color Tem_Color =: Tem_Color = Color. gainsboro;: Tem_Color = Color. darkOrchid;: Tem_Color = Color. royal blue;: Tem_Color = Color. gold;: Tem_Color = Color. lightGreen; Frm. backColor = Tem_Double =: Tem_Double =; frm. opacity = Frm. backColor = Frm. opacity = ToolColor_Glass_Click (SetEstate (}All form code