您的位置:首页 > 其它

给CComboBox添加记忆

2011-12-29 15:40 99 查看
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;

}

}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: