thanks
"created, resized, the view is changed" - but which messages/notifications would be for resizing and "changing the view"? The damn comment could've said that.
Now I have 1 small issue with my function to get the item rect and compare to the ListView rect. The item height isn't retrieved when the listview is empty. I thought about substituting the header item height, but it's not the same. Only thing I can think is maybe to check if an items exists, and if not, add a blank one so I get the right height. The function to fill the box clears it each time anyway, so I guess it can't hurt.
Well, this took a while, but it works.
Code:
int CalcPageSize(HWND hListView){
RECT ItemRect; memset(&ItemRect,0,sizeof(ItemRect));
int iCount = SendMessage(hListView, LVM_GETITEMCOUNT, 0, 0);
if (!(iCount)) {
LVITEM LvItem; memset(&LvItem,0,sizeof(LvItem));
SendMessage(hListView, LVM_INSERTITEM, 0, (LPARAM)&LvItem);
}
ItemRect.left = LVIR_LABEL;
SendMessage(hListView, LVM_GETITEMRECT, 0, (LPARAM)&ItemRect);
HWND hHeader = (HWND)SendMessage(hListView, LVM_GETHEADER, 0, 0);
RECT HeaderRect; memset(&HeaderRect,0,sizeof(HeaderRect));
if (hHeader) {
HeaderRect.left = LVIR_LABEL;
GetWindowRect(hHeader, &HeaderRect);
}
if ( (ItemRect.bottom - ItemRect.top) <= 0 ) {
if ( (HeaderRect.bottom - HeaderRect.top) > 0 ) {
ItemRect.top = HeaderRect.top;
ItemRect.bottom = HeaderRect.bottom;
} else { return DEFAULT_PAGE_SIZE; }
}
RECT lvRect; memset(&lvRect,0,sizeof(lvRect));
if (GetWindowRect(hListView, &lvRect) == 0 ) { return DEFAULT_PAGE_SIZE; }
return (((lvRect.bottom - lvRect.top) - (HeaderRect.bottom - HeaderRect.top)) / (ItemRect.bottom - ItemRect.top));
}