🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Thread View: alt.comp.borland-delphi
5 messages
5 total messages Started by Peter Timmerman Wed, 16 Jul 2003 12:02
Getting selected items from SysListview32 in Explorer windows
#1474
Author: Peter Timmerman
Date: Wed, 16 Jul 2003 12:02
13 lines
1852 bytes
Hi! =)

I'm making an application that needs to find the selected items in the
listview inside an Explorer window. I found some code that uses SendMessage
and it works fine, but
it returns ALL items not just the selected. In time I will
need the icon associated with the items, but I'm just wondering.. Is it
possible to assign or make a "copy" of an "alien"
control? like: mylistview := alienform.listview

thanks in advance,

Peter
Re: Getting selected items from SysListview32 in Explorer windows
#1470
Author: Jeremy Collins
Date: Thu, 17 Jul 2003 08:44
13 lines
2066 bytes
Peter Timmerman wrote:
> Hi! =)
> 
> I'm making an application that needs to find the selected items in the
> listview inside an Explorer window. I found some code that uses SendMessage
> and it works fine, but
> it returns ALL items not just the selected. 

Yep, then you just iterate the collection and
list which items state indicates "selected".

--
jc
Re: Getting selected items from SysListview32 in Explorer windows
#1471
Author: Peter Timmerman
Date: Sat, 19 Jul 2003 21:21
25 lines
2108 bytes
Hi Jeremy, thanks for you answer =) Do you have any source somewhere,
because I'm new to API coding in Delphi and feel STUCK :(

thanks


- Peter

"Jeremy Collins" <jd.collins@ntlworld.com> skrev i en meddelelse
news:MltRa.13238$nP.12752@newsfep4-winn.server.ntli.net...
> Peter Timmerman wrote:
> > Hi! =)
> >
> > I'm making an application that needs to find the selected items in the
> > listview inside an Explorer window. I found some code that uses
SendMessage
> > and it works fine, but
> > it returns ALL items not just the selected.
>
> Yep, then you just iterate the collection and
> list which items state indicates "selected".
>
> --
> jc
>
Re: Getting selected items from SysListview32 in Explorer windows
#1472
Author: Jeremy Collins
Date: Mon, 21 Jul 2003 09:19
66 lines
4101 bytes
Peter Timmerman wrote:
> Hi Jeremy, thanks for you answer =) Do you have any source somewhere,
> because I'm new to API coding in Delphi and feel STUCK :(

I'll knock up some code if you need further help, but once
you have a handle to your ListView [1], you use the control
messages documented in the API help. So to get the first
selected item:

SendMessage(hwndListView,
             LVM_GETNEXTITEM,
             0,
             MAKELPARAM(LVNI_ALL or LVNI_SELECTED, 0));

This will return the item index of the first selected item.
To get the next selected item, send the same message with
the returned index as the 3rd parameter (the start index),
and repeat until no more items are returned.

To get the total number of items use
   SendMessage(hwndListView, LVM_GETITEMCOUNT, 0, 0);

Now the catch. To get anything really useful, you need to
persuade Windows to pass some data via SendMessage from Explorer
to your application, something which it isn't very keeen on
doing.

If the listview was owned by your application, you could do this:

var
   AItem : tagLVITEM;
   hwndListView : HWND;
begin
   hwndListView := ListView1.Handle;
   FillChar(AItem , SizeOf(tagLVITEM), 0);
   AItem.iItem := 1;  //2nd item, e.g.
   AItem.mask := LVIF_TEXT or LVIF_IMAGE;

   ListView_GetItem(hwndListView, AItem);
   //AItem will now contain info about the list item...
end;

The ListView_GetItem macro simply wraps a call to SendMessge
with LVM_GETITEM, to make (C++) code more readable. Delphi's
TListView already wraps this stuff up in properties (aren't you
glad).

Anyway, to get aound this, you have to create a shared chunk
of memory. Rather than explain this myself, read this usenet
post:

http://tinyurl.com/hjo9

Also spend some time reading your SDK help files under "List
View Controls", the "LVM_XXX" messages and "ListView_XXX" macros.
You'll need to be familiar with the LVITEM structure, and also
with how Windows (not Delphi) handles image lists.

HTH

--
jc


[1] Be careful of code which calls FindWindowEx with hardcoded
window class names - these could differ between Windows versions.
Re: Getting selected items from SysListview32 in Explorer windows
#1473
Author: Peter Timmerman
Date: Mon, 28 Jul 2003 00:07
77 lines
4026 bytes
Hi again,

thanks - this sounds VERY promising!

=)

- Peter

"Jeremy Collins" <jd.collins@ntlworld.com> skrev i en meddelelse
news:BeOSa.2178$Ai3.1198@newsfep4-winn.server.ntli.net...
> Peter Timmerman wrote:
> > Hi Jeremy, thanks for you answer =) Do you have any source somewhere,
> > because I'm new to API coding in Delphi and feel STUCK :(
>
> I'll knock up some code if you need further help, but once
> you have a handle to your ListView [1], you use the control
> messages documented in the API help. So to get the first
> selected item:
>
> SendMessage(hwndListView,
>              LVM_GETNEXTITEM,
>              0,
>              MAKELPARAM(LVNI_ALL or LVNI_SELECTED, 0));
>
> This will return the item index of the first selected item.
> To get the next selected item, send the same message with
> the returned index as the 3rd parameter (the start index),
> and repeat until no more items are returned.
>
> To get the total number of items use
>    SendMessage(hwndListView, LVM_GETITEMCOUNT, 0, 0);
>
> Now the catch. To get anything really useful, you need to
> persuade Windows to pass some data via SendMessage from Explorer
> to your application, something which it isn't very keeen on
> doing.
>
> If the listview was owned by your application, you could do this:
>
> var
>    AItem : tagLVITEM;
>    hwndListView : HWND;
> begin
>    hwndListView := ListView1.Handle;
>    FillChar(AItem , SizeOf(tagLVITEM), 0);
>    AItem.iItem := 1;  //2nd item, e.g.
>    AItem.mask := LVIF_TEXT or LVIF_IMAGE;
>
>    ListView_GetItem(hwndListView, AItem);
>    //AItem will now contain info about the list item...
> end;
>
> The ListView_GetItem macro simply wraps a call to SendMessge
> with LVM_GETITEM, to make (C++) code more readable. Delphi's
> TListView already wraps this stuff up in properties (aren't you
> glad).
>
> Anyway, to get aound this, you have to create a shared chunk
> of memory. Rather than explain this myself, read this usenet
> post:
>
> http://tinyurl.com/hjo9
>
> Also spend some time reading your SDK help files under "List
> View Controls", the "LVM_XXX" messages and "ListView_XXX" macros.
> You'll need to be familiar with the LVITEM structure, and also
> with how Windows (not Delphi) handles image lists.
>
> HTH
>
> --
> jc
>
>
> [1] Be careful of code which calls FindWindowEx with hardcoded
> window class names - these could differ between Windows versions.
>
Thread Navigation

This is a paginated view of messages in the thread with full content displayed inline.

Messages are displayed in chronological order, with the original post highlighted in green.

Use pagination controls to navigate through all messages in large threads.

Back to All Threads