Populating a combobox

This is a discussion on Populating a combobox within the Windows Programming forums, part of the Platform Specific Boards category; Hi everyone, I am trying to populate a combobox IDD_OFFSET_CBO that I have created in the .rc file with the ...

  1. #1
    Registered User
    Join Date
    Feb 2010
    Posts
    128

    Populating a combobox

    Hi everyone,

    I am trying to populate a combobox IDD_OFFSET_CBO that I have created in the .rc file with the following code:

    Code:
    #include <windows.h>
    #include <string>
    #include <math.h>
    #include <conio.h>
    #include <cmath>
    #include <cstdio>
    #include "resource.h"
    
    BOOL CALLBACK ToolDlgProc(HWND hwnd, UINT Message, WPARAM wParam, LPARAM lParam)
    {
    	    HWND cboOffset;
    
    		const char *Offsets[] = { "+12", "+11", "+10", "+9", "+8", "+7", "+6", "+5", "+4", "+3", "+2", "+1", "0", "-1", "-2", "-3", "-4", "-5", "-6", "-7", "-8", "-9", "-10", "-11", "-12", };
    
    	switch(Message)
    	{
    
    	case WM_INITDIALOG:
    
    		cboOffset = GetDlgItem(hwnd, IDD_OFFSET_CBO);
    
    	for(int Count = 0; Count < 25; Count++)
            {
            SendMessage(cboOffset, CB_ADDSTRING, 0, (LPARAM)Offsets[Count]);
            }
        return TRUE;
    
    	case WM_COMMAND:
    		switch(LOWORD(wParam))
    		{
    
    		case IDC_EXIT:
    			EndDialog(hwnd, 0);
    		    break;
    
    		}
    		break;
    
    		case WM_CLOSE:
    			EndDialog(hwnd, 0);
    		    break;
    
    		default:
    			return FALSE;
    	}
    	return TRUE;
    }
    
    int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nCmdShow)
    {
    	return DialogBox(hInstance, MAKEINTRESOURCE(IDD_WINDOW), NULL, ToolDlgProc);
    }
    However, when the window opens, the combobox always remains empty. Can anyone tell me where I'm going wrong please?

    Thanks!

  2. #2
    Registered User
    Join Date
    Feb 2010
    Posts
    128
    I've got it - the dimensions in the .rc file were too small - it seems fixed now.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Populating 2-D arrays
    By fgg in forum C Programming
    Replies: 4
    Last Post: 10-13-2010, 12:39 PM
  2. Populating a Struct
    By larry_2k4 in forum C Programming
    Replies: 4
    Last Post: 10-21-2009, 09:27 PM
  3. populating arrays
    By jafa401 in forum C Programming
    Replies: 12
    Last Post: 08-04-2009, 11:22 PM
  4. populating matrices
    By jamiec_86 in forum C Programming
    Replies: 4
    Last Post: 04-04-2008, 06:36 AM
  5. populating arrays
    By john_murphy69 in forum C Programming
    Replies: 7
    Last Post: 04-04-2003, 11:03 AM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21