给CComboBox添加记忆

来源:互联网 发布:origin选择x轴数据 编辑:程序博客网 时间:2024/04/29 03:44
 

CComboBox m_combo;

CString m_str;

 

 

然后定义一个宏定义:

 

#define SEC_STR   "histotry"

 

接着在你按确定的按钮的点击函数上实现保存起来

 

UpdateData();  

int index=m_combo.FindStringExact(0,m_str);  

if(index>=0)  

{  

    m_combo.DeleteString(index);  

    m_combo.InsertString(0,m_str);  

    m_combo.SetCurSel(0);  

}  

else 

{  

    m_combo.InsertString(0,m_str);  

}  

CWinApp *app=AfxGetApp();  

for(int i=0;i<m_combo.GetCount();i++)  

{  

    CString id;  

    id.Format("%d",i);  

    CString str;  

    m_combo.GetLBText(i,str);  

    app->WriteProfileString(SEC_STR,id,str);  

      

       然后在你初始化的函数里添加读取功能

 

CWinApp *app=AfxGetApp();  

for(int i=0;i<20;i++)  

{  

    CString str;  

    str.Format("%d",i);  

    str=app->GetProfileString(SEC_STR,str,"");  

    if(!str.IsEmpty())  

    {  

        m_combo.AddString(str);  

    }  

    else 

    {  

        break;  

    }