Thread: Resizing Combo Box When Adding items to it

Threaded View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Registered User
    Join Date
    Jan 2010
    Posts
    209

    Question Resizing Combo Box When Adding items to it

    Hi there,

    I'll cut to the chase...I've made a combo box in the little Help->About Menu dialog box that appears as standard on the menu bar.

    Here's the code:

    Code:
    INT_PTR CALLBACK About(HWND hDlg, UINT message, WPARAM wParam, LPARAM lParam)
    {    
        const wchar_t* colour[4]
            = { L"Blue", L"Red", L"Orange", L"Yellow" };
    
        WPARAM nI;
    
        for (int i = 0; i < 4; i++)
        {
            nI = SendMessageW(GetDlgItem(hDlg, 1003), (UINT) CB_ADDSTRING, 0, (LPARAM)colour[i]);
        }
    
    ....etc (rest of message handling function)
    
        switch (message)
        {
        case WM_INITDIALOG:        
    
    ..... and so on
    This is the bit we're interested in:

    Code:
    const wchar_t* colour[4]
            = { L"Blue", L"Red", L"Orange", L"Yellow" };
    
        WPARAM nI;
    
        for (int i = 0; i < 4; i++)
        {
            nI = SendMessageW(GetDlgItem(hDlg, 1003), (UINT) CB_ADDSTRING, 0, (LPARAM)colour[i]);
        }
    All works. Actually looks quite nice too:

    Resizing Combo Box When Adding items to it-combo-box-jpg

    Only trouble is for a long while the bottom 3 strings were not showing. Only the first entry 'Blue' was shown. To fix this I had to MANUALLY change the height setting in the resource file where the Combo Box layout and flags are defined.

    Sometimes if working with DirectX for example when you're querying an adapter list and the resultant display modes/resolutions etc... there's no way to know how long the list of entries you need for the Combo Box is going to be. Thus surely one needs a way to dynamically resize the box when adding new entries.

    I don't know what this is though. I could try messing around in the settings in Visual Studio again but I thought it better to ask here first.

    Thanks

    Edit: Should also add that the 1003 in the GetDlgItem(hDlg, 1003) call equates to the identifier for the combo box.
    Last edited by shrink_tubing; 10-01-2023 at 10:30 PM.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Adding items to a Dialog Box
    By shrink_tubing in forum C++ Programming
    Replies: 2
    Last Post: 09-21-2022, 08:17 AM
  2. adding font to a combo box
    By supernater in forum Windows Programming
    Replies: 1
    Last Post: 03-13-2009, 06:11 AM
  3. adding font to a list box or combo box
    By supernater in forum Windows Programming
    Replies: 2
    Last Post: 03-13-2009, 05:53 AM
  4. Create new combo boxes based on items selected in preview combo box
    By RealityFusion in forum Windows Programming
    Replies: 2
    Last Post: 01-10-2007, 09:50 AM
  5. Adding Items to Combo Boxes
    By tenthirty in forum Windows Programming
    Replies: 10
    Last Post: 12-21-2001, 02:37 AM

Tags for this Thread