Ver Mensaje Individual
  #4  
Antiguo 31-03-2024
Avatar de MAXIUM
MAXIUM MAXIUM is offline
Miembro
 
Registrado: may 2005
Posts: 1.494
Reputación: 21
MAXIUM Va camino a la fama
Add ShellAPI and Messages to your project's uses:
Código Delphi [-]
uses
    ShellAPI, Messages;
Add a method to your form that handles the WM_DROPFILES message.

For example, the following would be placed in the TForm1 declaration in the protected section:
Código Delphi [-]
protected
    procedure WMDropFiles(var Msg: TWMDropFiles); message WM_DROPFILES;
Drag 'n' drop are activated by calling:
Código Delphi [-]
DragAcceptFiles(Handle, true);
and deactivated by calling:

Código Delphi [-]
DragAcceptFiles(Handle, false);
It is normal to activate drag 'n' drop in the OnCreate event, and deactivate it in the OnClose or OnDestroy events:
Código Delphi [-]
procedure TForm1.FormCreate(Sender: TObject);
begin
  DragAcceptFiles(Handle, true);
end;
procedure TForm1.FormClose(Sender: TObject; var Action: TCloseAction);
begin
  DragAcceptFiles(Handle, false);
end;
This first procedure will enable you to drop files one at a time:
Código Delphi [-]
procedure TForm1.WMDropFiles(var Msg: TWMDropFiles);
var filename: PChar;
    length: LongWord;
begin
  length:= DragQueryFile(Msg.Drop, 0, NIL, 0);
  filename:= StrAlloc(length+1);
  DragQueryFile(Msg.Drop,0,filename,length+1);
  {do something with filename}
  Msg.Result:=0;
  inherited;
end;
Responder Con Cita