tags:

views:

34

answers:

2

I can use GetDlgItemText to get the text from a control, but I want to clear the selection and SetDlgItemText(IDC_CTRL,_T("")); doesn't work. What is the right approach here?

+1  A: 

Assuming I'm reading the MSDN documentation for the Combo Boxes and the CB_SETCURSEL message right, you can send a CB_SETCURSEL message to the combo box with the wParam(In this case it will be the index of the string in the combo box) being set to -1. This should then clear the selection.

You can also decide to use the ComboBox_SetCurSel macro that wraps the message sending, it can make life a bit easier. Once again -1 will clear the selection.

Of course that would require you to get the handle of the combo box if you don't have it(I'm assuming you do, but in case you don't) you can possibly get it using the GetDlgItem function by supplying the handle for the dialog box and the id of the combo box.

Jacob
+1  A: 

If you use pure Win32 API you could use ComboBox_GetText macro to get text from a combo box control (ComboBox_SetText to set text). To get a string from a list in a combo box use ComboBox_GetLBText.

Kirill V. Lyadvinsky