0

I'm constructing a UI using wxWidgets.

In my GUI, I generate a window (wxFrame class) which is accessible through pushing a bitmap button. In that window, I also perform some tasks, again pushing some bitmap buttons and diabling them etc. But I can't close and reopen that window with the state saved. I always have to re-initialize it, and this is very impractical.

How can I save the state of my window? I checked the internet, it's suggested to use wxPersistent class but this class is missing in my wxWidgets.

Thank you for any help,

Best Regards.

3
  • Does it have to persist across program launches? Or do you just need persistence between window openings/closings within the program lifetime?
    – In silico
    Sep 23, 2011 at 6:49
  • I need it within the program lifetime. The whole process can be killed after I close the program. But during the lifetime, I want to save the state of the other windows which I open using buttons. Sep 23, 2011 at 6:52
  • FYI wxPersistentXXX is only available in wxWidgets 2.9.
    – VZ.
    Sep 28, 2011 at 17:22

1 Answer 1

1

Instead of destroying the window every time, you can just hide it with the wxWindow::Show() member function, passing false as the argument, when you receive a wxCloseEvent. You then veto the wxCloseEvent to prevent WxWidgets from destroying your window:

// In your close handler:
if(evt.CanVeto()) // Where evt is a wxCloseEvent
{
    Show(false);  // Hide window
    evt.Veto();   // Prevent window destruction
}

This should remove it from the screen, but all the initialized parts should still be there. If you need to show it again, call the Show() method again with true.

2
  • Marvelous!! Thank you! I modified my event handler function and it works! Is there also a way to modify the "x" - closing button on the top so that it doesn't destroy but hides the window? Sep 23, 2011 at 7:02
  • You need to Veto() the wxCloseEvent. For example, you can probably put something like this: if(evt.CanVeto()) { Show(false); evt.Veto(); } in your close handler. Basically, if we can veto the close, we veto it to prevent WxWidgets from destroying the window.
    – In silico
    Sep 23, 2011 at 7:13

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.