Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations derfloh on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How to implement drag and drop feature?

Status
Not open for further replies.

TheBugSlayer

Programmer
Sep 22, 2002
887
US
Hi all.

I saw a program that allows you to drag a shortcut from desktop (or any other folder for that matter), drop it on an open application window (in a list box for instance) and all the properties of the shortcut are added as an item in the listbox (the 'Target' text box).

Can anyone explain to me how to implement such behaviour? I need to do something exactly like that. I am using Delphi 6.

Thank you in advance.
 
Try this example:

unit Unit1;

interface

uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls;

type
TForm1 = class(TForm)
Memo1: TMemo;
procedure FormCreate(Sender: TObject);
private
procedure WMDropFiles(var Msg: TWMDropFiles); message WM_DROPFILES;
public
end;

var
Form1: TForm1;

implementation
{$R *.dfm}
uses
Shellapi;

procedure TForm1.FormCreate(Sender: TObject);
begin
DragAcceptFiles(Form1.Handle, True);
end;

procedure TForm1.WMDropFiles(var Msg: TWMDropFiles);
var
i, NumFiles, FilenameLength: integer;
s: string;
begin
NumFiles := DragQueryFile(Msg.Drop, $FFFFFFFF, nil, 0);
for i := 0 to NumFiles - 1 do
begin
FilenameLength := DragQueryFile(Msg.Drop, i, nil, 0) +1;
SetLength(s, FilenameLength);

DragQueryFile(Msg.Drop, i, PChar(s), FilenameLength);

Memo1.Lines.Add(s);
end;
DragFinish(Msg.Drop);
end;

end.



//Nordlund
 
Thanks Nordlund. While your examples works-I already had something similar- it does not give me the information in the 'Target' field of the shortcut properties. I am running a client from a shortcut which has a few switches and I would like to see that info in my memo or list box when I drop the selection.

Below is an example of what I have the 'Target' field of the shortcut props:

C:\FlashForms\FlashIt!\Bin\FlashIt.exe /S=MY-SERVER /P=my_program /I=my_item /T=FlashIt /U=MrFlashit /SQLU=sa

but when I drop the icon I only get

C:\FlashForms\FlashIt!\ToolBar\FlashIt.lnk


I hope I made myself clearer. Thanks for the help.
 
Thanks whosrdaddy.
I looked at the code superficially and it seems just like what I am looking for. I am almost sure it is the solution so thanks again.
 
whosrdaddy,
a simple code sample might help me more. I tried the procedure below and it does not work. Not to sure how to use the class.

Code:
[b]
procedure TForm1.Button1Click(Sender: TObject);
var FLink : TShellLink;
begin
   FLink.Create;
   FLink.LoadFromFile('C:\FlashForms\FlashIt!\ToolBar\FlashIt.lnk');
   ShowMessage(FLink.Arguments);
   FLink.Destroy;
end;
[/b]
[code]
 
you almost had it right :

procedure TForm1.Button1Click(Sender: TObject);

var FLink : TShellLink;
begin
FLink:=TShellLink.Create; //never call create from child object, always use parent constructor
FLink.LinkFile:='c:\temp\test.lnk';
Flink.Load;
ShowMessage(FLink.Arguments);
FLink.Destroy;
end;

greetings

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top