Create a mouse-penetrating form

Source: Internet
Author: User

[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

 

 

 

 

 

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.