Combo box

Started by
7 comments, last by Oxyd 19 years, 6 months ago
I have create a dialog with a combo box. How do I set the combo box options? and how do I read the option currently selected?
It's all about the wheel.Never blindly trust technoligy.I love my internal organs.Real men don't shower.Quote:Original post by Toolmaker Quote:Original post by The C modest godHow is my improoved signature?It sucks, just like you.
Advertisement
If you're using Win32, look up the CB_xxx messages.

CB_ADDSTRING will add an item to the list.

With CB_GETCURSEL you get the currently selected item.

If the Combo is editable you'd better use GetWindowText() to get the current item.

If MFC, it's AddString, and GetCurSel as member of the CComboBox class.

Fruny: Ftagn! Ia! Ia! std::time_put_byname! Mglui naflftagn std::codecvt eY'ha-nthlei!,char,mbstate_t>

Ok, I have done the following:
	DialogBox ( hThisInstance, ( LPCTSTR ) IDD_GRAPHICS, hWnd, ( DLGPROC ) MainWndProcGraphicsSetup );	PostMessage (hWnd, CB_ADDSTRING, 0, (LPARAM) (LPCTSTR)"Normal");	PostMessage (hWnd, CB_ADDSTRING, 0, (LPARAM) (LPCTSTR)"Hard");

It doesnt show these options I have added to the dialog box.
Perhaps I need an hWnd of the dialog box? how do I get the hWnd of the dialog box, if it has one...
It's all about the wheel.Never blindly trust technoligy.I love my internal organs.Real men don't shower.Quote:Original post by Toolmaker Quote:Original post by The C modest godHow is my improoved signature?It sucks, just like you.
Call GetDlgItem with the control ID to get its HWND.
"Most people think, great God will come from the sky, take away everything, and make everybody feel high" - Bob Marley
Quote:Original post by The C modest god
Ok, I have done the following:
	DialogBox ( hThisInstance, ( LPCTSTR ) IDD_GRAPHICS, hWnd, ( DLGPROC ) MainWndProcGraphicsSetup );	PostMessage (hWnd, CB_ADDSTRING, 0, (LPARAM) (LPCTSTR)"Normal");	PostMessage (hWnd, CB_ADDSTRING, 0, (LPARAM) (LPCTSTR)"Hard");



It doesnt show these options I have added to the dialog box.
Perhaps I need an hWnd of the dialog box? how do I get the hWnd of the dialog box, if it has one...


The problem with that snippet is that after DialogBox is finished, the dialog is gone already.

Put the CB_ADDSTRINGs in the MainWndProcGraphicsSetup when you get WM_INITDIALOG. And as Paradigm Shifter said, at that position use GetDlgItem to get the HWND of the combo box.

Sample code (inside MainWndProcGraphicsSetup ):

....case WM_INITDIALOG:{  HWND   hwndComboBox = GetDlgItem( hWnd, ID_OF_COMBOBOX );   SendMessage( hwndComboBox, CB_ADDSTRING, 0, (LPARAM)"Normal" );  SendMessage( hwndComboBox, CB_ADDSTRING, 0, (LPARAM)"Hard" );}return TRUE;

Fruny: Ftagn! Ia! Ia! std::time_put_byname! Mglui naflftagn std::codecvt eY'ha-nthlei!,char,mbstate_t>

Still doesnt work, here is what I am doing:
BOOL CALLBACK MainWndProcGraphicsSetup ( HWND Window, UINT uMsg, WPARAM wParam, LPARAM lParam ) {	HWND   hwndComboBox;	switch ( uMsg ) {		case WM_INITDIALOG: 			hwndComboBox = GetDlgItem( Window, IDC_COMBO1 );			SendMessage (hwndComboBox, CB_ADDSTRING, 0, (LPARAM)"Anti aliased (slower)");			SendMessage (hwndComboBox, CB_ADDSTRING, 0, (LPARAM)"Aliased (faster)");			return TRUE;
It's all about the wheel.Never blindly trust technoligy.I love my internal organs.Real men don't shower.Quote:Original post by Toolmaker Quote:Original post by The C modest godHow is my improoved signature?It sucks, just like you.
Which styles does the combo have? (Dropdown-List?)

Did you set the popup-height of the combo in the resource editor?
(In the editor, click on the down-button of the combobox; the selection rectangle should change appearance, adjust the height of the popup list here)

Also, per default nothing is being selected. The added items will only appear in the dropdown list. You can do that by sending CB_SETCURSEL.

Fruny: Ftagn! Ia! Ia! std::time_put_byname! Mglui naflftagn std::codecvt eY'ha-nthlei!,char,mbstate_t>

Quote:Original post by Endurion
Did you set the popup-height of the combo in the resource editor?

*g* that bitten me too, combos are shy maidens :)

Thermo
I did as you told and it works fine now.
Thanks for all the help.
It's all about the wheel.Never blindly trust technoligy.I love my internal organs.Real men don't shower.Quote:Original post by Toolmaker Quote:Original post by The C modest godHow is my improoved signature?It sucks, just like you.

This topic is closed to new replies.

Advertisement