Which is how the program was top form to achieve too?

That does not allow window top button on my nails, such as micro-channel chat window in the top right corner of the other windows, confirmation, not an ordinary window above him, but not absolute, top window also has property can also be overwritten he, these are done by WindowsApi the SetWindowPos function.

SetWindowPos

Change the child windows, pop-up or top-level window size, position, and Z order. These windows are ordered according to the appearance on the screen. The most top of the window to get the highest rankings, and Z is the order of the first window.
Here Insert Picture Description
7 parameters, but to achieve functions top, only the hWnd (window handle to top), hWndInsertAfter (in the order identified in the z), the uFlags (window flag).

the following values can hWndInsertAfter:
1.HWND_BOTTOM: a value of 1, the sequence Z at the bottom of the window. If the hWnd parameter identifies a topmost window, the window loses top position, and the other is set at the bottom of the window.

2.HWND_NOTOPMOST: value is -2, the non-window above all top-level windows (i.e., after all top-level windows). If the window has a non-top-level window, the flag has no effect.

3.HWND_TOP: a value of 0, the window is placed on top of the Z order.

4.HWND_TOPMOST: -1, the window is placed on all non-top-level windows. Even if the window is not the active window will remain the top position

Obviously use to -1,

uFlags value very much, is not listed, but to take SWP_NOSIZE SWP_NOMOVE and to ignore the parameters x, y, cx, cy, i.e. ignore the window size and location, otherwise SetWindowPos redefine the position and size, or a combination of values connecting operation, SWP_NOSIZE value 1, SWP_NOMOVE value of 2, i.e., the last value 1 | 2 = 3.

Vb take to be an example, after running, the window is sticky, he can go to the top of the window above the other, also other set-top windows can be on top of him.

Private Declare Function SetWindowPos Lib "user32.dll" (ByVal hwnd As Long, ByVal hWndInsertAfter As Long, ByVal x As Long, ByVal y As Long, ByVal cx As Long, ByVal cy As Long, ByVal wFlags As Long) As Long
Private Const SWP_SHOWWINDOW As Long = &H40
Private Const SWP_NOSIZE As Long = &H1
Private Const SWP_NOMOVE As Long = &H2
Private Const HWND_TOPMOST As Long = -1

Private Sub Form_Load()
SetWindowPos Me.hwnd, HWND_TOPMOST, 0, 0, 0, 0, SWP_NOSIZE Or SWP_NOMOVE
End Sub

Here Insert Picture Description

Published 42 original articles · won praise 7 · views 7733

Guess you like

Origin blog.csdn.net/HouXinLin_CSDN/article/details/104423232