how to find a window's SW_SHOW/SW_HIDE status

前端 未结 6 1759
野趣味
野趣味 2021-01-01 22:44

I am trying to determine a window control\'s visibility that has been hidden or enabled with CWnd::ShowWindow(). (or ::ShowWindow(hWnd,nCmdShow))

I cannot simply use

相关标签:
6条回答
  • 2021-01-01 22:53

    Call GetWindowLong( handle, GWL_STYLE), check the returned value for WS_VISIBLE style presence.

    0 讨论(0)
  • 2021-01-01 22:54

    I would use GetWindowPlacement, however I am not sure if I understood what you want. It fills in a WINDOWPLACEMENT structure and then use the showCmd member.

    0 讨论(0)
  • 2021-01-01 22:57

    If it is a multi-tab dialog and not a control, then override as

    void MyClass::OnShowWindow(BOOL bShow, UINT nStatus)
    {
        m_nCmdShow = bShow;
        CDialog::OnShowWindow(bShow, nStatus);
    }
    

    In BEGIN_MESSAGE_MAP, add ON_WM_SHOWWINDOW().

    m_nCmdShow now has the status if the window is SW_SHOW or SW_HIDE.

    0 讨论(0)
  • 2021-01-01 22:59

    Use GetWindowPlacement. It fills WINDOWPLACEMENT structure, which has field showCmd.

    showCmd
    Specifies the current show state of the window. This member can be one of the following values.

    0 讨论(0)
  • 2021-01-01 23:05

    GetWindowPlacement() function will work only if the window is maximized or minimized. Otherwise, showCmd member will return SW_SHOWNORMAL also when window is hidden, as pointed out in this StackOverflow answer: WINDOWPLACEMENT's showCmd... always 1?

    You can use the more straightforward boolean function IsWindowVisible() to get if the specified Window is in a visible state or not.

    0 讨论(0)
  • 2021-01-01 23:11

    I don't know if there is a proper method for this task but I would try WindowFromPoint Function.

    Remarks

    The WindowFromPoint function does not retrieve a handle to a hidden or disabled window, even if the point is within the window. An application should use the ChildWindowFromPoint function for a nonrestrictive search.

    For example I would convert control's corner coords into screen coords and then try to get it's handle from those points.

    0 讨论(0)
提交回复
热议问题