• <ins id="pjuwb"></ins>
    <blockquote id="pjuwb"><pre id="pjuwb"></pre></blockquote>
    <noscript id="pjuwb"></noscript>
          <sup id="pjuwb"><pre id="pjuwb"></pre></sup>
            <dd id="pjuwb"></dd>
            <abbr id="pjuwb"></abbr>

            牽著老婆滿街逛

            嚴以律己,寬以待人. 三思而后行.
            GMail/GTalk: yanglinbo#google.com;
            MSN/Email: tx7do#yahoo.com.cn;
            QQ: 3 0 3 3 9 6 9 2 0 .

            VC CIni

            //文件??1:??

            #pragma??once??






            #include??
            " afxTempl.h " ??






            class ??CIni??



            {??



            private :??



            ?????CString??m_strFileName;??



            public :??



            ?????CIni(CString??strFileName):m_strFileName(strFileName)??



            ?????
            {??



            ?????}
            ??



            public :??



            ?????
            // 一般性操作:??



            ?????BOOL??SetFileName(LPCTSTR??lpFileName);????
            // 設置文件名??



            ?????CString??GetFileName(
            void );?? // 獲得文件名??



            ?????BOOL??SetValue(LPCTSTR??lpSection,??LPCTSTR??lpKey,??LPCTSTR??lpValue,
            bool ??bCreate = true );?? // 設置鍵值,bCreate是指段名及鍵名未存在時,是否創建。??



            ?????CString??GetValue(LPCTSTR??lpSection,??LPCTSTR??lpKey);??
            // 得到鍵值.??



            ?????BOOL??DelSection(LPCTSTR??strSection);????
            // 刪除段名??



            ?????BOOL??DelKey(LPCTSTR??lpSection,??LPCTSTR??lpKey);????
            // 刪除鍵名??









            public :??



            ?????
            // 高級操作:??



            ?????
            int ??GetSections(CStringArray & ??arrSection);???? // 枚舉出全部的段名??



            ?????
            int ??GetKeyValues(CStringArray & ??arrKey,CStringArray & ??arrValue,LPCTSTR??lpSection);???? // 枚舉出一段內的全部鍵名及值??






            ?????BOOL??DelAllSections();??






            }
            ;??


            //文件??2:??
            #include??"StdAfx.h"??



            #include??
            "ini.h"??






            #define??MAX_ALLSECTIONS??2048????//全部的段名??



            #define??MAX_SECTION??260????//一個段名長度??



            #define??MAX_ALLKEYS??6000????//全部的鍵名??



            #define??MAX_KEY??260????//一個鍵名長度??






            BOOL??CIni::SetFileName(LPCTSTR??lpFileName)??



            {??



            ?????CFile??file;??



            ?????CFileStatus??status;??






            ?????
            if(!file.GetStatus(lpFileName,status))??



            ?????????
            return??TRUE;??






            ?????m_strFileName
            =lpFileName;??



            ?????
            return??FALSE;??



            }
            ??






            CString??CIni::GetFileName(
            void)??



            {??



            ?????
            return??m_strFileName;??



            }
            ??






            BOOL??CIni::SetValue(LPCTSTR??lpSection,??LPCTSTR??lpKey,??LPCTSTR??lpValue,
            bool??bCreate)??



            {??



            ?????TCHAR??lpTemp[MAX_PATH]??
            ={0};??






            ?????
            //以下if語句表示如果設置bCreate為false時,當沒有這個鍵名時則返回TRUE(表示出錯)??



            ?????
            //!*&*none-value*&!*??這是個垃圾字符沒有特別意義,這樣亂寫是防止湊巧相同。??



            ?????
            if??(!bCreate)??



            ?????
            {??



            ?????????GetPrivateProfileString(lpSection,lpKey,
            "!*&*none-value*&!*",lpTemp,MAX_PATH,m_strFileName);??



            ?????????
            if(strcmp(lpTemp,"!*&*none-value*&!*")==0)??



            ??????????????
            return??TRUE;??



            ?????}
            ??






            ?????
            if(WritePrivateProfileString(lpSection,lpKey,lpValue,m_strFileName))??



            ?????????
            return??FALSE;??



            ?????
            else??



            ?????????
            return??GetLastError();??



            }
            ??






            CString??CIni::GetValue(LPCTSTR??lpSection,??LPCTSTR??lpKey)??



            {??



            ?????DWORD??dValue;??



            ?????TCHAR??lpValue[MAX_PATH]??
            ={0};??






            ?????dValue
            =GetPrivateProfileString(lpSection,lpKey,"",lpValue,MAX_PATH,m_strFileName);??



            ?????
            return??lpValue;??



            }
            ??






            BOOL??CIni::DelSection(LPCTSTR??lpSection)??



            {??



            ?????
            if(WritePrivateProfileString(lpSection,NULL,NULL,m_strFileName))??



            ?????????
            return??FALSE;??



            ?????
            else??



            ?????????
            return??GetLastError();??



            }
            ??






            BOOL??CIni::DelKey(LPCTSTR??lpSection,??LPCTSTR??lpKey)??



            {??



            ?????
            if(WritePrivateProfileString(lpSection,lpKey,NULL,m_strFileName))??



            ?????????
            return??FALSE;??



            ?????
            else??



            ?????????
            return??GetLastError();??



            }
            ??









            int??CIni::GetSections(CStringArray&??arrSection)??



            {??



            ?????
            /*??



            ?????本函數基礎:??



            ?????GetPrivateProfileSectionNames??-??從??ini??文件中獲得??Section??的名稱??



            ?????如果??ini??中有兩個??Section:??[sec1]??和??[sec2],則返回的是??'sec1',0,'sec2',0,0??,當你不知道??????



            ?????ini??中有哪些??section??的時候可以用這個??api??來獲取名稱????



            ?????
            */
            ??



            ?????
            int??i;??????



            ?????
            int??iPos=0;??????



            ?????
            int??iMaxCount;??



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



            ?????TCHAR??chSection[MAX_SECTION]
            ={0};??//存放一個段名。??



            ?????GetPrivateProfileSectionNames(chSectionNames,MAX_ALLSECTIONS,m_strFileName);??






            ?????
            //以下循環,截斷到兩個連續的0??



            ?????
            for(i=0;i<MAX_ALLSECTIONS;i++)??



            ?????
            {??



            ?????????
            if??(chSectionNames[i]==0)??



            ??????????????
            if??(chSectionNames[i]==chSectionNames[i+1])??



            ???????????????????
            break;??



            ?????}
            ??






            ?????iMaxCount
            =i+1;??//要多一個0號元素。即找出全部字符串的結束部分。??



            ?????arrSection.RemoveAll();
            //清空原數組??






            ?????
            for(i=0;i<iMaxCount;i++)??



            ?????
            {??



            ?????????chSection[iPos
            ++]=chSectionNames[i];??



            ?????????
            if(chSectionNames[i]==0)??



            ?????????
            {????????



            ??????????????arrSection.Add(chSection);??



            ??????????????memset(chSection,
            0,MAX_SECTION);??



            ??????????????iPos
            =0;??



            ?????????}
            ??






            ?????}
            ??






            ?????
            return??(int)arrSection.GetSize();??



            }
            ??






            int??CIni::GetKeyValues(CStringArray&??arrKey,CStringArray&??arrValue,??LPCTSTR??lpSection)??



            {??



            ?????
            /*??



            ?????本函數基礎:??



            ?????GetPrivateProfileSection-??從??ini??文件中獲得一個Section的全部鍵名及值名??



            ?????如果ini中有一個段,其下有??"段1=值1"??"段2=值2",則返回的是??'段1=值1',0,'段2=值2',0,0??,當你不知道??????



            ?????獲得一個段中的所有鍵及值可以用這個。????



            ?????
            */
            ??



            ?????
            int??i;??????



            ?????
            int??iPos=0;??



            ?????CString??strKeyValue;??



            ?????
            int??iMaxCount;??



            ?????TCHAR??chKeyNames[MAX_ALLKEYS]
            ={0};??//總的提出來的字符串??



            ?????TCHAR??chKey[MAX_KEY]
            ={0};??//提出來的一個鍵名??






            ?????GetPrivateProfileSection(lpSection,chKeyNames,MAX_ALLKEYS,m_strFileName);??






            ?????
            for(i=0;i<MAX_ALLKEYS;i++)??



            ?????
            {??



            ?????????
            if??(chKeyNames[i]==0)??



            ??????????????
            if??(chKeyNames[i]==chKeyNames[i+1])??



            ???????????????????
            break;??



            ?????}
            ??






            ?????iMaxCount
            =i+1;??//要多一個0號元素。即找出全部字符串的結束部分。??



            ?????arrKey.RemoveAll();
            //清空原數組??



            ?????arrValue.RemoveAll();??






            ?????
            for(i=0;i<iMaxCount;i++)??



            ?????
            {??



            ?????????chKey[iPos
            ++]=chKeyNames[i];??



            ?????????
            if(chKeyNames[i]==0)??



            ?????????
            {??



            ??????????????strKeyValue
            =chKey;??



            ??????????????arrKey.Add(strKeyValue.Left(strKeyValue.Find(
            "=")));??



            ??????????????arrValue.Add(strKeyValue.Mid(strKeyValue.Find(
            "=")+1));??



            ??????????????memset(chKey,
            0,MAX_KEY);??



            ??????????????iPos
            =0;??



            ?????????}
            ??






            ?????}
            ??






            ?????
            return??(int)arrKey.GetSize();??



            }
            ??






            BOOL??CIni::DelAllSections()??



            {??



            ?????
            int??nSection;??



            ?????CStringArray??arrSection;??



            ?????nSection
            =GetSections(arrSection);??



            ?????
            for(int??i=0;i<nSection;i++)??



            ?????
            {??



            ?????????
            if(DelSection(arrSection[i]))??



            ??????????????
            return??GetLastError();??



            ?????}
            ??



            ?????
            return??FALSE;??



            }
            ??









            使用方法:??



            CIni??ini(
            "c:\\a.ini");??



            int??n;??






            /*獲得值??



            TRACE("%s",ini.GetValue("段1","鍵1"));??



            */
            ??






            /*添加值??



            ini.SetValue("自定義段","鍵1","值");??



            ini.SetValue("自定義段2","鍵1","值",false);??



            */
            ??






            /*枚舉全部段名??



            CStringArray??arrSection;??



            n=ini.GetSections(arrSection);??



            for(int??i=0;i<n;i++)??



            TRACE("%s\n",arrSection[i]);??



            */
            ??






            /*枚舉全部鍵名及值??



            CStringArray??arrKey,arrValue;??



            n=ini.GetKeyValues(arrKey,arrValue,"段1");??



            for(int??i=0;i<n;i++)??



            TRACE("鍵:%s\n值:%s\n",arrKey[i],arrValue[i]);??



            */
            ??






            /*刪除鍵值??



            ini.DelKey("段1","鍵1");??



            */
            ??






            /*刪除段??



            ini.DelSection("段1");??



            */
            ??






            /*刪除全部??



            ini.DelAllSections();??



            */
            ??

            posted on 2006-04-17 11:24 楊粼波 閱讀(499) 評論(0)  編輯 收藏 引用 所屬分類: 文章收藏

            久久精品国产AV一区二区三区 | 色综合久久久久久久久五月| 国产精品亚洲美女久久久| 久久精品无码一区二区无码| 亚洲精品乱码久久久久久| 久久久久久国产精品美女 | 99精品久久精品一区二区| 精品伊人久久久| 精品久久久久久久久免费影院| 久久精品成人一区二区三区| 精品久久久久久无码免费| 国产亚州精品女人久久久久久| 国产精品一区二区久久精品无码 | 99精品伊人久久久大香线蕉| 99久久精品免费看国产一区二区三区 | 精品久久人人妻人人做精品| 国产精品久久久久久久午夜片| 91久久香蕉国产熟女线看| 久久久WWW免费人成精品| 久久这里只有精品视频99| 香蕉久久夜色精品国产尤物| 老男人久久青草av高清| 亚洲香蕉网久久综合影视 | 97精品国产97久久久久久免费| 国产一区二区三精品久久久无广告| 精品久久久无码中文字幕天天| 亚洲AⅤ优女AV综合久久久| 久久人人爽人人爽人人片AV不 | 久久影院久久香蕉国产线看观看| 少妇久久久久久被弄到高潮 | 久久青青草原国产精品免费| 国产精品日韩欧美久久综合| 奇米影视7777久久精品人人爽 | 999久久久免费国产精品播放| 色综合久久久久综合99| 久久精品国产亚洲av麻豆色欲 | 亚洲国产另类久久久精品| 久久国产精品99久久久久久老狼| 久久亚洲高清综合| 久久久精品人妻一区二区三区蜜桃 | 人妻无码中文久久久久专区|