Application Development framework discussion-application configuration-wxFileConfig

Source: Internet
Author: User

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.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.