Delphi Pages Forums  

Go Back   Delphi Pages Forums > Delphi Forum > General

Lost Password?

Reply
 
Thread Tools Display Modes
  #1  
Old 01-28-2005, 12:24 AM
breandan breandan is offline
Junior Member
 
Join Date: Nov 2003
Posts: 21
Default Drag Folder into TListView and Have Associated icons..

Hi all,

does anyone know how to make it that you can drag a folder onto a listview and have all the files displayed along with their associated icons? Is this hard to do ?

Alternatively, is it possible to get the ShellListView to display the contents of one folder only i.e. a folder you drag over it.

Any help/code fragments you can give is appreciated.

thanks,

Brendan.
Reply With Quote
  #2  
Old 01-28-2005, 01:28 AM
Norrit Norrit is offline
Moderator
 
Join Date: Aug 2001
Location: Landgraaf
Posts: 6,699
Default RE: Drag Folder into TListView and Have Associated icons..

Hi ...

To allow drag-drop in your application, use the following code:
Code:
DragAcceptFiles(Self.Handle, True);
Now catch the WM_DROPFILES message:
Code:
protected
  procedure WMDROPFILES(var Message: TMessage); message WM_DROPFILES;
  ...

procedure TTDSView.WMDROPFILES(var Message: TMessage);
var
  FileName  : array [0..254] of Char;
  Hwnd      : THandle;
  FileCount : Byte;
begin
  Hwnd := Message.WParam;

  // Get the number of dropped files ...
  FileCount := DragQueryFile(Hwnd, $FFFFFFFF, FileName, SizeOf(FileName));
  try
    if FileCount > 0
    then begin
         // Load the last file ...
         DragQueryFile(Hwnd, FileCount - 1, FileName, SizeOf(FileName));

         // Do something with FileName ...
    end { if - FileCount > 0 };
  finally
    DragFinish(Hwnd);
  end { finally - DragQueryFile };
end;
And now to get the icon of a file into a TIcon:
Code:
var
  Ico         : TIcon;
  Extension   : String;
  SHFileInfo  : TSHFILEINFO;
begin
  Ico := TIcon.Create;
  try
    // Get the shortcut icon from the application ...
    SHGetFileInfo(PChar(FileName),
                  0, SHFileInfo, SizeOf(SHFileInfo),
                  SHGFI_LARGEICON or SHGFI_ICON);
    Ico.Handle := SHFileInfo.hIcon;
  finally
    Ico.Free;
  end;
end;
This should be all ... Just try and play a little with it ...

MvG
Peter

Objective reality is a delirium caused by lack of alcohol in blood.
24 hous in a day, 24 beers in a case. Coincidence ???
There are 10 kinds of people: Those who understand binary and those who don't
Reply With Quote
Reply

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is On

Forum Jump


All times are GMT. The time now is 09:13 PM.


Powered by vBulletin® Version 3.8.7
Copyright ©2000 - 2013, vBulletin Solutions, Inc.