I cant see a really problem in your code. But you should distinguish between combo and list box.
#pragma once
#define WIN32_LEAN_AND_MEAN
#include <windows.h>
#include <tchar.h>
#ifdef _WIN64
#define ON64(C,E) C
#else
#define ON64(C,E) E
#endif
#ifdef _DEBUG
#define ASSERT(B) if(!(B)){ __int2c(); }
#else
#define ASSERT(B)
#endif
static LPCDLGTEMPLATE __dlgResource(const int idr,HINSTANCE h)
{
HRSRC hrsrc = FindResource(h,MAKEINTRESOURCE(idr),RT_DIALOG);
HGLOBAL hres = hrsrc?LoadResource(h,hrsrc):0;
return (LPCDLGTEMPLATE)(hres?LockResource(hres):0);
}
void FillListBox(HWND hwnd,const int idc,UINT filter);
void FillComboBox(HWND hwnd,const int idc, UINT filter);
ON64(INT_PTR,int) FAR PASCAL __dlgProc(HWND h,unsigned int m,WPARAM w,LPARAM l)
{
switch(m)
{
case WM_CLOSE: EndDialog(h,0); break;
case WM_COMMAND:
switch(LOWORD(w))
{
case IDOK:
case IDCANCEL: EndDialog(h,LOWORD(w)); break;
}
break;
case WM_INITDIALOG:
FillListBox(h,101,0x0002);
FillComboBox(h,102,0x0002);
break;
}
return 0;
}
int FAR PASCAL _tWinMain(HINSTANCE h,HINSTANCE p,LPTSTR c,int sw)
{
DialogBoxIndirectParam(h,__dlgResource(1,h),0,__dlgProc,0);
return 0;
}
struct
{
const TCHAR* pWmMsg;
unsigned int fType;
} msginfo[] =
{
{ __T("first") ,0x001 },
{ __T("second") ,0x003 },
{ __T("third") ,0x007 },
};
const int numMessages = sizeof(msginfo)/sizeof(msginfo[0]);
void FillListBox(HWND hwnd,const int idc,UINT filter)
{
HWND hlb = ::GetDlgItem(hwnd,idc);
int index,i,done;
ASSERT(IsWindow(hlb));
if(IsWindow(hlb))
{
SendMessage(hlb,LB_RESETCONTENT,0,0 );
for(done=i=0;i<numMessages;i++)
{
if(msginfo[i].fType & filter)
{
index = SendMessage(hlb,LB_ADDSTRING,0,(LPARAM)msginfo[i].pWmMsg);
SendMessage(hlb,LB_SETITEMDATA,(WPARAM)index,(LPARAM)msginfo[i].fType);
++done;
}
}
if(0==done)
{
index = SendMessage(hlb,LB_ADDSTRING,0,(LPARAM)__T("(empty)"));
SendMessage(hlb,LB_SETITEMDATA,(WPARAM)index,(LPARAM)0);
}
}
}
void FillComboBox(HWND hwnd,const int idc, UINT filter)
{
HWND hcb = ::GetDlgItem(hwnd,idc);
int index,i,done;
ASSERT(IsWindow(hcb));
if(IsWindow(hcb))
{
SendMessage(hcb,CB_RESETCONTENT,0,0 );
for(done=i=0;i<numMessages;i++)
{
if(msginfo[i].fType & filter)
{
index = SendMessage(hcb,CB_ADDSTRING,0,(LPARAM)msginfo[i].pWmMsg);
SendMessage(hcb,CB_SETITEMDATA,(WPARAM)index,(LPARAM)msginfo[i].fType);
++done;
}
}
if(0==done)
{
index = SendMessage(hcb,CB_ADDSTRING,0,(LPARAM)__T("(empty)"));
SendMessage(hcb,CB_SETITEMDATA,(WPARAM)index,(LPARAM)0);
}
}
}
Good luck.