Bagikan melalui


Cara Menggunakan Infotip Tree-View

Saat Anda menerapkan gaya TVS_INFOTIP ke kontrol tampilan pohon, gaya tersebut menghasilkan pemberitahuan TVN_GETINFOTIP saat kursor berada di atas item dalam tampilan pohon. Dengan menanggapi pemberitahuan ini, Anda dapat mengatur teks yang muncul di infotip.

Apa yang perlu Anda ketahui

Teknologi

Prasyarat

  • C/C++
  • Pemrograman Antarmuka Pengguna Windows

Peraturan

Gunakan Tree-View Infotips

Contoh kode berikut menunjukkan bagaimana aplikasi mungkin merespons pemberitahuan. Untuk kesederhanaan, contoh hanya menyalin teks untuk item ke infotip.

  case WM_NOTIFY:
    switch (((LPNMHDR) lParam)->code)
    {
    case TVN_GETINFOTIP:
        {
          LPNMTVGETINFOTIP pTip = (LPNMTVGETINFOTIP)lParam;
          HWND hTree            = GetDlgItem(hDlg, IDC_TREE1);
          HTREEITEM item        = pTip->hItem;

          // Get the text for the item.
          TVITEM tvitem;
          tvitem.mask       = TVIF_TEXT;
          tvitem.hItem      = item;
          TCHAR temp[1024];
          tvitem.pszText    = infoTipBuf;
          tvitem.cchTextMax = sizeof(temp) / sizeof(TCHAR);
          TreeView_GetItem(hTree, &tvitem);

          // Copy the text to the infotip.
          wcscpy_s(pTip->pszText, pTip->cchTextMax, tvitem.pszText);
          break;
        }
    }
    return TRUE;