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}