Click here to Skip to main content
15,922,533 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Drop down list of combo box is not showing item added to it by SendMessage()

This is Dialog box which contains combo box
C++
BOOL CALLBACK AddRuleDlgProc (HWND hAddRuleDlg, UINT message, WPARAM wParam, LPARAM lParam)
{
	 const char *ComboBoxItem[] = {"All","TCP","UDP","ICMP"};
         case WM_INITDIALOG :
         for(i=0;i<3;i++)
         {	 SendMessage((GetDlgItem(hAddRuleDlg,IDC_COMBO4)),CB_ADDSTRING,0,reinterpret_cast<LPARAM>((LPCSTR)ComboBoxItem[i]));
         }
         return TRUE ;
}


This is resource of combo box
C++
COMBOBOX        IDC_COMBO4,81,151,44,49,CBS_DROPDOWNLIST | CBS_OWNERDRAWVARIABLE | WS_VSCROLL | WS_TABSTOP


Please help me asap
Posted
Updated 12-Mar-12 19:18pm
v3
Comments
enhzflep 11-Mar-12 7:48am    
I'd also suggest that you use SendDlgItemMessage function.
i.e
SendDlgItemMessage(hAddRuleDlg, IDC_COMBO4, CB_ADDSTRING, (LPARAM)ComboBoxItem[i]);

You are using CBS_OWNERDRAWVARIABLE (see here[^]) which means that you are expected to supply the items for the list on demand when the combobox is dispalyed or updated. Remove this option and try again.
 
Share this answer
 
Comments
amityadav4a 13-Mar-12 10:57am    
It worked after removing CBS_OWNERDRAWVARIABLE but have to change SendMessage((GetDlgItem(hAddRuleDlg,IDC_COMBO4)),CB_ADDSTRING,0,reinterpret_cast<lparam>(TEXT("amit"));
If you need to use the ownerdrawn-style (so removing it as Richard suggested won't work for you) then try adding CBS_HASSTRINGS (Combo-Box Styles[^].
 
Share this answer
 
Comments
amityadav4a 13-Mar-12 10:46am    
Not working any ways. What can i do now?
Code-o-mat 13-Mar-12 10:51am    
Are you measuring and drawing the items yourself?
Can u try this..

SendMessage(hWndComboBox,CB_ADDSTRING,0,
reinterpret_cast<LPARAM>LPCTSTR)ComboBoxItem[0]));

SendMessage(hWndComboBox,CB_ADDSTRING,0,
reinterpret_cast<LPARAM>((LPCTSTR)ComboBoxItems[1]));

SendMessage(hWndComboBox,CB_ADDSTRING,0,
reinterpret_cast<LPARAM>((LPCTSTR)ComboBoxItems[2]));

SendMessage(hWndComboBox,CB_ADDSTRING,0,
reinterpret_cast<LPARAM>((LPCTSTR)ComboBoxItems[3]));
 
Share this answer
 

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