保存ini文件和基本控件的保存函数(序:列表和树的保存)

1列表的保存和提取:

void DIALOG1::SetListValue(int Cname, CString AppName, CString KeyName, CString FileName)
{
int i;
    CString sReceiveBuf[50];
 m=m_Listgroundrun.GetCount();
 for(i=0;i<=m;i++)
  {
   CString temp[50],KeyNamep[50];
        temp[i].Format("%d",i);
  KeyNamep[i]=KeyName+temp[i];

     sRexeiveBuf[i]=m_Listgroundrun.GetItemText(i);
     WritePrivateProfileString(AppName,KeyNamep[i],sReceiveBuf[i],FileName);
    }
 } 

void DIALOG1::GetListValue(int Cname, CString AppName, CString KeyName, CString lpDefault, DWORD nSize, CString FileName)
{
  CString strName,strNamep,str;
  SHFILEINFO sfi;
        CString t="";
  char lpResult[100];
        int i,n;
 for(i=0;i<=50;i++)
 {
        strName.Format("DIALOG1list%d", i); 
     GetPrivateProfileString(AppName,strName,lpDefault,lpResult,nSize,FileName);

  if((lpResult[0]!=t) )
  {
              m_Listgroundrun.InsertItem(0,lpResult);
  }
  else if(lpResult==NULL || lpResult[0]==t)
   break;
 }

2树的保存和提取:

void DIALOG1::SetListValue(int Cname, CString AppName, CString KeyName, CString FileName)
{
int i;
    CString sReceiveBuf[50];
 m=m_Listgroundrun.GetCount();
 HTREEITEM   hSel=m_Listgroundrun.GetRootItem();

  while(hSel)
  {
   for(i=0;i<=m;i++)
 {
   CString temp[50],KeyNamep[50];
        temp[i].Format("%d",i);
  KeyNamep[i]=KeyName+temp[i];
     sReceiveBuf[i]=m_Listgroundrun.GetItemText(hSel);
     TreeVisit(m_Listgroundrun, hSel);
     WritePrivateProfileString(AppName,KeyNamep[i],sReceiveBuf[i],FileName);
     hSel=m_Listgroundrun.GetNextItem(hSel, TVGN_NEXT);
   }
  }
  }

void DIALOG1::TreeVisit(CTreeCtrl& m_Listgroundrun, HTREEITEM hItem)

CString sReceiveBufc,KeyNamepp,AppName,FileName;
int i,len; 
if (m_Listgroundrun.ItemHasChildren(hItem) && hItem !=0x0) 
{
HTREEITEM hChildItem = m_Listgroundrun.GetChildItem(hItem); 
while(hChildItem!=NULL) 
{
 for(i=0;i<=50;i++)
 {
 KeyNamepp.Format("DIALOG1listchild%d", i);
 sReceiveBufc=m_Listgroundrun.GetItemText(hChildItem);
    WritePrivateProfileString("DIALOG1",KeyNamepp,sReceiveBufc,filepath);
    len=sReceiveBufc.GetLength();
 if(len==0)
 break;

TreeVisit(m_Listgroundrun, hChildItem);     //递归遍历孩子节点 
hChildItem = m_Listgroundrun.GetNextItem(hChildItem, TVGN_NEXT);
 } 


}

void DIALOG1::GetListValue(int Cname, CString AppName, CString KeyName, CString lpDefault, DWORD nSize, CString FileName)
{
  CString strName,strNamep,str;
  SHFILEINFO sfi;
        CString t="";
     CString m="//";
  char lpResult[100];
        int i,n;
 for(i=0;i<=50;i++)
 {
        strName.Format("DIALOG1list%d", i);
     GetPrivateProfileString(AppName,strName,lpDefault,lpResult,nSize,FileName);

  if((lpResult[0]!=t) )
  {
              m_Listgroundrun.InsertItem(lpResult);
  }
  else if(lpResult==NULL || lpResult[0]==t)
   break;
 }
 HTREEITEM hSel,m_root;
    CString sReceiveBuf[50],strt,strc;
 n=m_Listgroundrun.GetCount();
 hSel=m_Listgroundrun.GetRootItem();

  while(hSel)
  {
   for(i=0;i<=n;i++)
 {
     sReceiveBuf[i]=m_Listgroundrun.GetItemText(hSel);
  strt=sReceiveBuf[i].Mid(2,1);
  if (strt!=m)
  {
   m_root=hSel;
   break;
  }
     hSel=m_Listgroundrun.GetNextItem(hSel, TVGN_NEXT);
   }
   break;
  }
  for(i=0;i<=50;i++)
 {
        strNamep.Format("DIALOG1listchild%d", i);
     GetPrivateProfileString(AppName,strNamep,lpDefault,lpResult,nSize,FileName);

  if((lpResult[0]!=t) )
  {
            m_Listgroundrun.InsertItem(lpResult,m_root);
  }
  else if(lpResult==NULL || lpResult[0]==t)
   break;
 }

}

你可能感兴趣的:(list,null,ini,dialog)