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.
Untuk membuat kontrol tampilan pohon, gunakan fungsi CreateWindowEx, menentukan nilai WC_TREEVIEW untuk kelas jendela. Kelas jendela tampilan pohon terdaftar di ruang alamat aplikasi saat DLL kontrol umum dimuat. Untuk memastikan bahwa DLL dimuat, gunakan fungsiInitCommonControls.
Apa yang perlu Anda ketahui
Teknologi
Prasyarat
- C/C++
- Pemrograman Antarmuka Pengguna Windows
Peraturan
Membuat Instans Kontrol Tree-View
Contoh berikut membuat kontrol tampilan pohon yang berukuran pas dengan area klien jendela induk. Ini juga menggunakan fungsi yang ditentukan aplikasi untuk mengaitkan daftar gambar dengan kontrol dan menambahkan item ke kontrol.
// Create a tree-view control.
// Returns the handle to the new control if successful,
// or NULL otherwise.
// hwndParent - handle to the control's parent window.
// lpszFileName - name of the file to parse for tree-view items.
// g_hInst - the global instance handle.
// ID_TREEVIEW - the resource ID of the control.
HWND CreateATreeView(HWND hwndParent)
{
RECT rcClient; // dimensions of client area
HWND hwndTV; // handle to tree-view control
// Ensure that the common control DLL is loaded.
InitCommonControls();
// Get the dimensions of the parent window's client area, and create
// the tree-view control.
GetClientRect(hwndParent, &rcClient);
hwndTV = CreateWindowEx(0,
WC_TREEVIEW,
TEXT("Tree View"),
WS_VISIBLE | WS_CHILD | WS_BORDER | TVS_HASLINES,
0,
0,
rcClient.right,
rcClient.bottom,
hwndParent,
(HMENU)ID_TREEVIEW,
g_hInst,
NULL);
// Initialize the image list, and add items to the control.
// InitTreeViewImageLists and InitTreeViewItems are application-
// defined functions, shown later.
if (!InitTreeViewImageLists(hwndTV) ||
!InitTreeViewItems(hwndTV))
{
DestroyWindow(hwndTV);
return FALSE;
}
return hwndTV;
}
Komentar
Saat membuat kontrol tampilan pohon, Anda juga dapat mengiriminya pesan WM_SETFONT untuk mengatur font yang akan digunakan untuk teks. Anda harus mengirim pesan ini sebelum menyisipkan item apa pun. Secara default, tampilan pohon menggunakan font judul ikon. Meskipun Anda dapat menyesuaikan font per item dengan menggunakan Gambar Kustom, kontrol tampilan pohon menggunakan dimensi font yang ditentukan oleh pesan WM_SETFONT untuk menentukan penspasian dan tata letak.