Game Programming and Development Tools

ComboBox for Windows – gingerellies

gingerellies

Member

Posts: 50
From: Orlando, FL
Registered: 05-28-2002
Can anyone help me, I need to make a comboboz for a tool I am making. It will be similar to a tile editor, but more specific to our needs. Anyway, I have been all over MSDN and I can't seem to get the info I need. I really just want a dropdown box with some choices in it, I don't need the user to be able to add items to the list, but I guess it would be ok if I have to have that option. I am using C++ to program a WIN32 App. I am using Visual C++ 6.0. I hope that's all the info you need, if it wasn't clear just let me know and I will clearify. Thanks!

------------------
God bless and keep you!
-Ginger

rowanseymour

Member

Posts: 284
From: Belfast, Northern Ireland
Registered: 02-10-2001
Is this for dialog box or toolbar ? Are you using MFC or straight Win32 controls ?

1. Use the resource editor to create the dialog box
2. Draw a combo box control where you want it
3. Give it a control name

If using MFC you will access the combo box with something like:

CComboBox* pCB = (CComboBox*)pDlg->GetDlgItem(IDC_MYCOMBOBOX);
pCB->AddString("Item #1");
pCB->AddString("Item #2");

(where IDC_MYCOMBOBOX is the control name you gave it and pDlg is a pointer to your MFC dialog box)

If using the Win32 API you will access the combo box with something like:

SendDlgItemMessage(hWnd, IDC_MYCOMBOBOX, CB_ADDSTRING, 0, (LPARAM)"Item #1");

(where IDC_MYCOMBOBOX is the control name you gave it and hWnd is the handle to your dialog box)

Hope this helps !

------------------
Rowan / GODCENTRIC Christian Demoscene

gingerellies

Member

Posts: 50
From: Orlando, FL
Registered: 05-28-2002
It is for dialog box with straight win32. Yes, that was very helpful! Do I make a call like that for every item in the list, and how do I control what happens when the click on one, or how do I know they even clicked on one?

------------------
God bless and keep you!
-Ginger

rowanseymour

Member

Posts: 284
From: Belfast, Northern Ireland
Registered: 02-10-2001
From memory i think you'll want something like this in your dialog procedure...

int CALLBACK DialogProc(HWND hWndDlg, UINT uMsg, WPARAM wParam, LPARAM lParam)
{
switch (uMsg) {
case WM_INITDIALOG:
/* Initialize dialog box */
return 1;
case WM_COMMAND: {
int nCmd = LOWORD(wParam);
switch (nCmd) {
case IDOK:
/* User pressed OK */
break;
case IDCANCEL:
/* User pressed Cancel */
break;
case IDC_MYCOMBOBOX:
int nNMsg = HIWORD(wParam);
switch (nNMsg) {
case CBN_SELCHANGE:
/* User changed combo box selection */
break;
case CBN_CLOSEUP:
/* User closed the list box part of the combo box */
break;
}
break;
}
return 1;
}
}

return 0;
}

Check out the MSDN stuff on combo boxes, you'll find a list their of all the notification messages sent by combo box controls and how to handle them.
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/shellcc/platform/CommCtls/comboboxes/specialcomboboxfeatures.asp?frame=true#combo_notifications

Good luck !

------------------
Rowan / GODCENTRIC Christian Demoscene

gingerellies

Member

Posts: 50
From: Orlando, FL
Registered: 05-28-2002
ok, I think I've got it working, except, when I push the dropdown button thingy (technical term ) It doesn't drop down. It shows a black line, I can even change the length of this black line, but it should be just a black line, it should be my dropdown box. Any ideas on that? If you can understand it .

------------------
God bless and keep you!
-Ginger

rowanseymour

Member

Posts: 284
From: Belfast, Northern Ireland
Registered: 02-10-2001
You need to increase the height of the combobox on the dialog. I recall there is some problem with resource editor not letting you increase it more than than one text line high, but you can edit it in the RC file

Find the following line in your .RC file where IDC_MYCOMBOBOX is the name of your combobox. The 4th number is the height - make sure this is set to at least 60 or 70.

COMBOBOX IDC_MYCOMBOBOX,10,10,200,70,CBS_DROPDOWNLIST | WS_VSCROLL | WS_TABSTOP,WS_EX_TRANSPARENT

------------------
Rowan / GODCENTRIC Christian Demoscene

gingerellies

Member

Posts: 50
From: Orlando, FL
Registered: 05-28-2002
THANK YOU, THANK YOU, THANK YOU!!! That was extremely helpful! That was the problem! You are a gem! It works great now! I owe ya!

------------------
God bless and keep you!
-Ginger