Combo Box信息的保存与读取

首先为你的COMBOBOX控件添加两个变量,一个是CComboBox类型的,一个是CString类型的。

 

这边假设为:

 

CComboBox m_combo; CString m_str;

 

然后定义一个宏定义:

#define SEC_STR   "DuAiGao"

 

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

 

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; } }

 

这样就实现了,(*^__^*) 嘻嘻

 

觉得不错的话请回复!你的回复是对我的最大支持!谢谢!

 

你可能感兴趣的:(IM)