Aracılığıyla paylaş


List-View Resim Listeleri Eklemek

Bu konuda, liste görünümü denetimine görüntü listelerinin nasıl ekleneceği gösterilmektedir.

Yalnızca denetimin kullandığı görüntü listelerini oluşturursunuz. Örneğin, uygulamanız kullanıcının simge görünümüne geçmesine izin vermiyorsa büyük bir simge listesi oluşturmanız ve atamanız gerekmez. Hem büyük hem de küçük resim listeleri oluşturursanız, her iki görüntü listesinde de bir liste görünümü öğesinin simgesini tanımlamak için tek bir değer kullanıldığından, bunların aynı görüntüleri aynı sırada içermesi gerekir.

Bilmeniz gerekenler

Teknolojileri

Önkoşullar

  • C/C++
  • Windows Kullanıcı Arayüzü Programlama

Talimatlar

Öğe görüntülerini görüntülemek için, liste görünümü denetimine bir resim listesi atamanız gerekir. Bunu yapmak için, LVM_SETIMAGELIST iletisini veya ListView_SetImageListkarşılık gelen makroyu kullanarak resim listesinin tam boyutlu simgeler, küçük simgeler veya durum görüntüleri içerip içermediğini belirtin. Bir liste görünümü denetimine şu anda atanmış olan bir görüntü listesinin tanıtıcısını almak için LVM_GETIMAGELIST iletisini kullanın. GetSystemMetrics işlevini kullanarak tam boyutlu ve küçük simgeler için uygun boyutları belirleyebilirsiniz.

Aşağıdaki C++ kod örneğinde, uygulama tanımlı işlev önce görüntü listeleri oluşturur ve sonra bunları liste görünümü denetimine atar.

// InitListViewImageLists: Creates image lists for a list-view control.
// This function only creates image lists. It does not insert the items into
// the control, which is necessary for the control to be visible.   
//
// Returns TRUE if successful, or FALSE otherwise. 
//
// hWndListView: Handle to the list-view control. 
// global variable g_hInst: The handle to the module of either a 
// dynamic-link library (DLL) or executable (.exe) that contains
// the image to be loaded. If loading a standard or system
// icon, set g_hInst to NULL.
//
BOOL InitListViewImageLists(HWND hWndListView) 
{ 
    HICON hiconItem;     // Icon for list-view items.
    HIMAGELIST hLarge;   // Image list for icon view.
    HIMAGELIST hSmall;   // Image list for other views.

    // Create the full-sized icon image lists. 
    hLarge = ImageList_Create(GetSystemMetrics(SM_CXICON), 
                              GetSystemMetrics(SM_CYICON), 
                              ILC_MASK, 1, 1); 

    hSmall = ImageList_Create(GetSystemMetrics(SM_CXSMICON), 
                              GetSystemMetrics(SM_CYSMICON), 
                              ILC_MASK, 1, 1); 
    
    // Add an icon to each image list.  
    hiconItem = LoadIcon(g_hInst, MAKEINTRESOURCE(IDI_ITEM));

    ImageList_AddIcon(hLarge, hiconItem);
    ImageList_AddIcon(hSmall, hiconItem);

    DestroyIcon(hiconItem);
 
// When you are dealing with multiple icons, you can use the previous four lines of 
// code inside a loop. The following code shows such a loop. The 
// icons are defined in the application's header file as resources, which 
// are numbered consecutively starting with IDS_FIRSTICON. The number of 
// icons is defined in the header file as C_ICONS.
/*    
    for(index = 0; index < C_ICONS; index++)
    {
        hIconItem = LoadIcon (g_hinst, MAKEINTRESOURCE(IDS_FIRSTICON + index));
        ImageList_AddIcon(hSmall, hIconItem);
        ImageList_AddIcon(hLarge, hIconItem);
        Destroy(hIconItem);
    }
*/
    
    // Assign the image lists to the list-view control. 
    ListView_SetImageList(hWndListView, hLarge, LVSIL_NORMAL); 
    ListView_SetImageList(hWndListView, hSmall, LVSIL_SMALL); 
    
    return TRUE; 
}

List-View Kontrol Referansı

Denetimler hakkında List-View

List-View Denetimlerini Kullanma