The perfect application framework should include the classes or interfaces related to saving and reading configuration parameters for the application, so that users cannot perform complex operations on files. This will be inefficient, unstable, and difficult to maintain.
WxFileConfig is a configuration interface provided by the wxWidgets framework. It is cross-platform and easy to use.
Of course, such as wxRegConfig and wxConfig are also very useful. Here we will only introduce the most common and common ones.
WxFileConfig, as its name implies, is a file configuration class that inherits and provides easy-to-use interfaces. The example is as follows:
1. The following header files are required
# Include <wx/config. h>
# Include <wx/fileconf. h>
2. Simple code
Define two macros for ease of use
WxFileConfig
Generally, AppName VendorName indicates the local configuration file name. The system configuration file name uses the relative path.
AppName VendorName can be written at Will here. The local configuration file name can be customized. the system configuration file name is empty and does not need to be used. The relative path refers to the same path as exe.
If the windows platform is determined, you can write it like this. If it is cross-platform, it is not good to use relative paths. It is best not to use relative paths so that they are saved in the corresponding user directory.
# Define BEGIN_CFG_MISC (var_name )\
WxFileConfig * var_name = new wxFileConfig (_ ("wxConfFrame"), _ ("wxConfFrame"), _ ("wxConfFrame. ini"), _ (""), callback );
# Define end_assist_misc (var_name )\
If (var_name )\
Delete var_name;
(1) Write A PARAMETER
BEGIN_CFG_MISC (pConfig );
PConfig-> Write (_ ("KEY2"), _ ("KEY2 "));
End_assist_misc (pConfig );
(2) read a parameter
WxString value;
BEGIN_CFG_MISC (pConfig );
PConfig-> Read (_ ("KEY2"), & value );
End_assist_misc (pConfig );
WxMessageBox (value, value );
For other usage instructions, see the official wxwidgets documentation.