tags:

views:

66

answers:

2

In Windows, I have a minimised window that is the foreground window (GetForegroundWindow). I now want to un-minimise the window so that it becomes visible again. How can I bring the window back to its previous state? I.e., if the window was "restored" before minimised, it should be restored, if it was maximised before being minimised, it should be maximised again and especially not restored or something.

It seems I can only determine the window's current state out of {minimised, restored, maximised}, but theoretically, minimised and maximised should be flags that can be set together.

How does the Explorer taskbar know in what state to show a window if the user clicks on it?

+1  A: 

If you use something like C, you can look on to ShowWindow function:

ShowWindow(hWnd, SW_RESTORE)

SW_RESTORE
Activates and displays the window. If the window is minimized or maximized, the system restores it to its original size and position. An application should specify this flag when restoring a minimized window.

Mihail
"If the window is (...) maximized, the system restores it to its original size and position." Exactly that is what I do not want. If the window is minimised and was maximised before, it shall be maximised again, not restored.
LonelyPixel
That's quite strange - I've tryed it and it works good. If the window is minimized and was maximized before, it will be maximized again. I just don't know where the bug is - in the implementation or in documentation :)
Mihail
True. The bug is in the documentation. It really works as expected (not as documented). Normal (Microsoft calls it "restored") windows, then minimised, get restored again; maximised windows, then minimised, get maximised again. Fine. :-)
LonelyPixel
A: 

Without getting technical (I don't know the language you are using for example), the program needs to store the current normal size, the current state and the previous state.

Then when restoring from minimized it can check the previous state and size.

In WPF the current size and state are stored in the Top, Left, Height, Width and WindowState properties of the main window. A copy of the location and size are held in the RestoreBounds structure and this is used by the base classes (so you don't have to) when restoring the window from Maximised for example.

ChrisF
So you mean that I have to remember myself what WindowState the window had before it was minimised? If I know that, I can easily return to the correct previous state, true. I was hoping the OS was doing that for me...
LonelyPixel
@LonelyPixel - no, the app will remember it for you. I was pointing at the various structures that WPF has.
ChrisF