2024年3月24日发(作者:)

Private Declare Function SetWindowPos Lib "" (ByVal hWnd As Long, ByVal

hWndInsertAfter As Long, ByVal x As Integer, ByVal y As Integer, ByVal cx As Integer,

ByVal cy As Integer, ByVal uFlags As Long) As Boolean

Const SWP_NOMOVE = &H2 '不更动目前视窗位置

Const SWP_NOSIZE = &H1 '不更动目前视窗大小

Const HWND_TOPMOST = -1 '设定为最上层

Const HWND_NOTOPMOST = -2 '取消最上层设定

Const FLAGS = SWP_NOMOVE Or SWP_NOSIZE

Dim bTopMost As Boolean

Private Sub Command1_Click()

If bTopMost = False Then

SetWindowPos , HWND_TOPMOST, , , , , FLAGS

bTopMost = True

n = "取消窗口置顶"

Else

SetWindowPos , HWND_NOTOPMOST, , , , , FLAGS

bTopMost = False

n = "窗口置顶"

End If

End Sub

Private Sub Form_Load()

bTopMost = False

End Sub

‘一直置顶:

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 SWP_NOSIZE& = &H1

Private Const SWP_NOMOVE& = &H2

Private Sub Form_Load()

SetWindowPos , HWND_TOPMOST, 0, 0, 0, 0, SWP_NOMOVE Or SWP_NOSIZE

End Sub

‘本文出自/?id=44,作者为本文上传者。