mdlittle
asked on
Accept dragged item from the desktop
How does a form accept dragged items from the desktop? I am especially interested in accepting links from the desktop.
Mike
Mike
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
2.) that is in the IDE **path**
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Hi
Drop a ListBox on your form, then handle wm_DropFiles message, and it will accept the files, try this sample
unit Unit1;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls;
type
TForm4 = class(TForm)
ListBox1: TListBox;
procedure FormCreate(Sender: TObject);
private
{ Private declarations }
public
procedure DropFiles (var Msg: TWmDropFiles); message wm_DropFiles;
end;
var
Form4: TForm4;
implementation
{$R *.dfm}
uses
ShellAPI;
procedure TForm4.DropFiles(var Msg: TWmDropFiles);
var
FileName: string;
begin
SetLength(FileName,200);
DragQueryFile(Msg.Drop,0,P char(FileN ame),200);
ListBox1.Items.Add(FileNam e)
end;
procedure TForm4.FormCreate(Sender: TObject);
begin
DragAcceptFiles(Handle, True);
end;
Regards,
Mohammed
Drop a ListBox on your form, then handle wm_DropFiles message, and it will accept the files, try this sample
unit Unit1;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls;
type
TForm4 = class(TForm)
ListBox1: TListBox;
procedure FormCreate(Sender: TObject);
private
{ Private declarations }
public
procedure DropFiles (var Msg: TWmDropFiles); message wm_DropFiles;
end;
var
Form4: TForm4;
implementation
{$R *.dfm}
uses
ShellAPI;
procedure TForm4.DropFiles(var Msg: TWmDropFiles);
var
FileName: string;
begin
SetLength(FileName,200);
DragQueryFile(Msg.Drop,0,P
ListBox1.Items.Add(FileNam
end;
procedure TForm4.FormCreate(Sender: TObject);
begin
DragAcceptFiles(Handle, True);
end;
Regards,
Mohammed
Hi rllibby,
Can you have a look at this post for me you answered something similar last year, your help would be most appreciated.
https://www.experts-exchange.com/questions/21406728/Change-Windows-XP-Dektop-Theme.html
Cheers
Haggard1
Can you have a look at this post for me you answered something similar last year, your help would be most appreciated.
https://www.experts-exchange.com/questions/21406728/Change-Windows-XP-Dektop-Theme.html
Cheers
Haggard1
What wrong with my post cwwkie?
> What wrong with my post cwwkie?
I did not put you in the split because you posted a link to a link of a zipfile. So a lot to do before before it can be read.
To be honest, I did not download it before, but I have done now. And I see there is an error in the code from mnasman which is not in the code you link to (mnasman: DragFinish is not called, so there is a small memory leak). So I will post a new recommendation.
I hope everybody agrees.
I did not put you in the split because you posted a link to a link of a zipfile. So a lot to do before before it can be read.
To be honest, I did not download it before, but I have done now. And I see there is an error in the code from mnasman which is not in the code you link to (mnasman: DragFinish is not called, so there is a small memory leak). So I will post a new recommendation.
I hope everybody agrees.
Thanks.
I know it was trouble to check it but i posted the link to give credits to the author.
I know it was trouble to check it but i posted the link to give credits to the author.
1) Download the 3 unit files:
DragDropFilesEx.pas
DragDrop.pas
PIDL.pas
2.) Place these files in your {delphi}\lib path, or a suitable location that is in the IDE for delphi.
3.) Edit the DragDropFilesEx unit to add the component register. (not sure why the original author did not do this). The additions are as noted below:
---- ADDITION before implementation section ----
procedure Register;
---- END ADDITION ----
implementation
- and at the end of the unit before the end. statement -
---- ADDITION ----
procedure Register;
begin
RegisterComponents('Sample
end;
---- END ADDITION ----
end.
4.) Save this unit source, then select Component | Install Component | and Browse to the unit file DragDropFilesEx. Install this component which will end up on your Samples tab.
5.) Drop the component on your form, and set the DragDropControl = Form1. The rest is very basic (it may take a few minutes to set up, but its worth it)
Example unit code:
unit Unit1;
interface
uses
Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
DragDrop, DragDropFilesEx;
type
TForm1 = class(TForm)
DragDropFilesEx1: TDragDropFilesEx;
procedure DragDropFilesEx1DragEnter(
procedure DragDropFilesEx1ProcessDro
private
{ Private declarations }
public
{ Public declarations }
end;
var
Form1: TForm1;
implementation
{$R *.DFM}
procedure TForm1.DragDropFilesEx1Dra
begin
Accept:=True;
end;
procedure TForm1.DragDropFilesEx1Pro
var dwIndex: Integer;
begin
for dwIndex:=0 to Pred(DragDropFilesEx1.File
ShowMessage(DragDropFilesE
end;
end.
-- and form dfm code ---
object Form1: TForm1
Left = 339
Top = 326
Width = 401
Height = 211
Caption = 'Form1'
Color = clBtnFace
Font.Charset = DEFAULT_CHARSET
Font.Color = clWindowText
Font.Height = -11
Font.Name = 'MS Sans Serif'
Font.Style = []
OldCreateOrder = False
PixelsPerInch = 96
TextHeight = 13
object DragDropFilesEx1: TDragDropFilesEx
AcceptOwnDnD = False
BringToFront = False
DragDropControl = Owner
ScrollDetectOptions.AreaWi
SourceCompatibility = []
SourceEffects = [deCopy]
TargetPopupMenu = True
TargetEffects = [deCopy]
DragDetect.Automatic = True
DragDetect.DeltaX = 4
DragDetect.DeltaY = 4
OnDragEnter = DragDropFilesEx1DragEnter
OnProcessDropped = DragDropFilesEx1ProcessDro
NeedValid = [nvFilename]
Left = 12
Top = 8
end
end
---
Regards,
Russell