Click to See Complete Forum and Search --> : COMBOBOXEX, Execution error when I try to insert one item


Braulio
March 31st, 1999, 04:28 AM
Hi,

I'm trying to insert items to a COMBOBOXEX control ( the combo from IE), but when I send the message the program stops

and gives me a nasty error, my code is:

BOOL CComboDlg::AddItems(HWND hwndCB)

{

COMBOBOXEXITEM cbei;

int iCnt;

typedef struct {

int iImage;

int iSelectedImage;

int iIndent;

LPSTR pszText;

} ITEMINFO, *pITEMINFO;

ITEMINFO IInf[]= {

{0,0,0,"First"},

{0,0,0,"Second"},

{0,0,0,"Third"},

{0,0,0,"Fourth"},

};

cbei.mask = CBEIF_TEXT;

for (iCnt = 0;iCnt<4;iCnt++) {

cbei.iItem = iCnt;

cbei.pszText = IInf[iCnt].pszText;

cbei.cchTextMax = sizeof(IInf[iCnt].pszText);

cbei.iImage = 0;

cbei.iSelectedImage = 0;

cbei.iIndent = 0 ;

if (::SendMessage(hwndCB,CBEM_INSERTITEM,0,(LPARAM)&cbei==-1)) return FALSE;

}

//::SendMessage(hwndCB,CBEM_SETIMAGELIST,0,(LPARAM) &m_smallImageList);

return TRUE;

}


How can I solve this ?, Thanks, Bye !

Braulio

Todd Jeffreys
March 31st, 1999, 06:28 AM
Your CBEM_INSERTITEM call it wrong. The last parameter, the address of an ITEMINFO structure, is being compared to =-1. You are sending it the boolean result. Basically it's like this ::SendMessage(hwnd,CBEM_INSERTITEM,0,1); What you want is this

if (::SendMessage(hwndCB,CBEM_INSERTITEM,0,(LPARAM)&cbei) == -1) return FALSE;

Braulio
March 31st, 1999, 06:49 AM
Thanks !, Was that error, I copied it wrong, and change one parenthesis, I didn't realize until now.


...Some questions, From wich inherit CComboBoxEx from Cwnd or from CComboBox ?, Is easy to capture the OnDropDown ( with the class wizard and a normal combo box is easy, but with this CComboBoxEx ?), can I attach a pointer to every item in the COMBOBOXEX like in the normal CComboBox ( SetItemDataPtr) ?


Thanks, Bye !

Braulio

Todd Jeffreys
March 31st, 1999, 07:14 AM
Yeah, in your COMBOBOXEXITEM structure, there is an lParam member. Just fill that member in, and remember to add CBEIF_LPARAM to the mask, and you're all set