GetGlgItemText() does not return the list index, it returns the length of the string.
CBN_SELENDOK is a windows message... Combo Box Notification... It does not give you the list index. It will give you the ID of the control in the LOWORD of it's WPARAM. It's LPARAM is the combox's handle.
Ok... real world example here...
Code:
// part of a windows message loop...
case 4092 : // control ID
switch (HIWORD(wParm))
{ case CBN_SELENDOK :
FixPulldownEnable(Dlg,LOWORD(wParm));
return 0;
default :
return 0; }
(I don't use the IDC_ thing, I just use the control ID numbers directly and I'm betting somebody's gonna give me some stick about it...But, it works )
Here's the function it calls...
Code:
// check enable states
VOID FixPulldownEnable(HWND Dlg,INT List)
{ INT cs; // selected list item
cs = SendDlgItemMessage(Dlg,List,CB_GETCURSEL,0,0);
// clear data if no selection
if (cs < 1)
{ CheckDlgButton(Dlg,List - 4,0);
CheckDlgButton(Dlg,List - 3,0);
CheckDlgButton(Dlg,List - 2,0);
CheckDlgButton(Dlg,List - 1,0);
SetDlgItemText(Dlg,List + 1,NULL); }
else
CheckDlgButton(Dlg,List - 4,1); }
I don't know how helpful that will be... but does show you how to get the curent list index...
Basically after CBN_SELENDOK you want to jump into your function, grab the list index (the display is not yet updated) and then do what you need to do with the list index value.
In your case you might actually want to store the handle for the bitmap in the list's LPARAM storage for each item and use the index to retrieve that so you can put it in your static control...
Here's an example of using the LPARAMS of each list item...
This loads a Virtual Key table into a list...
Code:
for (x = 0; x < VKTABLE_COUNT; x++)
{ item = SendDlgItemMessage(Dlg,List,CB_ADDSTRING,0,(LPARAM) VKTable[x].Name);
SendDlgItemMessage(Dlg,List,CB_SETITEMDATA,item,VKTable[x].VKey); }
This gets the LPARAM data out of the list when exporting the data to struct...
Code:
// get the vkey from a pulldown list
BYTE GetPulldown(HWND Dlg, INT List)
{ INT cs; // current selection
cs = SendDlgItemMessage(Dlg,List,CB_GETCURSEL,0,0);
return (BYTE) SendDlgItemMessage(Dlg,List,CB_GETITEMDATA,cs,0); }
All the really good stuff happens in messages...
This is where you gain a lot by downloading and reading the Windows API documentation. If you don't want to or can't download it you can read most of it online at:
Windows Development (Windows)
If you want to know about comboboxes search for "combobox control"... it's all there.