Reputation: 1019
I have a little wxWidget application which can save a few preferences into a simple xml file. Amongst those preferences, I store the position, size and maximized state of my top level window so that I can restore it on the next launch.
By default, when you maximize a window, when you click again the maximize button, you get back your initial (non-maximized) position/size. But when I save my preferences, the only position and size I can get are the maximized one. So when the user restart its application, and want to "un-maximize" it, the window will still occupies the whole screen.
On Windows XP, I did a little trick which was to call SetMaximize(false) before getting the position and size. This was working just fine. But now I'm on Seven, and this doesn't work anymore. It seems that the SetMaximize(false) is deferred : when I break, it works, but during a normal execution, I always end-up with the maximized position/size, as if the unmaximize operation is done in another thread.
So I tried to add a Sleep() just after my "SetMaximize(false)" call, but I need to use a really high value to ensure it's always working, and I don't like that.
So, my question is : is there any way to get the position and size of the non-maximized window ? (I also tried to catch resize events, but it only work for the size, and I need the position also ... and didn't found any "window moved" event)
Thanks in advance for any help !
Upvotes: 1
Views: 613
Reputation: 17056
It's easy.
The "window-moved" class is wxMoveEvent and the event-type for catching any move is wxEVT_MOVE. So define a function in your top-level window class,
void MyFrame::OnMove(wxMoveEvent& evt );
Bind it like so:
Bind(wxEVT_MOVE, &MyFrame::OnMove, this);
In both the OnMove function and the OnSize function, check to see if the window is maximized by calling the member-function IsMaximized(). When it returns true, do not change the position and size data.
Upvotes: 0
Reputation: 2710
I do it with:
wxPoint pos = GetPosition();
wxSize size = GetSize();
and it works with Win7/XP and Linux.
Upvotes: 0