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 LongPublic Function TopMost(ByVal oForm As Form, Optional ByVal fTop As Boolean = True) As Boolean
    Dim lReturn As Long
    Dim lpx As Long
    Dim lPY As Long
    Dim lTop As Long
    Dim lLeft As Long
    Dim lWidth As Long
    Dim lHeight As Long
    Dim lShow As Long
    
    lShow = IIf(fTop = True, HWND_TOPMOST, HWND_NOTOPMOST)
    
    With Screen
        lpx = .TwipsPerPixelX
        lPY = .TwipsPerPixelY
    End With
    
    With oForm
        lLeft = .Left / lpx
        lTop = .Top / lPY
        lWidth = .Width / lpx
        lHeight = .Height / lPY
    End With
    
    lReturn = SetWindowPos(oForm.hWnd, lShow, lLeft, lTop, lWidth, lHeight, SWP_SHOWWINDOW)
    TopMost = (lReturn <> 0)
End Function

解决方案 »

  1.   

    nik_Amis(Azrael) 最好能给点说明,那就太好了
      

  2.   

    Private Const HWND_BOTTOM = 1
    Private Const HWND_DESKTOP = 0
    Private Const HWND_NOTOPMOST = -2
    Private Const HWND_TOP = 0
    Private Const HWND_TOPMOST = -1
    Private Const SWP_HIDEWINDOW = &H80
    Private Const SWP_SHOWWINDOW = &H40
    常量忘了写了这个函数封装的很简单了
    还要怎样说明?你就 TopMost frmname ,True/False 就可以了
      

  3.   

    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 LongPrivate Const HWND_TOPMOST& = -1
    ' 将窗口置于列表顶部,并位于任何最顶部窗口的前面
    Private Const SWP_NOSIZE& = &H1
    ' 保持窗口大小
    Private Const SWP_NOMOVE& = &H2
    ' 保持窗口位置
    Private Sub Form_Load()SetWindowPos Me.hwnd, HWND_TOPMOST, 0, 0, 0, 0, SWP_NOMOVE Or SWP_NOSIZE
    ' 将窗口设为总在最前End Sub