Catatan
Akses ke halaman ini memerlukan otorisasi. Anda dapat mencoba masuk atau mengubah direktori.
Akses ke halaman ini memerlukan otorisasi. Anda dapat mencoba mengubah direktori.
Setiap item dalam kontrol tampilan pohon dapat memiliki dua gambar yang terkait dengannya. Item menampilkan satu gambar saat dipilih dan yang lainnya saat tidak dipilih. Untuk menyertakan gambar dengan item tampilan pohon, pertama-tama gunakan fungsi Daftar Gambar untuk membuat daftar gambar dan menambahkan gambar ke dalamnya. Kemudian kaitkan daftar gambar dengan kontrol tampilan pohon dengan menggunakan pesan TVM_SETIMAGELIST.
Apa yang perlu Anda ketahui
Teknologi
Prasyarat
- C/C++
- Pemrograman Antarmuka Pengguna Windows
Peraturan
Menginisialisasi Daftar Gambar
Contoh berikut membuat daftar gambar, menambahkan tiga bitmap ke daftar, dan mengaitkan daftar gambar dengan kontrol tampilan pohon.
// InitTreeViewImageLists - creates an image list, adds three bitmaps
// to it, and associates the image list with a tree-view control.
// Returns TRUE if successful, or FALSE otherwise.
// hwndTV - handle to the tree-view control.
//
// Global variables and constants:
// g_hInst - the global instance handle.
// g_nOpen, g_nClosed, and g_nDocument - global indexes of the images.
// CX_BITMAP and CY_BITMAP - width and height of an icon.
// NUM_BITMAPS - number of bitmaps to add to the image list.
// IDB_OPEN_FILE, IDB_CLOSED_FILE, IDB_DOCUMENT -
// resource identifiers of the bitmaps.
BOOL InitTreeViewImageLists(HWND hwndTV)
{
HIMAGELIST himl; // handle to image list
HBITMAP hbmp; // handle to bitmap
// Create the image list.
if ((himl = ImageList_Create(CX_BITMAP,
CY_BITMAP,
FALSE,
NUM_BITMAPS, 0)) == NULL)
return FALSE;
// Add the open file, closed file, and document bitmaps.
hbmp = LoadBitmap(g_hInst, MAKEINTRESOURCE(IDB_OPEN_FILE));
g_nOpen = ImageList_Add(himl, hbmp, (HBITMAP)NULL);
DeleteObject(hbmp);
hbmp = LoadBitmap(g_hInst, MAKEINTRESOURCE(IDB_CLOSED_FILE));
g_nClosed = ImageList_Add(himl, hbmp, (HBITMAP)NULL);
DeleteObject(hbmp);
hbmp = LoadBitmap(g_hInst, MAKEINTRESOURCE(IDB_DOCUMENT));
g_nDocument = ImageList_Add(himl, hbmp, (HBITMAP)NULL);
DeleteObject(hbmp);
// Fail if not all of the images were added.
if (ImageList_GetImageCount(himl) < 3)
return FALSE;
// Associate the image list with the tree-view control.
TreeView_SetImageList(hwndTV, himl, TVSIL_NORMAL);
return TRUE;
}