You can quickly set the size of the thumbnails in the list view, and there are no restrictions on the size!!This example demonstrates using the CreateNewImageList function to create an ImageList and associate it with a ListView control. You can then add images to the ImageList and display them in the ListView control. Please note that creating and sharing the image list, as well as adding images, is not fully implemented in this example; you will need additional functions and steps in your application. // This function creates a new Imagelist // and associates it with a Listview control (m_hWnd). HIMAGELIST CreateNewImageList(HWND m_hWnd, int cx, int cy) { // Set flags for configuring the Imagelist. UINT uFlags = ILC_COLOR32 | ILC_MASK; // Number of images in the Imagelist. int cImages = 1; // Create the Imagelist with // the specified width (cx) and height (cy) for the images. HIMAGELIST m_hImageList = ImageList_Create(cx, cy, uFlags, cImages, 1); // Associate the created Imagelist // with the Listview control (m_hWnd). // The constant LVM_SETIMAGELIST // is used to establish the linkage. SendMessage(m_hWnd, LVM_SETIMAGELIST, 0, (LPARAM)m_hImageList); // Return the created Imagelist. return m_hImageList; } LRESULT CALLBACK WindowProc(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam) { switch (uMsg) { case WM_CREATE: // Create the Listview control. HWND listViewHandle = CreateWindowEx(0, WC_LISTVIEW, L"", WS_VISIBLE | WS_CHILD | LVS_ICON, 0, 0, 200, 200, hWnd, NULL, GetModuleHandle(NULL), NULL); // Call the CreateNewImageList function to create an Imagelist // and associate it with the Listview control. HIMAGELIST imageList = CreateNewImageList(listViewHandle, 16, 16); if (imageList != NULL) { // Here, you can use the // created Imagelist to add and display images. // After you finish working with// // the Imagelist, you should release it // to avoid memory leaks. // This is not fully implemented in this example. // An example of adding images: // ImageList_Add(imageList, hBitmap, NULL); } break; case WM_DESTROY: PostQuitMessage(0); return 0; default: return DefWindowProc(hWnd, uMsg, wParam, lParam); } return 0; } int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nCmdShow) { WNDCLASS wc = { 0 }; wc.lpfnWndProc = WindowProc; wc.hInstance = hInstance; wc.lpszClassName = L"MyWindowClass"; if (!RegisterClass(&wc))return -1; HWND hWnd = CreateWindow(L"MyWindowClass", L"My Window", WS_OVERLAPPEDWINDOW, 100, 100, 400, 400, NULL, NULL, hInstance, NULL); if (!hWnd) { return -1; } ShowWindow(hWnd, nCmdShow); MSG msg = { 0 }; while (GetMessage(&msg, NULL, 0, 0)) { TranslateMessage(&msg); DispatchMessage(&msg); } return 0; } FAQ 8: Updated on: 1 November 2023 13:50 |