0
votes

In my MFC app, the user can minimize a window that has a CListCtrl inside. I need to know how many visible items the list control will be showing once the user restores the window.

The first implementation used GetCountPerPage. This was working great until we noticed the minimized window case and found it was returning zero.

I've also tried GetClientRect, GetWindowRect and GetWindowPlacement (using rcNormalPosition) to attempt to figure out the size of the CListCtrl so I can compute the page count manually. All these APIs return empty rectangles positioned at various offscreen locations.

What's the best way to figure out what the CListCtrl's height will be once I restore the window? Surely the real window rectangle is available somehow.

2
GetCountPerPage should not fail unless you are in icon view or something. When the window is minimized (or iconized) GetCountPerPage and GetClientRect will return the same numbers. The only difference is that there is no paint message. Maybe you are resizing the control or something. Some minimal code would help. - Barmak Shemirani
We are using a very big CListCtrl subclass which I can't share... so a minimal example can't be provided. But I am sure it doesn't do anything intentionally on window minimization. - StilesCrisis
I have to guess then... Maybe you are overriding OnSize. On first call, HWND of ListView may not be available so you get strange results for invalid window. For resizing window's children, check main window's GetClientRect, if width/height is zero then don't do anything because it's minimized. - Barmak Shemirani

2 Answers

0
votes

CListCtrl is a wrapper around list view control. To work with it directly you can try to use macros ListView_GetCountPerPage(...) which is basically sending LVM_GETCOUNTPERPAGE message. If that still returns zero, this behavior is probably by default or it's a bug in common controls implementation. If your listview cannot change size in minimized state, you can probably just remember last valid value before window gets minimized.

0
votes

Once the window is restored/minimized/shown/hidden, WM_SHOWWINDOW will be called. So you can use this message to invoke OnShowWindow() and find the counts/height of the clistctrl.