Fórum Drag&Drop do explorer para aplicação #561770
31/08/2016
0
Galera, estou iniciando em delphi e estou com uma dificuldade, estou fazendo um programinha básico, que você arrasta uma imagem do desktop para o programa em execução, e ele pega essa imagem, porém só consigo arrastar 1 imagem, se vou arrastar outra apenas 1 fica dominante na tela, segue o código abaixo:
unit Unit1;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, ExtCtrls, ShellAPI, jpeg, StdCtrls;
type
TForm1 = class(TForm)
Panel1: TPanel;
Image1: TImage;
Label2: TLabel;
Panel2: TPanel;
Image2: TImage;
procedure FormCreate(Sender: TObject);
procedure FormDestroy (Sender: TObject);
private
PanelOriginal : TWndMethod;
procedure PanelWindow (var Msg : TMessage);
procedure PanelImageDrop (var Msg: TWMDropFiles);
{ Private declarations }
public
{ Public declarations }
end;
var
Form1: TForm1;
implementation
{$R *.dfm}
procedure TForm1.FormCreate(Sender: TObject);
begin
PanelOriginal := Panel1.WindowProc;
Panel1.WindowProc := PanelWindow;
DragAcceptFiles(Panel1.Handle,true)
end;
procedure TForm1.PanelWindow(var Msg: TMessage);
begin
if Msg.Msg = WM_DROPFILES then
PanelImageDrop (TWMDROPFILES(msg))
else
PanelOriginal(msg);
end;
procedure TForm1.FormDestroy(Sender: TObject);
begin
Panel1.WindowProc := PanelOriginal;
DragAcceptFiles(Panel1.Handle,false);
end;
procedure TForm1.PanelImageDrop(var Msg: TWMDropFiles);
var
nArquivos : integer;
Destino : array [0..MAX_PATH] of char;
begin
nArquivos := DragQueryFile (Msg.Drop, $FFFFFFFF, nil, 0);
if nArquivos > 1 then
begin
ShowMessage('Voce esta selecionando Mais de uma imagem ao mesmo tempo');
end
else
begin
DragQueryFile(Msg.Drop, 0, @Destino, SizeOf(Destino));
try
Image1.Picture.LoadFromFile(Destino);
except
on EInvalidGraphic do ShowMessage ('Tipo de arquivo nao suportado'); retorna Msg
end;
end;
end;
end.
unit Unit1;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, ExtCtrls, ShellAPI, jpeg, StdCtrls;
type
TForm1 = class(TForm)
Panel1: TPanel;
Image1: TImage;
Label2: TLabel;
Panel2: TPanel;
Image2: TImage;
procedure FormCreate(Sender: TObject);
procedure FormDestroy (Sender: TObject);
private
PanelOriginal : TWndMethod;
procedure PanelWindow (var Msg : TMessage);
procedure PanelImageDrop (var Msg: TWMDropFiles);
{ Private declarations }
public
{ Public declarations }
end;
var
Form1: TForm1;
implementation
{$R *.dfm}
procedure TForm1.FormCreate(Sender: TObject);
begin
PanelOriginal := Panel1.WindowProc;
Panel1.WindowProc := PanelWindow;
DragAcceptFiles(Panel1.Handle,true)
end;
procedure TForm1.PanelWindow(var Msg: TMessage);
begin
if Msg.Msg = WM_DROPFILES then
PanelImageDrop (TWMDROPFILES(msg))
else
PanelOriginal(msg);
end;
procedure TForm1.FormDestroy(Sender: TObject);
begin
Panel1.WindowProc := PanelOriginal;
DragAcceptFiles(Panel1.Handle,false);
end;
procedure TForm1.PanelImageDrop(var Msg: TWMDropFiles);
var
nArquivos : integer;
Destino : array [0..MAX_PATH] of char;
begin
nArquivos := DragQueryFile (Msg.Drop, $FFFFFFFF, nil, 0);
if nArquivos > 1 then
begin
ShowMessage('Voce esta selecionando Mais de uma imagem ao mesmo tempo');
end
else
begin
DragQueryFile(Msg.Drop, 0, @Destino, SizeOf(Destino));
try
Image1.Picture.LoadFromFile(Destino);
except
on EInvalidGraphic do ShowMessage ('Tipo de arquivo nao suportado'); retorna Msg
end;
end;
end;
end.
Jose Paes
Curtir tópico
+ 0
Responder
Posts
31/08/2016
Jones Granatyr
Olá Jose,
Não consegui reproduzir o seu código, mas talvez você tenha usar threads para isso. Dê uma pesquisada sobre esse assunto para garantir!
Jones
Não consegui reproduzir o seu código, mas talvez você tenha usar threads para isso. Dê uma pesquisada sobre esse assunto para garantir!
Jones
Responder
Gostei + 0
Clique aqui para fazer login e interagir na Comunidade :)