我在一个非模态窗体中,创建并打开另一个非模态窗体,后代开的窗体总是隐藏在前面打开窗体的后面。如何才能将后面的窗体推到前面来显示?很简单的问题,请大家多多指教了~~

解决方案 »

  1.   

    先打开的窗口Create的时候是不是用了WS_POPUP或者WS_EX_TOPMOST的style,如果用了,会占据最前面的位置,把这些style去掉就可以。另一种方法,把后面打开的窗口的styple设置为WS_EX_TOPMOST,也可以提前。
      

  2.   

    BOOL BringWindowToTop(
      HWND hWnd   // handle to window
    );用这个试试,或者直接调用 CWnd::BringWindowToTop();
      

  3.   

    SetWindowPos() HWND_TOP||HWND_TOPMOST
    MSDN
      

  4.   

    BOOL SetWindowPos(
      HWND hWnd,             // handle to window
      HWND hWndInsertAfter,  // placement-order handle
      int X,                 // horizontal position
      int Y,                 // vertical position
      int cx,                // width
      int cy,                // height
      UINT uFlags            // window-positioning flags
    );
      

  5.   

    hWndInsertAfter 
    Handle to the window to precede the positioned window in the Z order. This parameter must be a window handle or one of the following values: Value Meaning 
    HWND_BOTTOM Places the window at the bottom of the Z order. If the hWnd parameter identifies a topmost window, the window loses its topmost status and is placed at the bottom of all other windows. 
    HWND_NOTOPMOST Places the window above all non-topmost windows (that is, behind all topmost windows). This flag has no effect if the window is already a non-topmost window. 
    HWND_TOP Places the window at the top of the Z order. 
    HWND_TOPMOST Places the window above all non-topmost windows. The window maintains its topmost position even when it is deactivated. 
    For more information about how this parameter is used, see the following Res section. 
      

  6.   

    void SetTopMost(BOOL bMost)
    {
    if( bMost == TRUE )
    {
    SetWindowPos(&CWnd::wndTopMost,0,0,0,0,SWP_NOSIZE|SWP_NOMOVE);
    }
    else
    {
    SetWindowPos(&CWnd::wndNoTopMost,0,0,0,0,SWP_NOSIZE|SWP_NOMOVE);
    }
    }
      

  7.   

    我已经解决了这个问题。在窗体创建的时候,把它的风格设为WS_POPUP就可以了。多谢大家帮助