查看: 698  |  回复: 0
  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


您需要登录后才可以回帖 登录 | 立即注册
【本版规则】请勿发表违反国家法律的内容,否则会被冻结账号和删贴。
用户名: 立即注册
密码:
2020-2025 MaNongKu.com