I have a CDialog (myDialogBox
) that has a CComboBox
member (myComboBox
). My goal is to get the user-typed text (preferably as a CString
) from the edit portion of a dropdown style CComboBox
. But, I cannot seem to get it to work.
I've tried using myComboBox.GetWindowText(myString)
. But whenever I run it in debug mode, my code breaks at ASSERT(::IsWindow(m_hWnd))
within the CWnd::GetWindowText()
function.
I've also tried myDialogBox.GetDlgItemText(MY_COMBOBOX_ID, myString)
, which breaks down in a similar way.
Additionally, I've tried:
COMBOBOXINFO info;
memset(&info,0,sizeof(info));
myComboBox.GetComboBoxInfo(&info);
LPTSTR str = new TCHAR[::GetWindowTextLength(info.hwndItem)];
::GetWindowText(info.hwndItem,str,::GetWindowTextLength(info.hwndItem));
But, it doesn't seem to be populating my info
variable correctly.
Could someone point me in the right direction, please? What am I doing wrong? Any suggestions?
EDIT: Just in case it might help understand my ultimate goal, I am trying to have a combo-box where that can help a user pic and choose from a listing of strings. Nonetheless, if he/she does not want any on the dropdown-list, he can come up with his own string. I'd like a way to receive his user-typed string.
DDX_Control
line in your dialog'sDoDataExchange()
method mappingMY_COMBOBOX_ID
tomyComboBox
. AlsoMY_COMBOBOX_ID
should have a unique numerical value in resource.h. Without those you'd get behaviour such as you're describing. – acraig5075