toolbar button question

This is a discussion on toolbar button question within the Windows Programming forums, part of the Platform Specific Boards category; I am adding buttons to a toolbar using this code... Code: void CreateToolBar(HWND hwnd) { // Define some constants. const ...

  1. #1
    Registered User
    Join Date
    Mar 2009
    Posts
    8

    toolbar button question

    I am adding buttons to a toolbar using this code...

    Code:
    void CreateToolBar(HWND hwnd)
    {
        // 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,
            hwnd, NULL, (HINSTANCE)GetWindowLong( hwnd, GWL_HINSTANCE), NULL);
        if (hWndToolbar == NULL)
        {
    		MessageBoxW( hwnd, L"Toolbar not created", NULL, MB_OK );	 //Check return value of status bar to make sure it's been created
    		return;
        }
    
        // 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.
        // IDM_NEW, IDM_OPEN, and IDM_SAVE are application-defined command constants, they can be found in "dnater.h".
    	TBBUTTON tbButtons[numButtons] = 
        {
            { MAKELONG(STD_FILENEW, ImageListID), ID_FILE_NEW, TBSTATE_ENABLED, 
              buttonStyles, {0}, 0, NULL },
            { MAKELONG(STD_FILEOPEN, ImageListID), ID_FILE_OPEN, TBSTATE_ENABLED, 
              buttonStyles, {0}, 0, NULL },
            { MAKELONG(STD_FILESAVE, ImageListID), ID_FILE_SAVE, 0, 
              buttonStyles, {0}, 0, NULL }
        };
    
        // 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;
    }
    The problem is that the buttons are positioned exactly on the left edge of the window. Is there any way to specify the exact position of the buttons on the toolbar? I'd like the buttons to be positioned 100 px away from the left side of the toolbar.

  2. #2
    'Allo, 'Allo, Allo
    Join Date
    Apr 2008
    Posts
    611

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Replies: 2
    Last Post: 06-28-2008, 08:30 PM
  2. button question
    By Rare177 in forum C# Programming
    Replies: 2
    Last Post: 01-05-2007, 09:59 AM
  3. Disable button on toolbar - MFC
    By bennyandthejets in forum Windows Programming
    Replies: 0
    Last Post: 05-10-2004, 03:31 AM
  4. What toolbar editor do you use?
    By _Elixia_ in forum Windows Programming
    Replies: 1
    Last Post: 08-09-2003, 04:57 AM
  5. Disabling "X" button on Window
    By Boomba in forum Windows Programming
    Replies: 3
    Last Post: 06-14-2003, 01:53 PM

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