首页 /编程语言和算法/VB6/VBA/ASP
 VB6 让你窗体永远在最上方 API SetWindowPos,窗体置顶
2023年5月4日 16:06

新建From1(窗体),新建Command1(按钮CommandButton),Command2(按钮CommandButton),代码:

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 SWP_NOMOVE = &H2
Private Const SWP_NOSIZE = &H1
Private Const HWND_TOPMOST = -1
Private Const HWND_NOTOPMOST = -2
Private Const FLAGS = SWP_NOMOVE Or SWP_NOSIZE

Private Sub Command1_Click()
    '窗口就出现在桌面的最上方
    Dim lngRet&
    lngRet = SetWindowPos(Me.hwnd, HWND_TOPMOST, 0, 0, 0, 0, FLAGS)
End Sub

Private Sub Command2_Click()
    '窗口恢复成原来的普通状态
    Dim lngRet&
    lngRet = SetWindowPos(Me.hwnd, HWND_NOTOPMOST, 0, 0, 0, 0, FLAGS)
End Sub


 
全部回复(0)
首页 | 电脑版 |