How to top any windows window

Source: Internet
Author: User

In the forum, someone asked how to top any windows window. Here, we can use the Windows API function setwindowspos. The following is the sample code:

The sample code demonstrates setting a newly opened Notepad program to the top

1 [dllimport ("user32.dll", setlasterror = true)]
2 public static extern intptr findwindow (string lpclassname, string lpwindowname );
3
4 [dllimport ("user32.dll")]
5 public static extern bool setwindowpos (intptr hwnd, intptr hwndinsertafter, int X, int y, int CX, int cy, uint uflags );
6
7 public static readonly intptr hwnd_topmost = new intptr (-1); // top the form
8 public static readonly intptr hwnd_notopmost = new intptr (-2); // unstick the form
9 Public const uint swp_nomove = 0x0002; // do not adjust the form position
10 public const uint swp_nosize = 0x0001; // do not adjust the form size
11
12 private void button#click (Object sender, eventargs E)
13 {
14 // find the default Notepad program
15 intptr notepadhandle = findwindow (null, "untitled-Notepad ");
16 if (notepadhandle = NULL | notepadhandle = intptr. Zero)
17 return;
18 setwindowpos (notepadhandle, hwnd_topmost, 1, 1, 1, 1, swp_nomove | swp_nosize );
19}
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.