只在本应用程序中,
怎么样能使一个窗体一直存在于最顶层。

解决方案 »

  1.   

    在每次窗口失去焦点时调用以下APISetFocus Function--------------------------------------------------------------------------------The SetFocus function sets the keyboard focus to the specified window. The window must be attached to the calling thread's message queue. SyntaxHWND SetFocus(          HWND hWnd
    );
    ParametershWnd
    [in] Handle to the window that will receive the keyboard input. If this parameter is NULL, keystrokes are ignored. 
    Return ValueIf the function succeeds, the return value is the handle to the window that previously had the keyboard focus. If the hWnd parameter is invalid or the window is not attached to the calling thread's message queue, the return value is NULL. To get extended error information, call GetLastError.
      

  2.   

    应该是这个BringWindowToTop Function--------------------------------------------------------------------------------The BringWindowToTop function brings the specified window to the top of the Z order. If the window is a top-level window, it is activated. If the window is a child window, the top-level parent window associated with the child window is activated. SyntaxBOOL BringWindowToTop(          HWND hWnd
    );
    ParametershWnd
    [in] Handle to the window to bring to the top of the Z order. 
    Return ValueIf the function succeeds, the return value is nonzero.If the function fails, the return value is zero. To get extended error information, call GetLastError. 
      

  3.   

    模块部分:
    Declare Function SetWindowPos Lib "user32" Alias "SetWindowPos" (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 LongGlobal Const SWP_HIDEWINDOW = &H80
    Global Const SWP_NOACTIVATE = &H10
    Global Const SWP_NOCOPYBITS = &H100
    Global Const SWP_NOMOVE = &H2
    Global Const SWP_NOOWNERZORDER = &H200
    Global Const SWP_NOREDRAW = &H8
    Global Const SWP_NOREPOSITION = SWP_NOOWNERZORDER
    Global Const SWP_NOSIZE = &H1
    Global Const SWP_NOZORDER = &H4
    Global Const SWP_SHOWWINDOW = &H40
    Global Const HWND_BOTTOM = 1
    Global Const HWND_BROADCAST = &HFFFF&
    Global Const HWND_DESKTOP = 0
    Global Const HWND_NOTOPMOST = -2
    Global Const HWND_TOPMOST = -1
    Global Const HWND_TOP = 0
    Global Const Flags=SWP_NOMOVE Or SWP_NOSIZE窗体部分:
    Dim Success as Long
    SuccesS=SetwindowPos(me.HWnd. HWND_TOPMOST,0,0,0,0,FLAGS)
    若Success返回的值不等于零则表示调用成功。
      

  4.   

    模块
    Option ExplicitPublic Const HWND_TOP = 0
    Public Const HWND_BOTTOM = 1
    Public Const HWND_TOPMOST = -1
    Public Const HWND_NOTOPMOST = -2Public Const SWP_NOSIZE = &H1
    Public Const SWP_NOMOVE = &H2
    Public Const SWP_NOZORDER = &H4
    Public Const SWP_NOREDRAW = &H8Declare 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
    窗体
    Option ExplicitPrivate Sub Command1_Click()
        SetWindowPos Me.hwnd, HWND_TOPMOST, 0, 0, 0, 0, SWP_NOSIZE Or SWP_NOMOVE
    End SubPrivate Sub Command2_Click()
        SetWindowPos Me.hwnd, HWND_NOTOPMOST, 0, 0, 0, 0, SWP_NOSIZE Or SWP_NOMOVE
    End Sub