Visualizzazione dei risultati da 1 a 2 su 2
  1. #1
    Utente di HTML.it
    Registrato dal
    Oct 2007
    Messaggi
    216

    [C++ API Win32] problema creazione toolbar

    Ciao, ho un'applicazione in cui voglio inserire una toolbar.
    Questo è il codice della funzione che crea una toolbar:
    codice:
    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.
        // IDM_NEW, IDM_OPEN, and IDM_SAVE are application-defined command constants.
        TBBUTTON tbButtons[numButtons] = 
        {
            { MAKELONG(STD_FILENEW, ImageListID), IDM_NEW, TBSTATE_ENABLED, 
              buttonStyles, {0}, 0, (INT_PTR)L"New" },
            { MAKELONG(STD_FILEOPEN, ImageListID), IDM_OPEN, TBSTATE_ENABLED, 
              buttonStyles, {0}, 0, (INT_PTR)L"Open"},
            { MAKELONG(STD_FILESAVE, ImageListID), IDM_SAVE, 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;
    }
    Questa funzione crea una toolbar con le immagini dei pulsanti predefinite, come faccio
    se voglio inserire le immagini dei pulsanti che voglio io? Grazie.

  2. #2
    Devi usare il metodo Add, la cui documentazione è qui:

    http://msdn.microsoft.com/en-us/libr...12(VS.85).aspx


    Ciao

Permessi di invio

  • Non puoi inserire discussioni
  • Non puoi inserire repliche
  • Non puoi inserire allegati
  • Non puoi modificare i tuoi messaggi
  •  
Powered by vBulletin® Version 4.2.1
Copyright © 2024 vBulletin Solutions, Inc. All rights reserved.