Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

c++ win32 : adding values to ComboBox

Im sure this question is so easy for all you experts, but I am new to C++ and trying to add a comboBox to a "Option" Dialog in my program, I have done the following, but still can't see any item in Combo box can you please tell me what I am missing here.

in Resourse.h : #define IDD_TRIGGER_MODE 201

in Project.rc : COMBOBOX IDD_TRIGGER_MODE, 64,22,68,14,WS_TABSTOP | WS_VSCROLL | CBS_DROPDOWN

any in the .cpp file I have the folliwng codes :

LRESULT CALLBACK WndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam){
int wmId, wmEvent;
PAINTSTRUCT ps;
HDC hdc;

switch (message)
{
case WM_COMMAND:    
    ///Other codes///
        case IDM_OPTIONS:       

    g_hToolbar = CreateDialog(hInst, MAKEINTRESOURCE(IDD_OPTION_BOX), hWnd, ToolDlgProc);
    if(g_hToolbar != NULL)
    {
        ShowWindow(g_hToolbar, SW_SHOW);
    }        
        break;
    default:
        return DefWindowProc(hWnd, message, wParam, lParam);
    }
    break;
///Other codes///
}

the ToolDlgProc function :

INT_PTR CALLBACK ToolDlgProc(HWND hDlg, UINT message, WPARAM wParam, LPARAM lParam)
{
UNREFERENCED_PARAMETER(lParam);
 HWND fgModes;

switch (message)
{
case WM_INITDIALOG:
     fgModes = ::GetDlgItem(hDlg, IDD_TRIGGER_MODE);
  fgModes = GetDlgItem(hDlg, IDD_TRIGGER_MODE); 
     if(fgModes!=NULL){
     if(SendMessage(fgModes,CB_ADDSTRING,0, reinterpret_cast<LPARAM (_T("FreeRun")))==NULL){            
        return (INT_PTR)FALSE ;          
     }                  
    return (INT_PTR)TRUE;
     }

case WM_COMMAND:
    if (LOWORD(wParam) == IDOK || LOWORD(wParam) == IDCANCEL)
    {
        EndDialog(hDlg, LOWORD(wParam));
        return (INT_PTR)TRUE;
    }
    break;
}
return (INT_PTR)FALSE;
}

I appricate it for any idea to solve this problem, Thank you

like image 326
user261002 Avatar asked Apr 06 '12 18:04

user261002


2 Answers

thank you so much for your help. but I notice I didnt have problem in my code, simply the size of the ComboBox in .rc file was quite small (because of my lack of experiance in c++ API), so I change it to 42 now I can see my items. here is the edited code :

COMBOBOX IDD_TRIGGER_MODE, 64,22,69,42,WS_CHILD|WS_VISIBLE|CBS_DROPDOWNLIST

like image 126
user261002 Avatar answered Oct 18 '22 04:10

user261002


Change:

SendMessage(fgModes,CB_ADDSTRING,0, reinterpret_cast<LPARAM>("FreeRun"));

To:

SendMessage(fgModes,CB_ADDSTRING,0, reinterpret_cast<LPARAM>(_T("FreeRun")));

Also is there a good reason you are mixing CreateWindow/Ex and resources? I am assuming CreateWindow/Ex because I see you are using a WndProc for the first cpp, not a DialogProc.

like image 3
Mike Kwan Avatar answered Oct 18 '22 03:10

Mike Kwan