CComboBox使用总结
来源:互联网 发布:611zy资源网备用域名 编辑:程序博客网 时间:2024/05/21 10:12
基本用法
//*********************************************************//// 属性Style////Type: Dropdown or Droplist// Dropdown既可以输入也可以选择,Droplist则只能选择// 无法在创建完成之后通过GetWindowLong与SetWindowLong更改此Style// 当为Dropdown时,可通过GetWindowText获取窗口内容;通过SetWindowText设置窗口内容// 当为Droplist时,可通过GetWindowText获取窗口内容;不可通过SetWindowText设置窗口内容//*********************************************************//// Insert Item//m_cb.AddString(TEXT("123")); //在末尾插入Itemm_cb.InsertString(0, TEXT("123")); //在指定位置插入Item//*********************************************************//// Delete Item//int DeleteString(UINT nIndex);void ResetContent();//清空所有内容//*********************************************************//// Get/Set Item Data//DWORD_PTR GetItemData(int nIndex) const;int SetItemData(int nIndex, DWORD_PTR dwItemData);//*********************************************************//// Get Item Count//int GetCount() const;//*********************************************************//// About Selection//int GetCurSel() const; //return CB_ERR if no item is selectedint SetCurSel(int nSelect);//*********************************************************//// Get Item Text//void GetLBText(int nIndex, CString& rString) const;int GetLBText(int nIndex, LPTSTR lpszText) const;
动态创建CComboBox控件
CComboBox *pMyComboBox = new CComboBox();pMyComboBox->Create(WS_CHILD | WS_VISIBLE | WS_TABSTOP | WS_BORDER | CBS_DROPDOWN,CRect(10, 10, 100, 300),this,NULL);pMyComboBox->SetFont(this->GetFont());pMyComboBox->AddString(TEXT("1"));pMyComboBox->AddString(TEXT("2"));pMyComboBox->AddString(TEXT("3"));