Here some sample code so a TGridView accepts dragged files from the explorer. Steps are simple,
Add an TApplicationEvents vcl and connect it to the following OnEvent handler:
CODE
procedure TForm1.ApplicationEvents1Message(var Msg: tagMSG;
var Handled: Boolean);
var
Buff : array[0..MAX_PATH] of Char;
Files,
Count : Word;
fn : string;
begin
case Msg.message of
WM_DropFiles:
begin
Handled := True;
Files := DragQueryFile(Msg.wParam, $FFFFFFFF, nil, 0);
for Count := 0 to Files - 1 do
begin
DragQueryFile(Msg.wParam, Count, @Buff, SizeOf(Buff) - 1);
fn := PChar(@Buff);
if (FileExists(fn)) then
begin
/*process a file with filename fn here, beware mutliple files can be dropped too */
end
else
MessageBeep(MB_ICONEXCLAMATION);
end;
DragFinish(Msg.wParam);
end;
else
Handled := False;
end;
end;
var Handled: Boolean);
var
Buff : array[0..MAX_PATH] of Char;
Files,
Count : Word;
fn : string;
begin
case Msg.message of
WM_DropFiles:
begin
Handled := True;
Files := DragQueryFile(Msg.wParam, $FFFFFFFF, nil, 0);
for Count := 0 to Files - 1 do
begin
DragQueryFile(Msg.wParam, Count, @Buff, SizeOf(Buff) - 1);
fn := PChar(@Buff);
if (FileExists(fn)) then
begin
/*process a file with filename fn here, beware mutliple files can be dropped too */
end
else
MessageBeep(MB_ICONEXCLAMATION);
end;
DragFinish(Msg.wParam);
end;
else
Handled := False;
end;
end;
In the formcreate call
CODE
DragAcceptFiles(GridView3.Handle, True);
found in the ShellApi unit (so include it).
Thats it!