08-09-2023 05:08 PM
Is there some way to have a LabWindows GUI program remember the window position/size/etc. between runs? I was learning a little Visual Studio C# and it has a way to remember certain attributes (somewhere) that are retained between runs. Does LW have something like this?
08-10-2023 02:16 AM
CVI does not have an automatic feature for this, but it offers you the tools to obtain it by your own.
The central point is to save windows position/size when it moves or sizes; this is what you need in the panel callback:
switch (event) {
case EVENT_PANEL_SIZE:
GetPanelAttribute (panel, ATTR_WIDTH, &Width);
GetPanelAttribute (panel, ATTR_HEIGHT, &Height);
SaveWindowSizePos ();
break;
case EVENT_PANEL_MOVE:
GetPanelAttribute (panel, ATTR_TOP, &Top);
GetPanelAttribute (panel, ATTR_LEFT, &Left);
SaveWindowSizePos ();
break;
}
SaveWindowSizePos () is a function to save attributes to disk so that you can restore it at the next execution.
When you need to display a panel you can simply do this:
panelHandle = LoadPanel (0, "MyUirFile.uir", panelID);
SetPanelPos (panelHandle, Top, Left);
SetPanelAttribute (panelHandle, ATTR_HEIGHT, Height);
SetPanelAttribute (panelHandle, ATTR_WIDTH, Width);
08-10-2023 02:29 AM
I forgot to say that ATTR_WINDOW_ZOOM is the attribute to get if the window is maximized.
08-10-2023 08:57 AM - edited 08-10-2023 09:06 AM
I understand. Is there any type of attribute load/save functionality in LabWindows? I suppose I could jam it in the .ini file I am using from the toolbox, if nothing else.
Edit: I suppose all I need to do is save the state on program shutdown, and then load and use it on startup. My career has mostly been working on embedded devices that do not have file systems so I am hoping to find a "recommended standard" for saving this type of data.
08-10-2023 02:43 PM
One thing to consider: Multiple monitors that may or may not be present, or extended in a different arrangement. You could end up with it totally off-screen, I believe.
(If that happens, the kludgey workaround is to give it focus via the task bar, then press <Alt>Space and then the M key (for move), followed by the arrow keys. Try it on a visible window to see how it works.)
08-10-2023 02:45 PM
I have a number of programs I use that do that (I'm lookin' at you, CCS compiler). I've learned about the Windows hot-key ALT-SPACE, M to move them back on to the screen.
I would expect it would be easy for a program to detect "I'm not on a screen that is hooked up" and move, but ... apparently that's not easy to do 😉
08-11-2023 06:02 AM
@AllenInIowa ha scritto:
I understand. Is there any type of attribute load/save functionality in LabWindows? I suppose I could jam it in the .ini file I am using from the toolbox, if nothing else.
Edit: I suppose all I need to do is save the state on program shutdown, and then load and use it on startup. My career has mostly been working on embedded devices that do not have file systems so I am hoping to find a "recommended standard" for saving this type of data.
The IniFile tool is handy and robust and it offers the possibility to revise/edit data even outside of your app if needed. Another possibility is the use of CVIxml instrument to save in .xml format.
As per when to get window position/size, I resolved to do that when the window is sized/moved in the case the window is closed and opened again during program life.
When developing applications for machines on a production line with a single monitor with limited real estate, once the user finds a suitable setup with program windows he's happy if them are restored with the same aspect every time he needs them.