CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 3 of 3
  1. #1
    Join Date
    May 2009
    Posts
    23

    add listbox to toolbar

    Hi there. I've created a toolbar using the method shown below...

    Code:
    HWND CreateSimpleToolbar(HWND hWndParent)
    {
        // Define some constants.
        const int ImageListID = 0;
        const int numButtons = 3;
        const DWORD buttonStyles = BTNS_AUTOSIZE;
        const int bitmapSize = 16;
    
        // Create the toolbar.
        HWND hWndToolbar = CreateWindowEx(0, TOOLBARCLASSNAME, NULL, 
            WS_CHILD | TBSTYLE_WRAPABLE,
            0, 0, 0, 0,
            hWndParent, NULL, g_hInst, NULL);
        if (hWndToolbar == NULL)
        {
            return NULL;
        }
    
        // Create the imagelist.
        HIMAGELIST hImageList = ImageList_Create(
            bitmapSize, bitmapSize,   // Dimensions of individual bitmaps.
            ILC_COLOR16 | ILC_MASK,   // Ensures transparent background.
            numButtons, 0);
    
        // Set the image list.
        SendMessage(hWndToolbar, TB_SETIMAGELIST, (WPARAM)ImageListID, 
            (LPARAM)hImageList);
    
        // Load the button images.
        SendMessage(hWndToolbar, TB_LOADIMAGES, (WPARAM)IDB_STD_SMALL_COLOR, 
            (LPARAM)HINST_COMMCTRL);
    
        // Initialize button info.
        TBBUTTON tbButtons[numButtons] = 
        {
            { MAKELONG(STD_CUT, ImageListID), IDM_CUT, TBSTATE_ENABLED, 
              buttonStyles, {0}, 0, (INT_PTR)L"New" },
            { MAKELONG(STD_COPY, ImageListID), IDM_COPY, TBSTATE_ENABLED, 
              buttonStyles, {0}, 0, (INT_PTR)L"Open"},
            { MAKELONG(STD_PASTE, ImageListID), IDM_PASTE, 0, 
              buttonStyles, {0}, 0, (INT_PTR)L"Save"}
        };
    
        // Add buttons.
        SendMessage(hWndToolbar, TB_BUTTONSTRUCTSIZE, 
            (WPARAM)sizeof(TBBUTTON), 0);
        SendMessage(hWndToolbar, TB_ADDBUTTONS, (WPARAM)numButtons, 
            (LPARAM)&tbButtons);
    
        // Tell the toolbar to resize itself, and show it.
        SendMessage(hWndToolbar, TB_AUTOSIZE, 0, 0); 
        ShowWindow(hWndToolbar, TRUE);
        return hWndToolbar;
    }
    I would like to add a listbox to the toolbar but I would like to place it between the 2nd and third button (the copy and paste button). How do I do this?

    Is there anyway to insert a listbox into the TBBUTTON? Or do I have to make two TBBUTTONs? In other words, should I make one TBBUTTON containing the first two buttons (cut and copy), position it. Make the Listbox, position it. Then make a second TBBUTTON containing the third button (paste button) and position it on the other side of the listbox.

  2. #2
    Join Date
    Dec 2008
    Posts
    114

    Re: add listbox to toolbar

    There are several known methods (see Win32 group) for code (C)

  3. #3
    Join Date
    Nov 2007
    Posts
    613

    Re: add listbox to toolbar

    A toolbar can only hold buttons. Use a dialog bar.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured