// JP opened flex table

Click to See Complete Forum and Search --> : Using resources and a list box.


bojo
January 13th, 2008, 09:25 AM
Howdy.

I've begun learning the winAPI in c/C++

My Problem is that i don't know how to populate a list box if it's made using resources?.

IDD_OPTIONS DIALOG DISCARDABLE 0, 0, 239, 66
STYLE DS_MODALFRAME | WS_POPUP | WS_CAPTION | WS_SYSMENU
CAPTION "Options"
FONT 8, "MS Sans Serif"
BEGIN
DEFPUSHBUTTON "&OK",IDOK,174,18,50,14
PUSHBUTTON "&Cancel",IDCANCEL,174,35,50,14
COMBOBOX IDC_COMPORTSELECT,25,16,48,30,CBS_DROPDOWNLIST | CBS_HASSTRINGS
END

Is part of the resource file.

The combo box appears in the dialogue box, but it is empty. Eventually i want to populate it with a list of the available comports on the PC. But for now if i can add in a string or two i will be happy.

but how would i do it?. I can't use sendmessage(..) because i don't know the handle of the combobox.


Also what is WM_KEYDOWN, is macro for keydown, what's the one for enter?. And how hard is it to get device information from device manager?, a list of available comports would be nice.

UnfitElf
January 13th, 2008, 08:20 PM
Hi Bojo,

To add items to a combo box you use the send message. You say you dont have the handle of the box. You should however have the handle of the dialog the combo box is in :)


// hDlg is the handle to the dialog the combo box is in.
HWND hCombo = GetDlgItem(hDlg, IDC_COMPORTSELECT);
SendMessage(hCombo, CB_ADDSTRING, 0, (LPARAM)"1");
SendMessage(hCombo, CB_ADDSTRING, 0, (LPARAM)"2");
SendMessage(hCombo, CB_ADDSTRING, 0, (LPARAM)"3");
SendMessage(hCombo, CB_ADDSTRING, 0, (LPARAM)"4");

// To make one of the added item the default pre selected option use the following line. nPort is a 0 based index of the items added above.
SendMessage(hCombo, CB_SETCURSEL, nPort, 0);


WM_KEYDOWN is a message that is sent to the dialog's message handler whenever a key is pressed. Take a look at the following link Click Here (http://msdn2.microsoft.com/en-us/library/ms646280(VS.85).aspx)

To check if enter was the key pressed you would go like this:

case WM_KEYDOWN:
if (wParam == VK_RETURN)
{
// Enter was pressed
}
break;


Hope this helps :)

bojo
January 14th, 2008, 04:23 AM
Hi unfitelf.

That looks great!!. I believe i was kinda in the dark about GetDlgItem(..)

I've also managed to work out the enter thing, thanks heaps mate.

//JP added flex table