[WinAPI] Cum aflu numarul de coloane intr-un list-view?

Folosire Windows API in programe C/C++ (forum moderat)
Post Reply
User avatar
Ovidiu Cucu
Fondator
Fondator
Posts: 3778
Joined: 11 Jul 2007, 16:10
Judet: Iaşi
Location: Iasi
Contact:

[WinAPI] Cum aflu numarul de coloane intr-un list-view?

Post by Ovidiu Cucu » 24 Dec 2008, 18:27

Intrebare
Cum aflu numarul de coloane aflate intr-un control tip list-view care are stilul "Report" (LVS_REPORT)?

Raspuns
Nu exista o functie sau un mesaj care sa intoarca direct numarul de coloane pe care le are un list-view. Totusi, il putem afla din numarul de elemente pe care le are controlul header folosit de list-view.

Code: Select all

   int nColumnCount = 0; 
   HWND hWndHeaderCtrl = (HWND)::SendMessage(hWndListCtrl, LVM_GETHEADER, 0, 0);
   if(NULL != hWndHeaderCtrl)
   {
      nColumnCount = (int)::SendMessage(hWndHeaderCtrl, HDM_GETITEMCOUNT, 0, 0);
   }
In mod similar dar un pic mai comod putem folosi macro-urile ListView_GetHeader si Header_GetItemCount definite in commctrl.h.

Code: Select all

   int nColumnCount = 0; 
   HWND hWndHeaderCtrl = ListView_GetHeader(hWndListCtrl);
   if(NULL != hWndHeaderCtrl)
   {
      nColumnCount = Header_GetItemCount(hWndHeaderCtrl);
   }

<< Back to Windows API Index



Post Reply