Delphi-PRAXiS

Delphi-PRAXiS (https://www.delphipraxis.net/forum.php)
-   Sonstige Fragen zu Delphi (https://www.delphipraxis.net/19-sonstige-fragen-zu-delphi/)
-   -   Delphi Drag and Drop in Edit Feld. (https://www.delphipraxis.net/73294-drag-drop-edit-feld.html)

MiniKeks 15. Jul 2006 12:00


Drag and Drop in Edit Feld.
 
Drag and Drop in ein Edit Feld: Beim Drag and Drop soll der Pfad zur Datei die hineingezogen wird, im edit feld angezeigt werden..

Ich habe jetz den code von Swissdelphicenter für die Listbox angeschaut, werde aber nicht schlau daraus.

Könnt ihr mir auf die Sprünge helfen?

(PS: http://www.swissdelphicenter.ch/de/showcode.php?id=493 )


mfg,
MiniKeks ;)

marabu 15. Jul 2006 12:43

Re: Drag and Drop in Edit Feld.
 
Hi,

du musst doch eigentlich nur die ListBox durch ein Edit ersetzen:

Delphi-Quellcode:
unit DemoFrm;

interface

uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, StdCtrls;

type
  TDemoForm = class(TForm)
    Edit: TEdit;
    procedure FormCreate(Sender: TObject);
    procedure FormDestroy(Sender: TObject);
  private
    OldEditWindowProc: TWndMethod;
    procedure WMDROPFILES(var Msg: TMessage);
    procedure EditWindowProc(var Message: TMessage);
  end;

var
  DemoForm: TDemoForm;

implementation

{$R *.dfm}

uses
  ShellApi;

procedure TDemoForm.WMDROPFILES(var Msg: TMessage);
var
  pcFileName: PChar;
  i, iSize, iFileCount: integer;
  s: TStrings;
begin
  s := TStringList.Create;
  pcFileName := ''; // to avoid compiler warning message
  iFileCount := DragQueryFile(Msg.wParam, $FFFFFFFF, pcFileName, 255);
  for i := 0 to Pred(iFileCount) do
  begin
    iSize := Succ(DragQueryFile(Msg.wParam, i, nil, 0));
    pcFileName := StrAlloc(iSize);
    DragQueryFile(Msg.wParam, i, pcFileName, iSize);
    s.Add(pcFileName);
    StrDispose(pcFileName);
  end;
  DragFinish(Msg.wParam);
  Edit.Text := s.CommaText;
  s.Free;
end;

procedure TDemoForm.EditWindowProc(var Message: TMessage);
begin
  if Message.Msg = WM_DROPFILES then
    WMDROPFILES(Message);
  OldEditWindowProc(Message);
end;

procedure TDemoForm.FormCreate(Sender: TObject);
begin
  OldEditWindowProc := Edit.WindowProc;
  Edit.WindowProc := EditWindowProc;
  DragAcceptFiles(Edit.Handle, True);
end;

procedure TDemoForm.FormDestroy(Sender: TObject);
begin
  Edit.WindowProc := OldEditWindowProc;
  DragAcceptFiles(Edit.Handle, False);
end;

end.
Grüße vom marabu


Alle Zeitangaben in WEZ +1. Es ist jetzt 21:10 Uhr.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
LinkBacks Enabled by vBSEO © 2011, Crawlability, Inc.
Delphi-PRAXiS (c) 2002 - 2023 by Daniel R. Wolf, 2024 by Thomas Breitkreuz