AGB  ·  Datenschutz  ·  Impressum  







Anmelden
Nützliche Links
Registrieren
Zurück Delphi-PRAXiS Code-Bibliothek Neuen Beitrag zur Code-Library hinzufügen Delphi Drag & Drop vom Explorer auf unterschiedliche Steuerelemente
Thema durchsuchen
Ansicht
Themen-Optionen

Drag & Drop vom Explorer auf unterschiedliche Steuerelemente

Ein Thema von Luckie · begonnen am 8. Mär 2010 · letzter Beitrag vom 8. Nov 2016
 
Benutzerbild von Luckie
Luckie

Registriert seit: 29. Mai 2002
37.621 Beiträge
 
Delphi 2006 Professional
 
#1

Drag & Drop vom Explorer auf unterschiedliche Steuerelem

  Alt 8. Mär 2010, 08:41
Mit folgendem Beispiel kann man Dateien aus dem Explorer auf unterschiedliche Steuerelemente seines Formulares ziehen:
Delphi-Quellcode:
unit Unit6;

interface

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

type
  TForm6 = class(TForm)
    Edit1: TEdit;
    Edit2: TEdit;
    procedure FormCreate(Sender: TObject);
  private
    { Private-Deklarationen }
    procedure AppMessage(var Msg: Tmsg; var Handled: Boolean);
    function IsDropPointInside(const aDropPoint: TPoint; const aControl: TControl): Boolean;
  public
    { Public-Deklarationen }
  end;

var
  Form6: TForm6;

implementation

{$R *.dfm}

uses
  ShellAPI;

procedure TForm6.AppMessage(var Msg: Tmsg; var Handled: Boolean);
const
  BufferLength: word = 255;
var
  DroppedFilename: string;
  FileIndex: Word;
  QtyDroppedFiles: Word;
  pDroppedFilename: array[0..255] of Char;
  DropPoint: TPoint;
begin
  if Msg.Message = WM_DROPFILES then
  begin
    FileIndex := $FFFF;
    QtyDroppedFiles := DragQueryFile(Msg.WParam, FileIndex, pDroppedFilename, BufferLength);
    for FileIndex := 0 to (QtyDroppedFiles - 1) do
    begin
      DragQueryFile(Msg.WParam, FileIndex, pDroppedFilename, BufferLength);
      DroppedFilename := StrPas(pDroppedFilename);
      DropPoint := Msg.pt;
      if IsDropPointInside(DropPoint, Edit1) then
        Edit1.Text := DroppedFilename
      else if IsDropPointInside(DropPoint, Edit2) then
        Edit2.Text := DroppedFilename;
    end;
    DragFinish(Msg.WParam);
    Handled := true;
  end;
end;

procedure TForm6.FormCreate(Sender: TObject);
begin
  DragAcceptFiles(Edit1.Handle, true);
  DragAcceptFiles(Edit2.Handle, true);
  Application.OnMessage := AppMessage;
end;

function TForm6.IsDropPointInside(const aDropPoint: TPoint; const aControl: TControl): Boolean;
begin
  Result := PtInRect(aControl.ClientRect, aControl.ScreenToClient(aDropPoint));
end;

end.
Danke auch an Dezipaitor für seine Hilfe.

Stichwörter: WM_DROPPFILES, Drag and drop, DragAcceptFiles
Michael
Ein Teil meines Codes würde euch verunsichern.
  Mit Zitat antworten Zitat
 


Forumregeln

Es ist dir nicht erlaubt, neue Themen zu verfassen.
Es ist dir nicht erlaubt, auf Beiträge zu antworten.
Es ist dir nicht erlaubt, Anhänge hochzuladen.
Es ist dir nicht erlaubt, deine Beiträge zu bearbeiten.

BB-Code ist an.
Smileys sind an.
[IMG] Code ist an.
HTML-Code ist aus.
Trackbacks are an
Pingbacks are an
Refbacks are aus

Gehe zu:

Impressum · AGB · Datenschutz · Nach oben
Alle Zeitangaben in WEZ +1. Es ist jetzt 01:12 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