Click here to Skip to main content
15,921,113 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
In a VC++ project, I have a combobox with dropdown style. During program initialisation, I fill the list of strings from a file, and set the edit of the combo box to a string which I read from registry. However the outcome is not always what I want it to be. Whenever the text which I write to the edit starts with something that is contained in the list, the string from the list is copied to the edit. For example: The list contains the string "UserAdmin", and I do
C++
SendMessage(hwndCombo, WM_SETTEXT, 0, (LPARAM)"UserA");

then the combo edit will show "UserAdmin" (but I want it to show "UserA"). However, if I do
C++
SendMessage(hwndCombo, WM_SETTEXT, 0, (LPARAM)"UserAb");

the combo edit will show "UserAb" as expected. I wonder what I may be doing wrong.

For those who wonder why I don't use CComboBox: This is a function which receives the handle through its parameter list.

Thanks... Hans
Posted

Use DropDownList combobox style. For more help see MSDN link here.


Sample code is also available at this[^] link.
 
Share this answer
 
v2
Comments
hans.sch 20-Sep-12 11:06am    
Thank you for the quick reply. The DropDownList style doesn't solve my problem because it doesn't allow the user to type a string that is not contained in the dropdown list. And, of course, it doesn't let me set such a string via WM_SETTEXT.
As per MSDN:
WM_SETTEXT does not change the current selection in the list box of a combo box. An application should use the CB_SELECTSTRING message to select the item in a list box that matches the text in the edit control.

Try CB_SELECTSRING:
http://msdn.microsoft.com/en-us/library/windows/desktop/bb775895(v=vs.85).aspx[^]
 
Share this answer
 
Comments
hans.sch 20-Sep-12 11:09am    
Thanks for the quick reply. Since I want to write a string to the edit that is not contained in the list, CB_SELECTSTRING is not an option.
Quoting from MSDN at http://msdn.microsoft.com/en-us/library/windows/desktop/ms632644%28v=vs.85%29.aspx: "For a combo box, the text is the contents of the edit-control portion of the combo box."
I may have to explicitly find the edit-control portion... I'll try that tomorrow.

Update: I retrieved the handle of the edit control of the combo box (used Spy++ to make sure this is what I want) and sent the WM_SETTEXT directly to the edit. It doesn't help: The string that is displayed is always one from the list.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900