Tech Support > Microsoft Windows > Development Resources > Q: resize ListView to show all items
Q: resize ListView to show all items
Posted by Jakob Bieling on September 2nd, 2006


Hi,

I have a ListView which will always hold exactly 5 items. Now I want
to make sure that this ListView is just large enough so those 5 items
will be visible. Currently, I am retrieving the item-rect of the last
item, AdjustWindowRectEx on that and use the result to determine the new
height of the ListView:

RECT rc;
RECT rcClient;
ListView_GetItemRect (hList, 4, &rc, LVIR_BOUNDS);
GetClientRect (hList, &rcClient);

rc.top = 0;
rc.left = 0;
AdjustWindowRectEx (&rc, GetWindowLong (hList, GWL_STYLE), FALSE,
GetWindowLong (hList, GWL_EXSTYLE));

SetWindowPos (hList, 0, 0, 0, rcClient.right, rc.bottom - rc.top + 5,
SWP_NOMOVE | SWP_NOZORDER | SWP_NOOWNERZORDER);

Unfortunately, I am missing 2px somewhere. As you can see, I have to
add 5 when setting the new window position: 3 are for a little space
just below the last item and those other 2 pixels are just coming out of
nowhere. I assume there is a better way to achieve this?

thanks for your time
--
jb

(reply address in rot13, unscramble first)


Posted by Charles Calvert on September 8th, 2006


On Sat, 2 Sep 2006 17:11:51 +0200, "Jakob Bieling"
<argfhesNGtzkQBGarg@rot13.com> wrote in
<edc70c$ij0$1@f1node01.rhrz.uni-bonn.de>:

Maybe it's just because I'm tired, but I don't understand why you're
calling AdjustWindowRectEx using the rect of a single item. Are you
trying to make the list view large enough to accommodate only one
item, or all five? Also, what view mode are you using? Icon, list,
report?

Forgetting my above question for a minute, have you verified that the
rect returned by ListView_GetItemRect is relative to the client rect
and not the window rect? I haven't played with it, so I don't know
for sure, but it's worth checking if you haven't already.
--
Charles Calvert | Software Design/Development
Celtic Wolf, Inc. | Project Management
http://www.celticwolf.com/ | Technical Writing
(703) 580-0210 | Research

Posted by Jakob Bieling on September 8th, 2006


Charles Calvert <cbciv@yahoo.com> wrote:
Oh, sorry, it's report view. And I get the last item's dimensions
only, because I need the right and bottom borders .. top and left are
then set to 0 (see the code). This way, I thought, I will get the
complete view area of the list view.

Well, I just checked, and for some reason, it is not relative to the
top-left-most corner of the ListView. Rather, its relative to (2,2) in
the ListView. Haven't even noticed the "left" value is also offset by 2.
Any ideas?

Thanks for your help!
--
jb

(reply address in rot13, unscramble first)




Posted by Jakob Bieling on September 8th, 2006


Jakob Bieling <argfhesNGtzkQBGarg@rot13.com> wrote:
Oh, and just to avoid confusion: those 2 pixels are not the border.
--
jb

(reply address in rot13, unscramble first)



Posted by Charles Calvert on September 14th, 2006


On Fri, 8 Sep 2006 10:55:35 +0200, "Jakob Bieling"
<argfhesNGtzkQBGarg@rot13.com> wrote in
<edrbd7$spi$1@f1node01.rhrz.uni-bonn.de>:

Sorry, but is that the window rect or the client rect? They are not
necessarily the same.

This is fairly odd, but I suspect that it has to do with the
difference between the window rect and client rect. I would do this:

1. Get both the windowrect and the clientrect for the listview. What
is the difference in their heights and widths? Two pixels?

2. Call ClientToScreen(listview.hwnd, POINT(0, 0) and compare the
result to the window rect. Are the left and top coordinates equal?
--
Charles Calvert | Software Design/Development
Celtic Wolf, Inc. | Project Management
http://www.celticwolf.com/ | Technical Writing
(703) 580-0210 | Research

Posted by Jakob Bieling on September 14th, 2006


Charles Calvert <cbciv@yahoo.com> wrote:
That did it Even tho those two pixels were not the border, one
pixel was! And of course the other one at the bottom. Not sure why I did
not think of that before. I went for the first approach you suggested
and added that difference (which was exactly two ) to the rect I
calculated.

Thanks a lot for your help!
--
jb

(reply address in rot13, unscramble first)




Similar Posts