Operations on the latest file list in VC

Source: Internet
Author: User

Support for the latest file list in the MFC framework

The standard framework program established by MFC has the ability to record recent operation files. the paths of these recent files are recorded in the Registry and added to the File menu when the program is running.

There isCrecentfilelist *M_precentfilelist; the pointer manages this information. 


The following process is analyzed and similar methods are used to save some other recent data with a fixed number.


1. Create a crecentfilelist object, read records, save records, and destroy objects.

① Creation and record reading

If loadstdprofilesettings is called in initinstance () in the cwinapp derived class, crecentfilelist is created, so the program can manage the list of recent files.


At the same time, read the previous records from the registry.

VoidCwinapp: loadstdprofilesettings (uintNmaxmru)// The default value is 4.

{
...
If(Nmaxmru! =0)
{
// Create a crecentfilelist object and initialize it to manage nmaxmru File Information
M_precentfilelist=NewCrecentfilelist (0,_ Afxfilesection,
_ Afxfileentry, nmaxmru );
// Read records
M_precentfilelist->Readlist ();
}
...
}

Key data member in the crecentfilelist object

Crecentfilelist contains a cstring pointerCstring *M_arrnames;It is used to point to a cstring object array, which records the most recent file name.


In additionIntM_nsizeIndicates the number of records.

When an object is created, the constructor completes initialization, including the establishment of the cstring array.

② Record storage and crecentfilelist destruction.

In exitinstance (), savestdprofilesettings () will be called. In savestdprofilesettings (), m_precentfilelist-> writelist (); operations are available to save the record.


DeleteM_precentfilelist; destroys an object.

Crecentfilelist: crecentfilelist (uintNstart,LpctstrLpszsection,

LpctstrLpszentryformat,IntNsize,IntNmaxdisplen)

{
Assert (nsize! =0 );
M_arrnames=NewCstring [nsize];// Create a cstring array.
M_nsize=Nsize;

M_nstart=Nstart;
M_strsectionname=Lpszsection;
M_strentryformat=Lpszentryformat;
M_nmaxdisplaylength=Nmaxdisplen;
}

3. Add record

When the document is saved, setpathname (...) is called, and setpathname (...) is called to call addtorecentfilelist in the application class.


In addtorecentfilelist, execute m_precentfilelist-> Add (lpszpathname) to add the file name to the string array.


VoidCrecentfilelist: add (lpctstrLpszpathname)
{
Assert (m_arrnames! =Null );
Assert (lpszpathname! =Null );
Assert (afxisvalidstring (lpszpathname ));

//FullyQualifyThePathName
TcharSztemp [_ max_path];
Afxfullpath (sztemp,Lpszpathname );// Obtain the full file path

//Search to see if this file name already exists
For(IntImru=0;Imru<M_nSize-1;
Imru ++)
{
If(Afxcomparepath (m_arrnames [imru],Sztemp ))
Break;//Imru

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.