同意! 另外,您不可以参考MSDN吗? CComboBox::AddString int AddString( LPCTSTR lpszString );Return ValueIf the return value is greater than or equal to 0, it is the zero-based index to the string in the list box. The return value is CB_ERR if an error occurs; the return value is CB_ERRSPACE if insufficient space is available to store the new string.ParameterslpszStringPoints to the null-terminated string that is to be added.ResAdds a string to the list box of a combo box. If the list box was not created with the CBS_SORT style, the string is added to the end of the list. Otherwise, the string is inserted into the list, and the list is sorted. To insert a string into a specific location within the list, use the InsertString member function.Example// The pointer to my combo box. extern CComboBox* pmyComboBox;// Add 20 items to the combo box. CString str; for (int i=0;i < 20;i++) { str.Format(_T("item string %d"), i); pmyComboBox->AddString( str ); }
msdn上有 CComboBox::AddString int AddString( LPCTSTR lpszString );Return ValueIf the return value is greater than or equal to 0, it is the zero-based index to the string in the list box. The return value is CB_ERR if an error occurs; the return value is CB_ERRSPACE if insufficient space is available to store the new string.ParameterslpszStringPoints to the null-terminated string that is to be added.ResAdds a string to the list box of a combo box. If the list box was not created with the CBS_SORT style, the string is added to the end of the list. Otherwise, the string is inserted into the list, and the list is sorted. To insert a string into a specific location within the list, use the InsertString member function.Example// The pointer to my combo box. extern CComboBox* pmyComboBox;// Add 20 items to the combo box. CString str; for (int i=0;i < 20;i++) { str.Format(_T("item string %d"), i); pmyComboBox->AddString( str ); }
可以在创建这个combox时制定它
的CBS_SORT风格,看msdn
BOOL Create( DWORD dwStyle, const RECT& rect, CWnd* pParentWnd, UINT nID );例如:
CCombox *m_combo2;m_combo2->create(WS_CHILD | WS_VISBLE | WS_BORDER | WS_VSCROLL
CBS_SORT | CBS_DROPDOWN,
rect,this,COMBO);
另外,您不可以参考MSDN吗?
CComboBox::AddString
int AddString( LPCTSTR lpszString );Return ValueIf the return value is greater than or equal to 0, it is the zero-based index to the string in the list box. The return value is CB_ERR if an error occurs; the return value is CB_ERRSPACE if insufficient space is available to store the new string.ParameterslpszStringPoints to the null-terminated string that is to be added.ResAdds a string to the list box of a combo box. If the list box was not created with the CBS_SORT style, the string is added to the end of the list. Otherwise, the string is inserted into the list, and the list is sorted. To insert a string into a specific location within the list, use the InsertString member function.Example// The pointer to my combo box.
extern CComboBox* pmyComboBox;// Add 20 items to the combo box.
CString str;
for (int i=0;i < 20;i++)
{
str.Format(_T("item string %d"), i);
pmyComboBox->AddString( str );
}
CComboBox::AddString
int AddString( LPCTSTR lpszString );Return ValueIf the return value is greater than or equal to 0, it is the zero-based index to the string in the list box. The return value is CB_ERR if an error occurs; the return value is CB_ERRSPACE if insufficient space is available to store the new string.ParameterslpszStringPoints to the null-terminated string that is to be added.ResAdds a string to the list box of a combo box. If the list box was not created with the CBS_SORT style, the string is added to the end of the list. Otherwise, the string is inserted into the list, and the list is sorted. To insert a string into a specific location within the list, use the InsertString member function.Example// The pointer to my combo box.
extern CComboBox* pmyComboBox;// Add 20 items to the combo box.
CString str;
for (int i=0;i < 20;i++)
{
str.Format(_T("item string %d"), i);
pmyComboBox->AddString( str );
}