Наши проекты:
Журнал · Discuz!ML · Wiki · DRKB · Помощь проекту |
||
ПРАВИЛА | FAQ | Помощь | Поиск | Участники | Календарь | Избранное | RSS |
[3.133.79.70] |
|
Сообщ.
#1
,
|
|
|
unit Unit1; interface uses Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs, ShellAPI; type TForm1 = class(TForm) procedure FormCreate(Sender: TObject); private procedure GetFile(var Message: TMessage); message WM_DROPFILES; end; var Form1: TForm1; implementation {$R *.dfm} { TForm1 } procedure TForm1.FormCreate(Sender: TObject); begin DragAcceptFiles(Handle, True); end; procedure TForm1.GetFile(var Message: TMessage); var FileNames: String; FileName: PChar; FileCount, I: Integer; begin GetMem(FileName, MAX_PATH); try FileCount := DragQueryFile(Message.WParam, DWORD(-1), nil, 0); for I := 0 to FileCount - 1 do begin if FileNames <> '' then FileNames := FileNames + #13#10; DragQueryFile(Message.WParam, I, FileName, MAX_PATH); FileNames := FileNames + FileName; end; ShowMessage(FileNames); finally FreeMem(FileName); end; end; end. Эта тема была разделена из темы "Перетаскивание файлов в приложение" |
Сообщ.
#2
,
|
|
|
Аналог, но в качестве приемника будет выступать ListView:
unit Unit1; interface uses Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs, ComCtrls, ShellAPI, AppEvnts; type TForm1 = class(TForm) ListView1: TListView; ApplicationEvents1: TApplicationEvents; procedure FormCreate(Sender: TObject); procedure ApplicationEvents1Message(var Msg: tagMSG; var Handled: Boolean); end; var Form1: TForm1; implementation {$R *.dfm} procedure TForm1.FormCreate(Sender: TObject); begin DragAcceptFiles( ListView1.Handle, True); end; procedure TForm1.ApplicationEvents1Message(var Msg: tagMSG; var Handled: Boolean); var FileName: PChar; FileCount, I: Integer; begin if Msg.message = WM_DROPFILES then begin GetMem(FileName, MAX_PATH); try FileCount := DragQueryFile(Msg.WParam, DWORD(-1), nil, 0); for I := 0 to FileCount - 1 do begin DragQueryFile(Msg.WParam, I, FileName, MAX_PATH); with ListView1.Items.Add do Caption := FileName; end; finally FreeMem(FileName); end; end; end; end. |