MFC Global Configuration Read Save configuration

Source: Internet
Author: User

Do not know about the global configuration of how others are handled, the most recent things are used in the global configuration, and to save the software settings, the next time you start to use the last shutdown configuration.

My approach is to build a class to hold and read the configuration, and to create variables in this class that are used by all interface classes and processing classes.

For example, the name of this class

Cgloableconfig

For example, I use a variable in a lot of dialog boxes or processing classes.

CString Strllow;

This variable is required to be read from the configuration file when the software is started, and when the software is closed, the size of this value in a dialog box needs to be known in a processing class.

A globally configured class that defines an object in CMainFrame, which is, of course, defined in the main view for a single document or dialog box for a multi-document program.

Cgloableconfig gloablecfg;

In this cgloableconfig, there is an initialization function, a save function at exit.

void Cgloableconfig::init (CString strfile)

void Cgloableconfig::saveconfig (CString strfile)

The INI file is used as the configuration file, and the Init function is called to read the value when the software is started.


GetPrivateProfileString ("panding", "Llow", "Odd", chartemp,20,strfile);
Strllow.format ("%s", chartemp);

Call Saveconfig to save the value at exit

WritePrivateProfileString ("panding", "Llow", strllow,strfile);

In the dialog box that sets this value, you can modify this value to first get a pointer to the main window

cmainframe* pMainFrame = (cmainframe*) AfxGetMainWnd ();

Pmainframe->gloablecfg.strllow = "12345";

If it's a single document, get a pointer to the main view

Cbrightnessmeasureview * Pmainview = (cbrightnessmeasureview*) ((cframewnd*) AfxGetApp ()->m_pmainwnd) GetActiveView ();

Pmainview->gloablecfg.strllow = "12345";

When using this value, the same as to get the main window or the main view of the pointer, and then get gloablecfg, in order to normal use.

MFC Global Configuration Read Save configuration

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.