GetPosition() when minimized / maximized Topic is solved

If you are using the main C++ distribution of wxWidgets, Feel free to ask any question related to wxWidgets development here. This means questions regarding to C++ and wxWidgets, not compile problems.
jakejanovetz
In need of some credit
In need of some credit
Posts: 3
Joined: Wed Jul 27, 2005 1:45 am

GetPosition() when minimized / maximized

Post by jakejanovetz »

Hi folks-

I searched online and found a couple references to this topic from back in 2003, but they were incomplete in the Google cache.

I'd like to store window size/position upon closing in the Windows registry. It seems that when minimized, GetPosition() returns -3200,-3200.

GetWindowPlacement (native Win32 API) seems to do the trick. I was wondering how you folks handle save/restore of the window position under windows.

I noticed that DialogBlocks does the right thing -- is it using wxWidgets code or is it using the native Win32 API?
darklordsatan
Earned a small fee
Earned a small fee
Posts: 17
Joined: Thu Jul 14, 2005 5:51 am

Post by darklordsatan »

Im gonna shot in the dark here.
Sorry if this is stuff you already know...

Code: Select all

// APP START!!!
wxRegKey *key=new wxRegKey("HKEY_LOCAL_MACHINE\\Software\\MyApp");

// We simply check out if the key already exists. Otherwise, lets create it
if(!key->Exists()){
    key->Create();
   // Ok, so, this is the first time the user is running the app, lets get the
   // current x and y with GetPosition() for example...
}
else{
   //So... lets read the key from the registry and then use Move()
   long xValue,yValue;
   key->QueryValue("WinX",&xValue); 
   key->QueryValue("WinY",&yValue);
  // Here we use Move(), for example...

}

//-------------------------------------------------------------------------//

// APP END!!!

/* We are closing!!! (This is a block of code supossed to go in a closing
 * event handling function...)
 * Lets now save the values in the registry...
 */
key->SetValue("WinX",x);
key->SetValue("WinY",y);;
This is, supossing x and y exist. And pretty much the same goes for the window size...

What you could do is listen for wxMoveEvent, that basically tells you when the user is moving the window (thus in "normal" state), and then use the GetPosition() function of such event to know x and y. (And for starters, if the wxRegKey above is not created, which means your user just ran your app for the first time, then initialize x and y to the current position, when the window was just created, otherwise -if the key exists- then read it from the registry and use Move())

This way, when you close the app, you will have in x and y the "normal" position of the window, even if its minimized when the user closes it (and I believe thats your problem, since you say when minimized the returned values are negative)

Hope it helps, cheers
User avatar
Ryan Norton
wxWorld Domination!
wxWorld Domination!
Posts: 1319
Joined: Mon Aug 30, 2004 6:01 pm

Post by Ryan Norton »

Related threads -

http://forums.wxwidgets.org/viewtopic.p ... wplacement

http://forums.wxwidgets.org/viewtopic.p ... =maximized

Also, please use wxConfig, as it is cross-platform while wxRegKey is not... see wxConfigBase in the docs
[Mostly retired moderator, still check in to clean up some stuff]