添加一个标准模块,并加入以下代码:'调用一个API函数SetWindowPos可实现窗体显示在上面的功能。
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 Sub SetFormTopmost(theForm As Form)
'使窗体处于最上,需要用到SetWindowPos API函数
SetWindowPos theForm.hwnd, -1, 0, 0, 0, 0, 3
'SetWindowPos theForm.hwnd, HWND_TOPMOST, 0, 0, 0, 0, SWP_NOMOVE + SWP_NOSIZE + SWP_NOZORDER
End SubPublic Sub setFormTop(theForm As Form)
'使窗体恢复正常,需要用到SetWindowPos API函数,并与上面的SetFormTopmost配合使用
SetWindowPos theForm.hwnd, -2, 0, 0, 0, 0, 3
End Sub再在FORM_LOAD()中加入以下代码:
SetFormTopmost(form1)

解决方案 »

  1.   

    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
      

  2.   

    如果是在同一个程序中 zOrder 够了
    如果想让这个窗体在所有的程序的前面则必须要用楼上的方法。