ComboBox其实由Edit、ListCtrl组成的 GetComboBoxInfo可以获取到两者的窗口句柄 具体看MSDN typedef struct tagCOMBOBOXINFO { DWORD cbSize; RECT rcItem; RECT rcButton; DWORD stateButton; HWND hwndCombo; //Handle to the combo box. HWND hwndItem; //Handle to the edit box. HWND hwndList; //Handle to the drop-down list. } COMBOBOXINFO, *PCOMBOBOXINFO, *LPCOMBOBOXINFO;
COMBOBOXINFO cbi = {sizeof(COMBOBOXINFO)};
m_cb.GetComboBoxInfo(&cbi);
CWnd::FromHandle(cbi.hwndItem)->GetWindowText(str);
来得到
ComboBox其实由Edit、ListCtrl组成的
GetComboBoxInfo可以获取到两者的窗口句柄
具体看MSDN
typedef struct tagCOMBOBOXINFO {
DWORD cbSize;
RECT rcItem;
RECT rcButton;
DWORD stateButton;
HWND hwndCombo; //Handle to the combo box.
HWND hwndItem; //Handle to the edit box.
HWND hwndList; //Handle to the drop-down list.
} COMBOBOXINFO, *PCOMBOBOXINFO, *LPCOMBOBOXINFO;
GetLBText估计是获取ListBox的Text
随意编辑内容后,如果和原有的Item的String匹配不上的话,CurSel会被设置为-1
这时GetLBText(GetCurSel())是会报错的,获取不到内容
测试了下,在ComboBox里手动输入字符串后,无论匹配不匹配,CurSel都会被设置为-1
CString strText;
GetDlgItem(IDC_COMBO1)->GetWindowText(strText);就这三句话.