# Re: 使用 SetWindowPos API

Posted by 陈凯程 on March 15, 1998 at 23:50:35:

In Reply to: How to make posted by Rpg之鬼 on March 14, 1998 at 01:51:40:

Option Explicit

Private Declare Function SetWindowPos _
Lib "user32" ( _
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 HWND_TOPMOST = -1
Private Const HWND_NOTOPMOST = -2
Private Const SWP_NOSIZE = &H1
Private Const SWP_NOMOVE = &H2

Public Sub SetOnTop(frm As Form, Topmost As Boolean)
If Topmost Then
SetWindowPos frm.hwnd, HWND_TOPMOST, 0, 0, 0, _
0, SWP_NOSIZE Or SWP_NOMOVE
Else
SetWindowPos frm.hwnd, HWND_NOTOPMOST, 0, 0, 0, _
0, SWP_NOSIZE Or SWP_NOMOVE
End If
End Sub

将以上的程式码放在一个 Module 中，在 Form_Load 中输入：

SetOnTop Me, True

这样便可以将 Form "Always On Top" 了！

Follow Ups: