GetForegroundWindow() ??
枚举窗口EnumWindows()得到第一个窗口判断是否和你指定的窗口HWND相等?

解决方案 »

  1.   

    在OnWindowPosChanged应该这样就可以吧?
    if (!(lpwndpos->flags & SWP_NOACTIVATE))
    {
    }SWP_NOACTIVATE Does not activate the window. If this flag is not set, the window is activated and moved to the top of either the topmost or non-topmost group (depending on the setting of the hWndInsertAfter parameter).
     
    hwndInsertAfter 
    Specifies the position of the window in Z order (front-to-back position). This member can be a handle to the window behind which this window is placed, or can be one of the special values listed with the SetWindowPos function. 
      

  2.   

    HWND desWnd = ::GetDesktopWindow();
    HWND topWnd = ::GetTopWindow(desWnd);
    if(topWnd == this->m_hWnd)
    {
       //说明自己在顶层
    }
      

  3.   

    通过观察发现,鼠标点出该窗口,键盘切换出,BringWindowToTop掉出该窗口
    void OnWindowPosChanged(WINDOWPOS* lpwndpos)里面可以这样写,
    BOOL bSWP_DRAWFRAME      = ((lpwndpos->flags & SWP_DRAWFRAME     ) == SWP_DRAWFRAME     );
    BOOL bSWP_FRAMECHANGED   = ((lpwndpos->flags & SWP_FRAMECHANGED  ) == SWP_FRAMECHANGED  );
    BOOL bSWP_HIDEWINDOW     = ((lpwndpos->flags & SWP_HIDEWINDOW    ) == SWP_HIDEWINDOW    );
    BOOL bSWP_NOACTIVATE     = ((lpwndpos->flags & SWP_NOACTIVATE    ) == SWP_NOACTIVATE    );
    BOOL bSWP_NOCOPYBITS     = ((lpwndpos->flags & SWP_NOCOPYBITS    ) == SWP_NOCOPYBITS    );
    BOOL bSWP_NOMOVE         = ((lpwndpos->flags & SWP_NOMOVE        ) == SWP_NOMOVE        );
    BOOL bSWP_NOOWNERZORDER  = ((lpwndpos->flags & SWP_NOOWNERZORDER ) == SWP_NOOWNERZORDER );
    BOOL bSWP_NOREDRAW       = ((lpwndpos->flags & SWP_NOREDRAW      ) == SWP_NOREDRAW      );
    BOOL bSWP_NOREPOSITION   = ((lpwndpos->flags & SWP_NOREPOSITION  ) == SWP_NOREPOSITION  );
    BOOL bSWP_NOSENDCHANGING = ((lpwndpos->flags & SWP_NOSENDCHANGING) == SWP_NOSENDCHANGING);
    BOOL bSWP_NOSIZE         = ((lpwndpos->flags & SWP_NOSIZE        ) == SWP_NOSIZE        );
    BOOL bSWP_NOZORDER       = ((lpwndpos->flags & SWP_NOZORDER      ) == SWP_NOZORDER      );
    BOOL bSWP_SHOWWINDOW     = ((lpwndpos->flags & SWP_SHOWWINDOW    ) == SWP_SHOWWINDOW    );
    BOOL bTop = (
    bSWP_DRAWFRAME      == FALSE && 
    bSWP_FRAMECHANGED   == FALSE && 
    bSWP_HIDEWINDOW     == FALSE && 
    bSWP_NOACTIVATE     == FALSE && 
    bSWP_NOCOPYBITS     == FALSE && 
    bSWP_NOMOVE         == TRUE  && 
    bSWP_NOOWNERZORDER  == FALSE && 
    bSWP_NOREDRAW       == FALSE && 
    bSWP_NOREPOSITION   == FALSE && 
    bSWP_NOSENDCHANGING == FALSE && 
    bSWP_NOSIZE         == TRUE  && 
    bSWP_NOZORDER       == FALSE && 
    bSWP_SHOWWINDOW     == FALSE);
    if (bTop == TRUE)
    {
        //  感觉这个方法有些不是很优美,不知道有没有啥缺陷或者更好的方法
    }