geocoin
geocoin

Reputation: 1281

how to find a window's SW_SHOW/SW_HIDE status

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 ::IsWindowVisible(hWnd) as the control is on a tab sheet, which may itself be switched out, causing IsWindowVisible to return FALSE.

Is there a way to get the SW_SHOW/HIDE (or others) window status or do I need to use the retun value of ShowWindow() and reset accordingly?

edit: as the control is enabled (or disabled) to show, but may not be currently visible, as the tab is switched ot, I would think that it's SW_SHOW status would remain the same, even if the window itself is not actually switched in. If I'm unrealistic in my expectations that that's fine.

So really I'm looking for 'can this window/control be shown'

Upvotes: 16

Views: 28268

Answers (6)

Irfan
Irfan

Reputation: 51

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.

Upvotes: 0

Flavio
Flavio

Reputation: 461

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.

Upvotes: 0

Kirill V. Lyadvinsky
Kirill V. Lyadvinsky

Reputation: 99555

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.

Upvotes: 7

sharptooth
sharptooth

Reputation: 170479

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

Upvotes: 14

jdehaan
jdehaan

Reputation: 19928

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.

Upvotes: 2

Nick Dandoulakis
Nick Dandoulakis

Reputation: 43110

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.

Upvotes: -1

Related Questions