• <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>

            牽著老婆滿街逛

            嚴(yán)以律己,寬以待人. 三思而后行.
            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);????
            // 設(shè)置文件名??



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



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



            ?????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);???? // 枚舉出一段內(nèi)的全部鍵名及值??






            ?????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語句表示如果設(shè)置bCreate為false時,當(dāng)沒有這個鍵名時則返回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)??



            {??



            ?????
            /*??



            ?????本函數(shù)基礎(chǔ):??



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



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



            ?????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);??






            ?????
            //以下循環(huán),截斷到兩個連續(xù)的0??



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



            ?????
            {??



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



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



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



            ?????}
            ??






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



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






            ?????
            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)??



            {??



            ?????
            /*??



            ?????本函數(shù)基礎(chǔ):??



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



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



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



            ?????
            */
            ??



            ?????
            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號元素。即找出全部字符串的結(jié)束部分。??



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



            ?????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 楊粼波 閱讀(501) 評論(0)  編輯 收藏 引用 所屬分類: 文章收藏

            久久777国产线看观看精品| 久久精品国产99久久丝袜| 一本一道久久a久久精品综合| 久久综合伊人77777麻豆| 美女久久久久久| 国产成人久久精品一区二区三区 | 一本色道久久88综合日韩精品 | 国产精品九九久久精品女同亚洲欧美日韩综合区| 精品999久久久久久中文字幕| 品成人欧美大片久久国产欧美...| 久久本道久久综合伊人| 亚洲精品综合久久| 国产韩国精品一区二区三区久久| 国产精品xxxx国产喷水亚洲国产精品无码久久一区 | 久久丫精品国产亚洲av不卡 | 亚洲色婷婷综合久久| 秋霞久久国产精品电影院| 久久久久久久免费视频| 亚洲欧洲日产国码无码久久99| 国产亚洲美女精品久久久久狼| 青青久久精品国产免费看| 久久精品国产清高在天天线| 久久久久九国产精品| 久久国产色AV免费观看| 久久一区二区免费播放| 大伊人青草狠狠久久| 久久精品免费全国观看国产| 亚洲国产精品久久久久婷婷软件| 国产精品美女久久福利网站| 久久精品国产99国产电影网 | 精品久久一区二区三区| 国内精品伊人久久久久妇| 久久国产精品-国产精品| 久久精品国产久精国产果冻传媒 | 午夜精品久久久久成人| 91亚洲国产成人久久精品网址| 一本色综合网久久| 污污内射久久一区二区欧美日韩 | 久久国产精品国产自线拍免费| 亚洲成色WWW久久网站| 久久亚洲精品国产精品婷婷|