Discussion:
LVM_GETITEMPOSITION unexpected result
Add Reply
R.Wieser
2024-12-12 14:08:02 UTC
Reply
Permalink
Hello all,

In a listview in basic LVS_ICON mode (no grouping) I'm trying the get the
location of an item. For that I'm using LVM_GETITEMPOSITION.

The problem is that it gives a way to large X position for all items (iow,
its a constant value of "too big").

Also, the first item gives a LVM_GETITEMPOSITION result of 0x00000015
0x00000002. The same item gives a LVM_GETITEMRECT result of 0x0000000D
0x00000000 0x0000003D 0x00000035.

Notice how the RECT X and Y results are, quite unexpected to me, *smaller*
than the POSITONs X and Y results.

Does anyone knows whats going on ? What is LVM_GETITEMPOSITION actually
returning ?

Regards,
Rudy Wieser
JJ
2024-12-13 08:42:07 UTC
Reply
Permalink
Post by R.Wieser
Hello all,
In a listview in basic LVS_ICON mode (no grouping) I'm trying the get the
location of an item. For that I'm using LVM_GETITEMPOSITION.
The problem is that it gives a way to large X position for all items (iow,
its a constant value of "too big").
Also, the first item gives a LVM_GETITEMPOSITION result of 0x00000015
0x00000002. The same item gives a LVM_GETITEMRECT result of 0x0000000D
0x00000000 0x0000003D 0x00000035.
Notice how the RECT X and Y results are, quite unexpected to me, *smaller*
than the POSITONs X and Y results.
Does anyone knows whats going on ? What is LVM_GETITEMPOSITION actually
returning ?
Regards,
Rudy Wieser
Have you checked it against the item's icon RECT?
R.Wieser
2024-12-14 08:09:14 UTC
Reply
Permalink
JJ,
Post by JJ
Have you checked it against the item's icon RECT?
I thought about that being a possible reason, and just checking it it looks
like you hit the nail on the head. :-)

Its just that I didn't expect a LVM_GET*ITEM*POSITION call to return the
position of something (the icon) inside of it. :-|

Any idea how I can get the top-left of the item itself ? (I'm trying to
draw a more visible focus indicator).

Regards,
Rudy Wieser
JJ
2024-12-15 08:39:39 UTC
Reply
Permalink
Post by R.Wieser
JJ,
Post by JJ
Have you checked it against the item's icon RECT?
I thought about that being a possible reason, and just checking it it looks
like you hit the nail on the head. :-)
Its just that I didn't expect a LVM_GET*ITEM*POSITION call to return the
position of something (the icon) inside of it. :-|
Any idea how I can get the top-left of the item itself ? (I'm trying to
draw a more visible focus indicator).
Regards,
Rudy Wieser
Just give LVM_GETITEMRECT which information you want. Or did you overlooked
it in the documentation?
R.Wieser
2024-12-15 09:57:21 UTC
Reply
Permalink
JJ,
Post by JJ
Post by R.Wieser
Any idea how I can get the top-left of the item itself ? (I'm
trying to draw a more visible focus indicator).
...
Post by JJ
Just give LVM_GETITEMRECT which information you want. Or did you
overlooked it in the documentation?
Did you overlook that I also mentioned that one in my inital message (and
included results of both), and that its documentation says it returns the
*boundary* of the item (which turns out to be the smallest box which
encompass all in it) ? :-p

Yeah, I tested (and drawn) both.

Regards,
Rudy Wieser
JJ
2024-12-16 05:14:47 UTC
Reply
Permalink
Post by R.Wieser
JJ,
Post by JJ
Post by R.Wieser
Any idea how I can get the top-left of the item itself ? (I'm
trying to draw a more visible focus indicator).
....
Post by JJ
Just give LVM_GETITEMRECT which information you want. Or did you
overlooked it in the documentation?
Did you overlook that I also mentioned that one in my inital message (and
included results of both), and that its documentation says it returns the
*boundary* of the item (which turns out to be the smallest box which
encompass all in it) ? :-p
Yeah, I tested (and drawn) both.
Regards,
Rudy Wieser
I'm not referring to the result.
R.Wieser
2024-12-16 07:37:44 UTC
Reply
Permalink
JJ,
Post by JJ
Post by R.Wieser
Post by JJ
Just give LVM_GETITEMRECT which information you want. Or did you
overlooked it in the documentation?
Did you overlook that I also mentioned that one in my inital message (and
included results of both), and that its documentation says it returns the
*boundary* of the item (which turns out to be the smallest box which
encompass all in it) ? :-p
Yeah, I tested (and drawn) both.
...
Post by JJ
I'm not referring to the result.
Than you've lost me. What /are/ you referring to ?


For your information, the below is the code I am using :

-- Inside the CDRF_NOTIFYITEMDRAW notification

lea esi,[@@rRect]
call RtlZeroMemory,esi,size RECT ;Implicite LVIR_BOUNDS request.
call SendMessageA,[ebx].NMH_hWndFrom,LVM_GETITEMRECT \
,[ebx].NMCD_lItemSpec,esi

call Rectangle,[ebx].NMCD_hDC \
,[esi].R_lLeft,[esi].R_lTop \
,[esi].R_lRight,[esi].R_lBottom

Using the above I get rectangles draw of all different sizes, depending on
the ammount/size of the text in the item. What I expect (and need) is
a series of same-sized rectangles that have no gaps between them.

If you see anything wrong with the above code please do tell.

Remark: To make damn sure I just tested the different LVIR_* possibilities,
and see no difference between LVIR_BOUNDS and LVIR_BOUNDSSELECT. :-|

Regards,
Rudy Wieser
Udo Steinbach
2024-12-18 13:08:25 UTC
Reply
Permalink
Without any knowledge I would think that the 3 words „in view coordinates“
make the difference, <=> „in the current view“. And „The position of list-
view items is specified in view coordinates, which are client coordinates
offset by the scroll position.“
--
Fahrradverkehr in Deutschland: http://radwege.udoline.de/
GPG: A245 F153 0636 6E34 E2F3 E1EB 817A B14D 3E7E 482E
R.Wieser
2024-12-18 14:25:59 UTC
Reply
Permalink
Udo,
Without any knowledge I would think that the 3 words "in view coordinates"
make the difference, <=> "in the current view". And "The position of
list-
view items is specified in view coordinates, which are client coordinates
offset by the scroll position."
When I did draw the rectangle returned by LVM_GETITEMRECT and a cross where
LVM_GETITEMPOSITION pointed to both stayed rock-steady on their respective
items - regardless of a horizontal/vertical scroll.

Which is, I must say, something I expected (I didn't think that
non-releative to the client rectangle would be of much use for drawing
purposes).

The only problem is that neither indicates the actual top-left of its item
(a shown by the "selected item" rectangle as displayed by the
LVS_EX_BORDERSELECT setting). :-(


To me it looks like that I can only get that "selected item" top-left
location by taking the result of LVM_GETITEMPOSITION, apply the scrolled
origin from LVM_GETVIEWRECT, divide by the result of LVM_GETITEMSPACING,
floor the results and re-multiply by it again.

... which feels rather hackish to me.

I still have to test that though.

Its not the first time I try to do something seemingly very basic/simple,
only to find out no method for it is exposed (even though the "selected"
rectangle shows its already done internally) - but that the result I /can/
get (the top/left of the icon) is possible in two different ways. Go figure.
:-\

Regards,
Rudy Wieser

Loading...