Notes
L’accès à cette page nécessite une autorisation. Vous pouvez essayer de vous connecter ou de modifier des répertoires.
L’accès à cette page nécessite une autorisation. Vous pouvez essayer de modifier des répertoires.
Cette rubrique montre comment utiliser la fonction ImageList_Create pour créer une liste d’images.
Bon à savoir
Technologies
Prérequis
- C/C++
- Programmation de l’interface utilisateur Windows
Instructions
Vous créez une liste d’images en appelant la fonction ImageList_Create . Les paramètres incluent le type de liste d’images à créer, les dimensions de chaque image et le nombre d’images que vous envisagez d’ajouter à la liste.
L’exemple suivant crée une liste d’images masquées et utilise la macro ImageList_AddIcon pour ajouter deux icônes à la liste.
// AddIconsToImageList - creates a masked image list and adds some
// icons to it.
// Returns the handle to the new image list.
// hinst - handle to the application instance.
//
// Global variables and constants
// g_nBird and g_nTree - indexes of the images.
// cx_icon and cy_icon - width and height of the icon.
// num_icons - number of icons to add to the image list.
extern int g_nBird, g_nTree;
#define CX_ICON 32
#define CY_ICON 32
#define NUM_ICONS 3
HIMAGELIST AddIconsToImageList(HINSTANCE hinst)
{
HIMAGELIST himlIcons; // handle to new image list
HICON hicon; // handle to icon
// Ensure that the common control DLL is loaded.
InitCommonControls();
// Create a masked image list large enough to hold the icons.
himlIcons = ImageList_Create(CX_ICON, CY_ICON, ILC_MASK, NUM_ICONS, 0);
// Load the icon resources, and add the icons to the image list.
hicon = LoadIcon(hinst, MAKEINTRESOURCE(IDI_BIRD));
g_nBird = ImageList_AddIcon(himlIcons, hicon);
hicon = LoadIcon(hinst, MAKEINTRESOURCE(IDI_TREE));
g_nTree = ImageList_AddIcon(himlIcons, hicon);
return himlIcons;
}
Rubriques connexes