Showing previous window on minimize (just one solution)

C

C. Vollmer

Hi,

just in case somebody doesn't know: There is a problem if you have an
app with several windows, e.g. form a 'Loging/Logout', form b 'Main
Menu', form c 'data'. If you open a, then b and then c, then put your
PPC on the table and go away until next day (or you have another way to
minimize all windows), then you start your PPC again, all windows are
minimized. If you now start your app again, .NET CF is smart enough to
see that your app is already started. So your last opened windows gets
shown, form c. But if you minimze that, you don't see form b or a, you
just see what was behind form c. So you don't have the possibility to
close your app or logout or do anything on form a or b.

There may be other and more intelligent solutions for this problem
(Katie promised better handling with v2), but this is my story (I had to
find a solution very quick, as always ;-)).

If your app has the windows always only at one place, you are "a bit"
lucky. You only have to know when your windows is minimized, and then
show the window that has to get shown. If the same windows can be shown
at several places in your app, it's more complicated.
My attempt was a simple stack for the windows. I have a little cache for
my forms in a factory, so I just hooked in there and always put my new
form on the stack. Now I only need to know when a windows is minimized,
get the form from the stack and show the next one. And there is the
biggest problem. There is no event for "minimize". As Maarten Struys
(thanks to Maarten) pointed out, there is a special order when a form
gets minimized. But, this order (at least in my app) happens also when I
open a Messagebox, when I show a new form ... I even have the same
order, when I open a new form b, put focus in a control, minimize, open
b again and put focus again in the control. The order is the same, just
not in the same "phase". (By the way, it is most funny when you have the
focus in a control, because then, on minimize, you only get the
Deactivate event, Validating and Validated get thrown when the focus
gets to the control.)

To make a long story short: All you have to do is find all cases that
you find are not minimize, try to avoid "Show previous window" in that
cases and pray, that now you only show the previous window in case of a
minimize.

Longer story (of my actual solution):
- Create a central stack where you put every form that you show.
- Base class for all forms, hook in events Deactivate, Validating,
Validated, LostFocus.
- If these events take place in that order, it should be a minimize.
- Prevent to respond to messageboxes, showing other forms, starting
other apps (maybe even controls from 3rd parties), showing start screen, ...
- When removing from the stack, be shure to only remove if the sender is
on top of the stack (there were some strange scenarios where it wasn't
the same).
- But be also shure, to remove every instance of the sender on top of
the stack (it may happen that you open form a several times, not knowing
that you minimized it in between. In that case you have form a several
times on top of the stack and every time you try to close it you show it
again because you think it is the next window in the z-order.)

It took me some time to figure out these things and to implement them.
If you try it, take some time! And still I know some ways to cheat my
app. But I hope, the user won't use the app that way. (And I'm too lazy
to code any more on this ... ;-)).

Regards,
Christoph
 
C

C. Vollmer

I forgot my other solution: No minimize, just OK button and then just
hide the form in the close event. ;-)
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top