چگونه ميتوان يك فايل يا شئ را از سيستم به برنامه و بلعكس Drag كرد
از مهندس هاي عزيز خواهشمندم به اين سوال من پاسخ دهند :34::37:
Printable View
چگونه ميتوان يك فايل يا شئ را از سيستم به برنامه و بلعكس Drag كرد
از مهندس هاي عزيز خواهشمندم به اين سوال من پاسخ دهند :34::37:
کد:unit Unit1;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls,
ShellAPI {ShellAPI is rquired};
type
TForm1 = class(TForm)
ListBox1: TListBox;
procedure FormCreate(Sender: TObject);
private
//WM_DROPFILES is sent to any window that is registered to accept draged
//files from explorer.
procedure WMDROPFILES(var MSG : TMessage); message WM_DROPFILES;
public
{ Public declarations }
end;
var
Form1: TForm1;
implementation
{$R *.dfm}
procedure TForm1.FormCreate(Sender: TObject);
begin
//Register the main window to accept draged files
DragAcceptFiles(Handle,True);
end;
procedure TForm1.WMDROPFILES(var MSG: TMessage);
var
hDrop : integer; //Drag data
FileCount : integer;
FileName : Array[ 0..Max_Path] of char; //Buffer
Index : integer; //Index of the file
begin
//WParam contains a pointer to the drag info. This data is created by Windows
//and must be freed by DragFinish.
hDrop := Msg.WParam;
//Passing $FFFFFFFF to DragQueryFile returns the numnber of files which are
//draged.
FileCount := DragQueryFile(hDrop,$FFFFFFFF,FileName,SizeOf(FileName));
//iterate in the draged files list and add each file to the listbox.
Index := 0;
repeat
//Get file name for each item.
//DragQueryFile returns the number of bytes returned as the file name. If
//is 0 then no data is returned and an error has been accured.
if DragQueryFile(hDrop,Index,FileName,SizeOf(FileName)) > 0 then
ListBox1.Items.Add(FileName)
else
raise Exception.Create('File Drag Error');
Inc(Index);
until Index = FileCount;
//Free the drag data
DragFinish(hDrop);
end;
ازين كه همكاري كرديد وجواب رو داديد ممنونم