Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

populating combo box

Status
Not open for further replies.

foxnet

Programmer
Mar 24, 2005
21
US
I am trying to create a win32 application with a menu bar on the main window. This menu bar has an option to open a dialog box with list boxes. I am trying to fill these list boxes by usuing the "LB_ADDSTRING" message. However when I click on the list box to drop down the list, none of the items are listed.


My main menu bar has three options; "About", "Settings" and "Exit". The WM_COMMAND for the main window is listed below.

case WM_COMMAND:
WORD idControl = LOWORD(wParam);
HWND hwndCtl = (HWND) lParam;
switch(idControl) {
case IDD_FILE:
DialogBox(g_hInst,
MAKEINTRESOURCE(IDD_ABOUT), hwnd,
(DLGPROC)extradlg);
break;
case IDD_SET:
g_hwndODlg = CreateDialog(g_hInst,
MAKEINTRESOURCE(IDD_SETTINGS), hwnd,
(DLGPROC)optdlg);
ShowWindow(g_hwndODlg, SW_SHOW);
break;
case ID_EXIT:
break;
}
return(0);


All these options appear to be working fine. When the Settings option (IDD_SETTINGS) is chosen a new dialog window is display with the combo boxes I am trying to fill. The procedure I am using to fill these boxes is:

BOOL CALLBACK optdlg(HWND hwndDlg, UINT uMsg,
WPARAM wParam, LPARAM lParam )
{
int retstat;
HWND hListWnd;

switch(uMsg) {
case WM_INITDIALOG:
hListWnd = GetDlgItem(hwndDlg,IDC_LISTBOX);
SendMessage(hListWnd, LB_ADDSTRING, 0,
(LPARAM)"Item 1");
SendMessage(hListWnd, LB_ADDSTRING, 0,
(LPARAM)"Item 2");
SendMessage(hListWnd, LB_ADDSTRING, 0,
(LPARAM)"Item 3");
SetFocus(GetDlgItem(hwndDlg, IDC_LISTBOX));
return(false);
case WM_COMMAND:
WORD idControl = LOWORD(wParam);
HWND hwndCtl = (HWND) lParam;
switch(idControl) {
case IDOK:
EndDialog(hwndDlg, IDOK);
return(true);
case IDCANCEL:
DestroyWindow(g_hwndODlg);
g_hwndODlg = NULL;
return(true);
}
return (false);
}
return(false);
}

Thanks for any help you can provide.


 
you should have tagged this on to your first question, it is the same topic I believe?

What do you get when you set and/or get the value from the combo box?
 
on my first question I tried using the app wizard which made everything with classes. I didn't understand how to read the code it made so I switch to the win32 application and made the main function an APIENTRY WinMain. I haven't tried to set a value to the combobox yet. I have only tried to populate the list and setfocus. The setfocus appears to work.
Thanks
 
when you set focus can you scroll through the list using the up/down arrows? Can you see the item in the list?
 
When I set focus, the box turns blue, but when I click the arrow to drop down the list, the entire box is blank. I do have a list box and I can scroll through those entries, which I have added through LB_ADDSTRING. It is just the drop down combo I cannot get working.

Is it OK to add the SendMessage commands in the WM_INITDIALOG case ?

Thanks
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top