OldSchoolCode

.com



Combo Box
Drag a "Combo Box" from your tool box over to your dialog box.

A combo box allows the user to select a name from the drop down list OR enter a name if the name isn't already populated in the list :)

__________________________________________________________
#include <stdio.h>
#include <windows.h>
#include "resource.h"

INT_PTR CALLBACK DialogMessages(HWND hwnd,UINT 
                                uMsg,WPARAM wparam,LPARAM lparam)
{
    if( uMsg == WM_INITDIALOG )
    {
        //this will populate our combo box
        //with the name we supplied
        //Use your help files and look up
        //SendDlgItemMessage
        SendDlgItemMessage(hwnd, IDC_COMBO1, CB_ADDSTRING, 0,(LPARAM)"Karen");
        SendDlgItemMessage(hwnd, IDC_COMBO1, CB_ADDSTRING, 0,(LPARAM)"Amy");
        SendDlgItemMessage(hwnd, IDC_COMBO1, CB_ADDSTRING, 0,(LPARAM)"Krisha");
    }

    if ( uMsg == WM_COMMAND )
    {
        if ( HIWORD(wparam) == BN_CLICKED )
        {
            if (LOWORD(wparam) == IDOK)
            {
                char name [260];
				
                //get the name from our combo
                //box. I used the default name "IDC_COMBO1"	
                GetDlgItemText( hwnd, IDC_COMBO1, name, 260 );
                
                //display a message box showing
                //the name selected ( or entered )
                MessageBox( NULL,name, "messagebox", 
                            MB_OK|MB_ICONEXCLAMATION  );

                EndDialog( hwnd, 0 );
                return TRUE;
            }

            else if (LOWORD(wparam) == IDCANCEL)
            {
                EndDialog( hwnd, 0 );
                return TRUE;
            }
        }
    }

return FALSE;
}

int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE 
                            hPrevInstance, LPSTR pCmdLine, int iCmdShow)
{
    DialogBox(GetModuleHandle(NULL), MAKEINTRESOURCE(IDD_MYDIALOG), 
                                            NULL, DialogMessages);
	
    return 0;
}