Example on Define Custom Persistent Controls

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.
Post Reply
samsam598
Super wx Problem Solver
Super wx Problem Solver
Posts: 324
Joined: Mon Oct 06, 2008 12:55 pm

Example on Define Custom Persistent Controls

Post by samsam598 » Sun Jul 06, 2014 5:40 am

Greetings!

I tried to learn how to do persistent/serialization in C++/wxWidgets and find this from the doc:

Code: Select all

Defining Custom Persistent Windows

User-defined classes can be easily integrated with wxPersistenceManager. To add support for your custom class MyWidget you just need to:
1.Define a new MyPersistentWidget class inheriting from wxPersistentWindow<MyWidget>.
2.Implement its pure virtual GetKind() method returning a unique string identifying all MyWidget objects, typically something like "widget" 
3.Implement its pure virtual Save() and Restore() methods to actually save and restore the widget settings using wxPersistentObject::SaveValue() and wxPersistentObject::RestoreValue() methods.
4.Define wxCreatePersistentObject() overload taking MyWidget * and returning a new MyPersistentWidget object.

But I have no clue on how to make a running program,for example,a drawing canvas that remebers its contents when open it the next time; and also ,does wxPersistentManager also work for any other classes/objects created in pure C++?

Tips or a piece of running example would be much appreciated.
Regards,
Sam
-------------------------------------------------------------------
Windows xp
VS.Net 2003/MinGW 3.4.5 C::B character set: UTF-8
wxWidgets github 3.0 RC1 Unicode Static build,Unicode Shared build.

User avatar
doublemax
Moderator
Moderator
Posts: 14080
Joined: Fri Apr 21, 2006 8:03 pm
Location: $FCE2

Re: Example on Define Custom Persistent Controls

Post by doublemax » Sun Jul 06, 2014 10:05 pm

I don't know a complete sample for that. I can only suggest to look into some of the current implementations in <wxdir>\include\wx\persist
Use the source, Luke!

Post Reply