Adding data to Combo,which was made using CreateWindow API

Hi,

I have successfully created a Combo using CreateWindow API.

hdlgid = CreateWindow ("COMBOBOX", "",
WS_CHILD | CBS_SIMPLE | CBS_SORT | WS_VSCROLL,
100, 100, 180, 180, g_hWndMain, NULL, g_hInst, NULL) ;

when i add data to combo one by one, it gets added successfully.
but fails in case of a loop.

Fails in this case:-

for (cntr = 0; cntr<g_NoOfCount; cntr++)
{
SendMessage(hdlgid,CB_ADDSTRING, (WPARAM)0,(DWORD)cntr);
}


kindly suggest any solution to fill data in combo using loop.
The last parameter is LPARAM or pointer to a String, not a DWORD:
1
2
3
4
for (cntr = 0; cntr<g_NoOfCount; cntr++)
{
SendMessage(hdlgid,CB_ADDSTRING, (WPARAM)0,(DWORD)cntr);
}


So just convert DWORD to a string first:
1
2
3
4
5
6
7
std::stringstream ss;
for (cntr = 0; cntr<g_NoOfCount; cntr++)
{
ss << cntr;
SendMessageA(hdlgid,CB_ADDSTRING, (WPARAM)0,(LPARAM)ss.str().c_str());
ss.str(""); // delete stringstream content
}
Topic archived. No new replies allowed.