For those who often bubble the network, load Dongdong, and write programs, they usually need to open more than N windows, sometimes it is inconvenient to switch back and forth between two windows to compare the two windows and observe the results, especially when the screen is small! The program below is specifically used to set any form to the top. By dragging the cross cursor to the desired window, you can get the handle of the window and automatically set it to the top layer, you can also right-click to delete a window that is not needed:
The following code is analyzed:
To set the position of the window on the Windows Z axis, call winapi: setwindowpos:
In VB6.0
Dword_prt setwindowpos (hwnd, hwnd hinsertafter, int X, int y, int CX, int cy, uint nflag)
In C #:
[Dllimport ("user32.dll", entrypoint = "setwindowpos", charset = charset. Auto)]
Public static extern long setwindowpos (intptr hwnd, int hinsertafter, int X, int y, int CX, int cy, int nflag );
[Dllimport ("user32.dll", entrypoint = "setwindowpos", charset = charset. Auto)]
Public static extern long setwindowpos (intptr hwnd, intptr hinsertafter, int X, int y, int CX, int cy, int nflag );
The following table describes the parameters:
Parameters |
Description |
In VB6.0 |
In C # |
|
Hwnd Hwnd |
Intptr Hwnd |
Handle of the window to be moved |
Hwnd Hinsertafter |
Hwnd_bottom (1) |
Intptr Hwnd Int |
Put the window at the end of the Z axis, that is, behind all windows |
Hwnd_top (0) |
Intptr Hwnd Int |
Place the window at the top of the Z axis, that is, the front of all windows. |
Hwnd_topmost (-1) |
Intptr Hwnd Int |
Make the window a "topmost" type window. This type of window is always in front of other windows until it is closed. |
Hwnd_notopmost (-2) |
Intptr Hwnd Int |
Place the window in all "topmost" types Behind a window and before a window of other types |
Int X |
Int X |
Specify the left boundary of the new window position with the client coordinates |
Int Y |
Int Y |
Specify the top boundary of the new window position with the client coordinates |
Int CX |
Int CX |
Specify the new window width in pixels |
Int Cy |
Int Cy |
Specify the new height of the window in pixels |
Uint Nflag |
Swp_asncwindowpos |
Int |
If the calling process does not have a window, the system sends a request to the thread that owns the window. This prevents the call thread from deadlocks when other threads process their needs. |
Swp_defererase |
Int |
Prevent wm_syncpaint messages |
... |
|
A lot of things. If you are interested, you can check "Windows API Daquan" Or: msdn |
You can use the windowfrompoint (point) method to obtain the first parameter (the intptr type in C #). The method is defined in C # as follows:
[Dllimport ("user32.dll")]
Public static extern intptr windowfrompoint (point );
Here is a point struct parameter used to pass the mouse coordinates:
[Structlayout (layoutkind. Sequential)]
Public struct point
{
Public int X;
Public int y;
Public point (int x, int y)
{
This. x = X;
This. Y = y;
}
Public Static Implicit operator system. Drawing. Point (point P)
{
Return new system. Drawing. Point (P. X, p. y );
}
Public Static Implicit operator point (system. Drawing. point P)
{
Return new point (P. X, p. y );
}
In this way, we can obtain any coordinate and any object handle. With this handle, we can check the windows API to see which tasks can be completed using this handle.
Recently, I was wondering if there was such a program that could selectively Save the status of some applications before you shut down, and then restore these programs to the last state at the next boot, like the tag saving function in Firefox. Use Windows
The API can also complete these tasks. If you have time, you can find them again.
Finally, link the compressed package. Do not forget my PS if you have any opinions on this program ~~