VC:INI文件中節與健的枚舉(GetPrivateProfileSection()、GetPrivateProfileSectionNames())


//先選擇Project|setting命令下Project setting命令下對話框,在Microsoft Foundation Classes下選擇 Use MFC in a Shared DLL

#include<iostream.h>

#include<afx.h>

 

//#include<afx1.h>

#define MAX_ALLSECTIONS 300  //定義最大的段長度

#define MAX_SECTION 20     //段的最大長度

 

void main()

{

      

 

       //2、節與健的枚舉

/*    1 健

              DWORD GetPrivateProfileSection(

                LPCTSTR lpAppName,        // section name

                LPTSTR lpReturnedString,  // return buffer

                DWORD nSize,              // size of return buffer

                LPCTSTR lpFileName        // initialization file name

              );

       2 節

              DWORD GetPrivateProfileSectionNames(

                LPTSTR lpszReturnBuffer,  // return buffer

                DWORD nSize,              // size of return buffer

                LPCTSTR lpFileName        // initialization file name

              );

*/

       int i;

       int pos=0;

       //CString str;

       char chSectionNames[MAX_ALLSECTIONS]={0};//總的提出來的字符串

       char chSection[MAX_SECTION]={0};//存放一個小節名

 

       char chKey[MAX_SECTION]={0};

       //LPCTSTER lpFileName="";

       GetPrivateProfileSectionNames(chSectionNames,MAX_ALLSECTIONS,lpFileName);

 

              //cout<<chSectionNames<<endl;

       for(i=0;i<MAX_ALLSECTIONS-1;i++)

       {

              /*

              if(chSectionNames[i]==0 && chSectionNames[i+1]!=0)//得到前面段明

              {

                     for(int m=pos;m<=i;m++)

                     {

                            chSection[m-pos]=chSectionNames[m];//獲取小節名

                     }

                     pos=i+1;

                     str.Format("%s",chSection);

                     cout<<str<<endl;

              }

              if(chSectionNames[i]==0&&chSectionNames[i+1]==0)//得到最后一個小節名

              {

                     for(int m=pos;m<=i;m++)

                     {

                            chSection[m-pos]=chSectionNames[m];

                     }

                     str.Format("%s",chSection);

                     cout<<str<<endl;

                     break;

              }*/

              if(chSectionNames[i]==0)//得到前面段明

              {

                     for(int m=pos;m<=i;m++)

                     {

                            chSection[m-pos]=chSectionNames[m];//獲取小節名

                     }

                     str.Format("%s",chSection);

                     cout<<str<<endl;

                     //獲取鍵值

                     GetPrivateProfileSection(chSection,chKey,MAX_SECTION,lpFileName);

                     str.Format("%s",chKey);

                     cout<<str<<endl;

 

                     if(chSectionNames[i+1]!=0)

                     {

                            pos=i+1;

                     }

                     else

                     {

                            break;

                     }

      

              }

       }

}


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM