http://www.csdn.net/expert/topic/499/499697.xml
主  题:  晶晶的第三篇口水话:"VB调用API函数使窗口保持在最上层 "....(API相关)

解决方案 »

  1.   

    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)Private Sub Form_Load()
        dim rtn
        rtn = SetWindowPos(OnTop.hwnd, -1, 0, 0, 0, 0, 3)
    End Sub
      

  2.   

    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 LongPrivate Const HWND_TOPMOST = -1
    Private Const SWP_NOMOVE = &H2
    Private Const SWP_NOSIZE = &H1Private Sub Form_Load()
    Dim retValue As Long
    retValue = SetWindowPos(Me.hwnd, HWND_TOPMOST,0,0,0,0, SWP_NOMOVE Or SWP_NOSIZE)
    End Sub
      

  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 Long这样在最前面:
    SetWindowPos Me.hwnd, -1, 0,0,0,0, 1 or 2
    这样取消在最前面:
    SetWindowPos Me.hwnd, -2, 0,0,0,0, 1 or 2
      

  4.   

    Const HWND_TOPMOST = -1
    Const HWND_NOTOPMOST = -2
    Const SWP_NOSIZE = &H1
    Const SWP_NOMOVE = &H2
    Const SWP_NOACTIVATE = &H10
    Const SWP_SHOWWINDOW = &H40
    Private Declare Sub 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)Private Sub Form_Activate()
        'KPD-Team 1998
        'URL: http://www.allapi.net/
        'E-Mail: [email protected]
        'Set the window position to topmost
        SetWindowPos Me.hWnd, HWND_TOPMOST, 0, 0, 0, 0, SWP_NOACTIVATE Or SWP_SHOWWINDOW Or SWP_NOMOVE Or SWP_NOSIZE
    End Sub