Combo box
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?
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.
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.
Ok, I have done the following:
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...
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...
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;
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;
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.
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.
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
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement