Saving and restoring windows
An application has code to save its widnows so they can be restored
when the application is restarted. But the code does not work as
intended.
The child window which has the focus seems to affect the save/restore
process. For example, if window X has the focus the restore places the
windows one way but, with the same arrangement of windows, if window Y
has the focus the restore places the windows differently.
Please help me with references to documentation and/or sample code
which would show how to accomplish this task?
TIA.
--
John Small
Re: Saving and restoring windows
My feeling is, you are storing the position of the child window (instead of
the main window)
but then restore the position of the main window (with the child windows
coordinates)
Lars
"John Small" <jsmall@os2world.net> schrieb im Newsbeitrag
news:4rkzjBzzMnpe-pn2-Mr4sJ2dfDLKu@x.y.z...[color=blue]
> An application has code to save its widnows so they can be restored
> when the application is restarted. But the code does not work as
> intended.
>
> The child window which has the focus seems to affect the save/restore
> process. For example, if window X has the focus the restore places the
> windows one way but, with the same arrangement of windows, if window Y
> has the focus the restore places the windows differently.
>
> Please help me with references to documentation and/or sample code
> which would show how to accomplish this task?
>
> TIA.
>
> --
>
> John Small
>[/color]
Re: Saving and restoring windows
On Sun, 29 Jun 2008 10:39:25 UTC, "John Small" <jsmall@os2world.net>
wrote:
[color=blue]
> An application has code to save its widnows so they can be restored
> when the application is restarted. But the code does not work as
> intended.
>
> The child window which has the focus seems to affect the save/restore
> process. For example, if window X has the focus the restore places the
> windows one way but, with the same arrangement of windows, if window Y
> has the focus the restore places the windows differently.
>
> Please help me with references to documentation and/or sample code
> which would show how to accomplish this task?[/color]
To have saved size and position of any open windows of an application
there is a bit tricky work needed.
1. When you does a new install of the system you'll loose any any
knowledge because os2.ini gets lost. So at shutdown time of your app
you will copy your window data from os2.ini into your application.ini.
Good place for that ini will be the directory where the program itsel
is installed or an directory the program stores other data too.
When your program gets restarted it will copy the data from your
application.ini back to os2.ini to restore any data regardles of if
the progrsm gets started first time after reinstall of the system or
not.
You'll have to save and restore
- x/y, cx/cy position of frame
size and position of dependant windows can be easy calculated
- font, fontsize, fore- and background colors of each window you
allows to change separately
To get the work done remember the Prf-APIs.
After setting the values in os2.ini you MUST use the APIs
(WinSetWindowPos, ...) to set the correct values. Sending messages is
not enough. It is the frame that controls its childs.
Yes, it's hard work to get anything right but your user will
(hopefully) say thank you.
--
Tschau/Bye
Herbert
Visit [url]http://www.ecomstation.de[/url] the home of german eComStation
eComStation 1.2R Deutsch ist da!
Re: Saving and restoring windows
Herbert Rosenau wrote:[color=blue]
> On Sun, 29 Jun 2008 10:39:25 UTC, "John Small" <jsmall@os2world.net>
> wrote:
>
>[color=green]
>>An application has code to save its widnows so they can be restored
>>when the application is restarted. But the code does not work as
>>intended.
>>
>>The child window which has the focus seems to affect the save/restore
>>process. For example, if window X has the focus the restore places the
>>windows one way but, with the same arrangement of windows, if window Y
>>has the focus the restore places the windows differently.
>>
>>Please help me with references to documentation and/or sample code
>>which would show how to accomplish this task?[/color]
>
> To have saved size and position of any open windows of an application
> there is a bit tricky work needed.
>
> 1. When you does a new install of the system you'll loose any any
> knowledge because os2.ini gets lost. So at shutdown time of your app
> you will copy your window data from os2.ini into your application.ini.
> Good place for that ini will be the directory where the program itsel
> is installed or an directory the program stores other data too.
>
> When your program gets restarted it will copy the data from your
> application.ini back to os2.ini to restore any data regardles of if
> the progrsm gets started first time after reinstall of the system or
> not.[/color]
????
Why bother cluttering up the OS2.INI with that junk? Just put it right
in the application INI.
[color=blue]
> You'll have to save and restore
> - x/y, cx/cy position of frame[/color]
Don't forget the minimized locations too.
--
[Reverse the parts of the e-mail address to reply.]
Re: Saving and restoring windows
On Thu, 3 Jul 2008 17:34:02 UTC, Marty <net@comcast.martyamodeo>
wrote:
[color=blue]
>
> Why bother cluttering up the OS2.INI with that junk? Just put it right
> in the application INI.[/color]
It is the PM that accesses it in os2.ini but not in application.ini.
In original it will be set by PM in os2*.ini - saved in
application.ini by the app and restored by the app from its ini when
the app runs again. It makes no sene to test ift it is alredy ther to
set it only when not already seted. So do it blindly.
I see it as comfort to the customomer to save any possible setting and
restore them when they were lost during a system install. When you
sees no comfort in helping your customer in bewaring his setup over
failover you can leave the inis alone and let the customer do any
single step of configuration again.
--
Tschau/Bye
Herbert
Visit [url]http://www.ecomstation.de[/url] the home of german eComStation
eComStation 1.2R Deutsch ist da!
Re: Saving and restoring windows
On Thu, 3 Jul 2008 17:34:02 UTC, Marty <net@comcast.martyamodeo> wrote:
[color=blue]
> ????
>
> Why bother cluttering up the OS2.INI with that junk? Just put it right
> in the application INI.[/color]
Maybe he refers to the Win(Re-)StoreWindowPos APIs. The good thing about
these is, that they will not only save/restore the sizes and positions,
but also presentation parameters like fonts and colors etc. The bad
thing
is, that for some strange reason it is not possible to specify a file
name.
So data will end up in OS2.INI. However, instead of copying the stuff
back
and forth, I would probably not use that API at all if I don't want the
stuff to reside in OS2.INI.
BTW, one should not forget to use meaningful defaults in case of no INI
entry exists or the values beeing bogus. Users normally don't really
like
windows way outside the desktop area or at position (0,0) with a size
of (0,0) ;-).
--
Ruediger "Rudi" Ihle [S&T Systemtechnik GmbH, Germany]
[url]http://www.s-t.de[/url]
Please remove all characters left of the "R" in my email address
Re: Saving and restoring windows
Herbert Rosenau wrote:[color=blue]
> On Thu, 3 Jul 2008 17:34:02 UTC, Marty <net@comcast.martyamodeo>
> wrote:
>[color=green]
>>Why bother cluttering up the OS2.INI with that junk? Just put it right
>>in the application INI.[/color]
>
> It is the PM that accesses it in os2.ini but not in application.ini.
> In original it will be set by PM in os2*.ini - saved in
> application.ini by the app and restored by the app from its ini when
> the app runs again. It makes no sene to test ift it is alredy ther to
> set it only when not already seted. So do it blindly.[/color]
I think it's generally a bad practice to let this stuff sit in OS2.INI
because it will leave a "residue" after the app is uninstalled, and
prevents the possible use of different, non-colliding profiles.
Here's my usual techinque which is easy and works well:
// Inside of case WM_CLOSE
HINI iniFile;
HWND win;
SWP swp;
WinQueryWindowPos( win, &swp );
if ( (swp.fl & SWP_MINIMIZE) || (swp.fl & SWP_MAXIMIZE) )
{
swp.x = WinQueryWindowUShort( win, QWS_XRESTORE );
swp.y = WinQueryWindowUShort( win, QWS_YRESTORE );
swp.cx = WinQueryWindowUShort( win, QWS_CXRESTORE );
swp.cy = WinQueryWindowUShort( win, QWS_CYRESTORE );
}
PrfWriteProfileData( iniFile, "My Main Window",
"Window position data", &swp, sizeof( SWP ) );
....
// After WinCreateStdWindow call
#define DEFAULT_WIDTH 320
#define DEFAULT_HEIGHT 200
RECTL desktop;
SWP swp;
ULONG tmpLong;
HWND hFrame, hClient;
// Window handles from WinCreateStdWindow
// Note WinCreateStdWindow called without WS_VISIBLE
WinQueryWindowRect( HWND_DESKTOP, &desktop );
swp.x = desktop.xLeft + ((desktop.xRight - desktop.xLeft -
DEFAUT_WIDTH) / 2);
swp.y = desktop.yBottom + ((desktop.yTop - desktop.yBottom -
DEFAULT_HEIGHT) / 2);
swp.cx = DEFAULT_WIDTH;
swp.cy = DEFAULT_HEIGHT;
// Establish defaults
tmpLong = sizeof( SWP );
PrfQueryProfileData( iniFile, "My Main Window",
"Window position data", &swp, &tmpLong );
// Read INI settings if there are any
WinSetWindowPos( hFrame, 0, swp.x, swp.y, swp.cx, swp.cy,
SWP_SIZE | SWP_MOVE | SWP_SHOW );
This method never touches the OS2.INI file if you specify your own
profile handle.
--
[Reverse the parts of the e-mail address to reply.]
Re: Saving and restoring windows
Ruediger Ihle wrote:[color=blue]
> On Thu, 3 Jul 2008 17:34:02 UTC, Marty <net@comcast.martyamodeo> wrote:
>[color=green]
>>????
>>
>>Why bother cluttering up the OS2.INI with that junk? Just put it right
>>in the application INI.[/color]
>
> Maybe he refers to the Win(Re-)StoreWindowPos APIs. The good thing about
> these is, that they will not only save/restore the sizes and positions,
> but also presentation parameters like fonts and colors etc. The bad
> thing
> is, that for some strange reason it is not possible to specify a file
> name.
> So data will end up in OS2.INI. However, instead of copying the stuff
> back
> and forth, I would probably not use that API at all if I don't want the
> stuff to reside in OS2.INI.[/color]
Never found or used that API myself. If you can't select an INI handle,
then it seems kinda useless to me.
[color=blue]
> BTW, one should not forget to use meaningful defaults in case of no INI
> entry exists or the values beeing bogus. Users normally don't really
> like
> windows way outside the desktop area or at position (0,0) with a size
> of (0,0) ;-).[/color]
A point well worth mentioning!
--
[Reverse the parts of the e-mail address to reply.]
Re: Saving and restoring windows
On Thu, 03 Jul 2008 23:49:21 -0700, Marty <net@comcast.martyamodeo> wrote:
[color=blue][color=green][color=darkred]
>>>Why bother cluttering up the OS2.INI with that junk? Just put it right
>>>in the application INI.[/color]
>>
>> Maybe he refers to the Win(Re-)StoreWindowPos APIs. The good thing about
>> these is, that they will not only save/restore the sizes and positions,
>> but also presentation parameters like fonts and colors etc. The bad
>> thing
>> is, that for some strange reason it is not possible to specify a file
>> name.
>> So data will end up in OS2.INI. However, instead of copying the stuff
>> back
>> and forth, I would probably not use that API at all if I don't want the
>> stuff to reside in OS2.INI.[/color]
>
> Never found or used that API myself. If you can't select an INI handle,
> then it seems kinda useless to me.[/color]
You need to use the right APIs then. This is what I wrote for the XWP
Helpers code:
#pragma pack(2)
typedef struct _STOREPOS
{
USHORT usMagic; // Always 0x7B6A (???)
ULONG ulFlags;
USHORT usXPos;
USHORT usYPos;
USHORT usWidth;
USHORT usHeight;
ULONG ulRes1; // Always 1 (???)
USHORT usRestoreXPos;
USHORT usRestoreYPos;
USHORT usRestoreWidth;
USHORT usRestoreHeight;
ULONG ulRes2; // Always 1 (???)
USHORT usMinXPos;
USHORT usMinYPos;
ULONG ulScreenWidth;
ULONG ulScreenHeight;
ULONG ulRes3; // Always 0xFFFFFFFF (???)
ULONG ulRes4; // Always 0xFFFFFFFF (???)
ULONG ulPPLen; // Presentation Parameters length
} STOREPOS, *PSTOREPOS;
#pragma pack()
#pragma import(WinGetFrameTreePPSize, , "PMWIN", 972)
#pragma import(WinGetFrameTreePPs, , "PMWIN", 973)
ULONG APIENTRY WinGetFrameTreePPSize(HWND hwnd);
ULONG APIENTRY WinGetFrameTreePPs(HWND hwnd, ULONG cchMax, PCH pch);
BOOL XWPENTRY winhStoreWindowPos(HWND hwnd, HINI hIni, const char *pcszApp, const char *pcszKey);
/*
*@@ winhStoreWindowPos:
* saves the position of a certain window in the same format
* as the barely documented WinStoreWindowPos API.
* This uses the completely undocumented calls
* WinGetFrameTreePPSize and WinGetFrameTreePPs imported
* from PMWIN.DLL ordinals 972 and 973.
*
* The window should still be visible on the screen
* when calling this function. Do not call it in WM_DESTROY,
* because then the SWP data is no longer valid.
*
* This returns TRUE if saving was successful.
*
*@@added (2006-10-31) [pr]
*@@changed (2006-12-16) [pr]: detect screen height/width
*/
BOOL winhStoreWindowPos(HWND hwnd, // in: window to save
HINI hIni, // in: INI file (or HINI_USER/SYSTEM)
const char *pcszApp, // in: INI application name
const char *pcszKey) // in: INI key name
{
BOOL brc = FALSE;
SWP swp;
if (WinQueryWindowPos(hwnd, &swp))
{
ULONG ulSizePP = WinGetFrameTreePPSize(hwnd);
ULONG ulSize = sizeof(STOREPOS) + ulSizePP;
PSTOREPOS pStorePos;
if ((pStorePos = malloc(ulSize)))
{
// This first bit is guesswork as I don't know what it all means,
// but it always seems to be the same everywhere I've looked.
pStorePos->usMagic = 0x7B6A;
pStorePos->ulRes1 = 1;
pStorePos->ulRes2 = 1;
pStorePos->ulRes3 = 0xFFFFFFFF;
pStorePos->ulRes4 = 0xFFFFFFFF;
pStorePos->ulFlags = swp.fl;
pStorePos->usXPos = pStorePos->usRestoreXPos = swp.x;
pStorePos->usYPos = pStorePos->usRestoreYPos = swp.y;
pStorePos->usWidth = pStorePos->usRestoreWidth = swp.cx;
pStorePos->usHeight = pStorePos->usRestoreHeight = swp.cy;
if (swp.fl & (SWP_MAXIMIZE | SWP_MINIMIZE))
{
pStorePos->usRestoreXPos = WinQueryWindowUShort(hwnd, QWS_XRESTORE);
pStorePos->usRestoreYPos = WinQueryWindowUShort(hwnd, QWS_YRESTORE);
pStorePos->usRestoreWidth = WinQueryWindowUShort(hwnd, QWS_CXRESTORE);
pStorePos->usRestoreHeight = WinQueryWindowUShort(hwnd, QWS_CYRESTORE);
}
pStorePos->usMinXPos = WinQueryWindowUShort(hwnd, QWS_XMINIMIZE);
pStorePos->usMinYPos = WinQueryWindowUShort(hwnd, QWS_YMINIMIZE);
pStorePos->ulScreenWidth = WinQuerySysValue(HWND_DESKTOP, SV_CXSCREEN);;
pStorePos->ulScreenHeight = WinQuerySysValue(HWND_DESKTOP, SV_CYSCREEN);;
pStorePos->ulPPLen = WinGetFrameTreePPs(hwnd, ulSizePP, (PSZ)(pStorePos + 1));
ulSize = pStorePos->ulPPLen + sizeof(STOREPOS);
brc = PrfWriteProfileData(hIni, (PSZ)pcszApp, (PSZ)pcszKey, pStorePos, ulSize);
free(pStorePos);
}
}
return brc;
}