2

When you click a window in your taskbar (Windows users) it will retain it's last state - maximised or normal scalable window. I'm trying to do a similar thing, but programatically and without the window gaining focus (eg. becoming foreground and disturbing my current activity in another window).

Can I do that? Current window state can be obtained using this API call:

   //Empty Window placement structure
   WinDefExt.WINDOWPLACEMENT placement = new WinDefExt.WINDOWPLACEMENT();
   //winapi call to external User32.dll file
   UserExt.GetWindowPlacement(hwnd, placement);
   //showCmd should be equal to one of the SW_ constants (here: https://msdn.microsoft.com/en-us/library/windows/desktop/ms633548%28v=vs.85%29.aspx)
   placement.showCmd;
Tomáš Zato
  • 50,171
  • 52
  • 268
  • 778
  • 1
    This seems like an XY problem to me. See my answer, but I think that really you should concentrate on your other question as it seemed to me that the people commenting on that simply misunderstood what you were asking. Asking "How can I restore a window without it coming to the foreground" is a reasonable question, I just don't think you've stated it clearly enough. – Jonathan Potter Feb 01 '15 at 19:51
  • I think you're right, thanks. I'll keep googling. – Tomáš Zato Feb 01 '15 at 19:53
  • Did you try MoveWindow? I think it can restore window without changing the foreground window. – Mustafa Chelik Feb 04 '15 at 20:10

1 Answers1

4

ShowWindow isn't a "state", it's an "action". There's no GetShowState command. You can infer a value from the current state of the window, but there's no way to find out the actual last value used with ShowWindow.

if (!IsWindowVisible(hWnd))
    swState = SW_HIDE;
else
if (IsIconic(hWnd))
    swState = SW_MINIMIZE;
else
if (IsZoomed(hWnd))
    swState = SW_MAXIMIZE;
else
{
    // not hidden, minimized or zoomed, so we are a normal visible window
    // last ShowWindow flag could have been SW_RESTORE, SW_SHOW, SW_SHOWNA, etc
    // no way to tell
    swState = SW_SHOW;
}
Jonathan Potter
  • 36,172
  • 4
  • 64
  • 79