Sign in to follow this  

Combo box

This topic is 4825 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

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.

Share this post


Link to post
Share on other sites
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...

Share this post


Link to post
Share on other sites
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;

Share this post


Link to post
Share on other sites
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;

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites

This topic is 4825 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this