怎么把一个窗体在任何时候都处于最前端?

解决方案 »

  1.   

    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 HWND_TOPMOST = -1
    Private Const HWND_NOTOPMOST = -2
    Private Const SWP_NOMOVE = &H2
    Private Const SWP_NOSIZE = &H1
    Private Const Flag = SWP_NOMOVE Or SWP_NOSIZE  '不移动和改变窗口大小'  使窗口位于最前
    Private Sub Command1_Click()
        SetWindowPos Demo_Frm.hwnd, HWND_NOTOPMOST, 0, 0, 0, 0, Flag
    End Sub
    '  使窗口不位于最前
    Private Sub command2_Click()
        SetWindowPos Demo_Frm.hwnd, HWND_TOPMOST, 0, 0, 0, 0, Flag
    End Sub