06-28-2015 08:38 AM
LV2013, Win7
My app has several non-modal windows, some of them resizable.
When the app shuts down, I want to save the position and size of these windows and restore them the next time it starts up, so that things are just as you left them.
I convert the FP.Bounds into a string, and save that in an INI file.
My customer wants to remember whether the window is MAXIMIZED or not, and restore it that way if so.
I realize that there is a FP.STATE property that I need to pay attention to, but I'm looking at something else first.
Here's a scenario, where I CLOSE the window BEFORE I read the BOUNDS.
I open this window.
I set this window to minimum (500x150), and by eyeball, put the top left of the panel in the center of my screen (about 960x540)
I shut down. The position is saved as "L=942,T=506,R=1442,B=656".
I start up again. The window is restored to the same place. Great.
I then MAXIMIZE the window, and shut down.
The position is saved as "L=2,T=46,R=502,B=196".
Why? it stored the new TOP LEFT, but left the SIZE where it was ? ? ?
According to the help text. "If the panel is not open, this property returns the bounds in the posiition in which it was last saved".
Since I'm dynamically opening a reentrant clone, there is no "last saved" position.
Anyway, I tried forcing the FP.CLOSE to occur AFTER the BOUNDS are read.
Here's the same scenario:
I open this window.
I set this window to minimum (500x150), and by eyeball, put the top left of the panel in the center of my screen (about 960x540)
I shut down. The position is saved as "L=926,T=500,R=1426,B=650".
I start up again. The window is restored to the same place. Great.
I then MAXIMIZE the window, and shut down.
The position is saved as "L=2,T=46,R=1918,B=1078".
OK, so that's maximized.
But the trouble is, I've lost the original position/size. If I unmaximize this, there's no where to go - there is no other size to return to.
It just removes the border pixels and the thing is still full screen.
I don't want to have to record all the maximizing operations, and the bounds before and after.
If I try this with MINIMIZED, the BOUNDS don't change - the BOUNDS specify where it would be if you un-minimized it.
But that's not true for MAXIMIZED.
I suppose that I have to do this:
Record FP.STATE (Maximized, Minimized, Standard, Closed)
If state = Maximized
Set State to Standard
Record FP.Bounds.
It looks like that would restore the bounds from wherever they are stored while maximized.
QUESTION: Is there a better way? Is there a way to get to those stored bounds numbers without unmaximizing the window while I'm shutting down?
Blog for (mostly LabVIEW) programmers: Tips And Tricks
06-28-2015 08:46 AM
I haven't played with this myself at all, but I guess if this is really how it behaves, you could probably use the window resize event (don't remember the exact name) to track maximization events during the run. You can then log the previous size info and cache it for using when saving to the file.
06-28-2015 09:19 AM
You're on here 24/7, aren't you?
Yeah, I thought of that, but it's code I would have to add to every window.
I was hoping to add code to the common STARTUP and SHUTDOWN procedures.
I'm working on setting the state to STANDARD before recording the bounds and THEN closing it.
I have a hunch it'll be fugly, but it's when you're quitting anyway, so you shouldn't care too much.
There has to be a secret stash somewhere, where it keeps the bounds to go back to when you un-maximize.
But I don't know how to access it.
Blog for (mostly LabVIEW) programmers: Tips And Tricks
06-28-2015 11:21 AM
Well, for the record, here's my solution, and it's not nearly as ugly as I had feared.
I defined a FORMAT string as "%1s:L=%d,T=%d,R=%d,B=%d"
ON SHUTDOWN:
Format the FP.STATE and the FP.BOUNDS into a string, using the format string above.
I used CLOSED = "X", STANDARD = ".", MAXIMIZED = "+", MINIMIZED = "-", but you can use whatever encoding is sensible.
Save the string somewhere (I already use an INI file for such things, this is just another line).
FP.CLOSE
ON STARTUP:
Read the string from your stash (INI file).
SCAN the FP.STATE and FP.BOUNDS from the string.
Translate the encoded STATE into a real STATE enum.
case STATE of
CLOSED: STATE 1 = CLOSED, STATE 2 = INVALID
STANDARD: STATE 1 = STANDARD, STATE 2 = INVALID
MINIMIZED: STATE 1 = STANDARD, STATE 2 = MINIMIZED
MAXIMIZED: STATE 1 = STANDARD, STATE 2 = MAXIMIZED
FP.OPEN (state = STATE 1)
FP.BOUNDS = RECTANGLE from BOUNDS string (if string is empty [missing PREFS file], I center the window).
If STATE 2 ≠ INVALID
FP.STATE = STATE 2
That's it . If you shut down while a window is MAXIMIZED, it will be restored to MAXIMIZED state, but it will remember the unmaximized state as well.
You can't see the transition from MAX --> STANDARD --> Closed. It's quick enough that you can't see it, even if you're looking for it.
On STARTUP, if you are specifically looking at the right spot, you can see the window appear in standard mode VERY briefly (0.1 sec?), then it is maximized.
Not a problem at all.
If it comes up as MINIMIZED, you can see it briefly appear as standard, and then move toward the dock. More noticable than MAXIMIZED, but still not a problem.
If you DON'T bring up a MINIMIZED window as STANDARD first, then the dock image is blank (white). The window contents are not on that image.
Blog for (mostly LabVIEW) programmers: Tips And Tricks