Image list overview
Image list as the name suggest is a container to hold an array of images that can be used in other controls in the application. Image list is not an independent GUI element like button or textbox which user can interact with. Rather image list is maily an invisible control and used indirectly in the toolbars, list or tree controls. Image list generally holds a group of icons, bitmaps or images for the use of other controls. We see toolbars have new, open, save buttions or Windows explorer has icons for files and folders. All these icons are loaded in an image list then they are used. Toolbars, Tree and list control have APIs to associate an image list to itself. Later those controls directly uses the images from the list control.
Image list library calls
Windows common control controls library provides a collection of APIs for verious controls including Image list. ImageList_Create is the API to create the image list. Developers then need to add images to the list. ImageList_Add API is generally used for this purpose. This image list can be used to display verious icons and images in list view or tree view. SetImageList is the API to associate the image list object to the list view or tree view.
ImageList APIs
Here is the full list of ImageList utility APIs. Each API does a certain operation on the image list. Opertion name is appended with API nameand thus developer can easily choose the APIs to be used in their application. MSDN has full documentation on these APIs.
ImageList_Add ImageList_AddMasked ImageList_BeginDrag ImageList_CoCreateInstance ImageList_Copy ImageList_Create ImageList_Destroy ImageList_DragEnter ImageList_DragLeave ImageList_DragMove ImageList_DragShowNolock ImageList_Draw ImageList_DrawEx ImageList_DrawIndirect ImageList_Duplicate ImageList_EndDrag ImageList_GetBkColor ImageList_GetDragImage ImageList_GetIcon ImageList_GetIconSize ImageList_GetImageCount ImageList_GetImageInfo ImageList_LoadImage ImageList_Merge ImageList_Read ImageList_ReadEx ImageList_Remove ImageList_Replace ImageList_ReplaceIcon ImageList_SetBkColor ImageList_SetColorTable ImageList_SetDragCursorImage ImageList_SetIconSize ImageList_SetImageCount ImageList_SetOverlayImage ImageList_Write ImageList_WriteEx
ImageList Example
HIMAGELIST hLarge; HIMAGELIST hSmall; void CreateImageList(void) { HICON hiconItem; HMODULE hDll; // Create the full-sized icon image lists. hLarge = ImageList_Create(GetSystemMetrics(SM_CXICON), GetSystemMetrics(SM_CYICON), ILC_COLOR32|ILC_MASK, 1, 1); hSmall = ImageList_Create(GetSystemMetrics(SM_CXSMICON), GetSystemMetrics(SM_CYSMICON), ILC_COLOR32|ILC_MASK, 1, 1); hDll = LoadLibrary ( "SHELL32.dll" ); // Add an icon to each image list. hiconItem = LoadIcon (hDll , MAKEINTRESOURCE ( 3)); ImageList_AddIcon(hLarge, hiconItem); ImageList_AddIcon(hSmall, hiconItem); } void SetImageList(HWND hWndListView) { ListView_SetImageList(hWndListView, hLarge, LVSIL_NORMAL); ListView_SetImageList(hWndListView, hSmall, LVSIL_SMALL); } void DestroyImageList(void) { ImageList_Destroy(hLarge); ImageList_Destroy(hSmall); }
About our authors: Team EQA
Further readings
Where is WinMain() function in MFC application ?
MFC hides WinMain in its framework and includes source file on WinMain(). This explains how framework calls global CWinApp::Initinstance() from entry WinMain.
What is the utility of CWinApp class?
This is constructed during global C++ objects are constructed and is already available when Windows calls the WinMain function, which is supplied by the ...
Basic steps in Win32 GUI Application with source code.
Define a custom Window class structure, Register the class name, CreateWindow, Show windows and write message get and dispatch loop statements. Define the Window CallBack procedure and write the handlers.
What is a Window CallBack procedure and what is its utility?
DispatchMessage() is a API which indirectly triggers the Window CallBack procedure. Message structure members from this function are passed to the CallBack procedure. CallBack procedure should implement event handlers depending on the need of the application.
What are LPARAM and WPARAM in window proc function?
LPARAM and WPARAM are the two parameters in Window CallBack procedure. They signifies parameters of various events. They are used in handing individual events.
What are the basic steps of a typical MFC based application?
We need to write WinMain and need to follow all these in a Win32 application. However we need not to write much if we are writing an application with MFC ...