![]() |
Empfänger bei WM_DROPPFILES unterscheiden
Ich habe viel gesucht, aber leider nichts zum Thema gefunden. Wie kann ich bei WM_DROPPFILES den Empfänger unterscheiden? Mein bisheriger Code:
Delphi-Quellcode:
So wie er jetzt ist landet die Datei natürlich in beiden Edits, wenn ich sie über einem droppe.
procedure TfrmSteganosaur.AppMessage(var Msg: Tmsg; var Handled: Boolean);
const BufferLength: word = 255; var DroppedFilename: string; FileIndex: word; QtyDroppedFiles: word; pDroppedFilename: array[0..255] of Char; DroppedFileLength: word; 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 DroppedFileLength := DragQueryFile(Msg.WParam, FileIndex, pDroppedFilename, BufferLength); DroppedFilename := StrPas(pDroppedFilename); edtCarrierFile.Text := DroppedFilename; edtTrailerFile.Text := DroppedFilename; end; DragFinish(Msg.WParam); Handled := true; end; end; |
Re: Empfänger bei WM_DROPPFILES unterscheiden
Könntest ja die Mausposition, an der losgelassen wurde, ermitteln und dann das dazugehörige VCL-Control...
|
Re: Empfänger bei WM_DROPPFILES unterscheiden
Ja, das habe ich schon versucht mit DragQueryPt aber weder ClientRect noch BoundsRect von den Edit Komponenten liefert bei PtInRect true.
|
Re: Empfänger bei WM_DROPPFILES unterscheiden
Hallo Michael,
wenn das Formular die Nachricht WM_DROPFILES empfängt, bezieht sich der DropPoint auf den Client-Bereich des Formulars. Du musst also die Koordinaten auf die Client-Bereiche der Edit-Controls umrechnen (lassen):
Delphi-Quellcode:
Gruß Hawkeye
var
DropPoint: TPoint; begin : DragQueryPoint(Msg.WParam, DropPoint); if IsDropPointInside(DropPoint, edtCarrierFile) then edtCarrierFile.Text := DroppedFilename else if IsDropPointInside(DropPoint, edtTrailerFile) then edtTrailerFile.Text := DroppedFilename; : end; function TfrmSteganosaur.IsDropPointInside (const aDropPoint: TPoint; const aControl: TControl): Boolean; begin Result := PtInRect(aControl.ClientRect, aControl.ScreenToClient({Self.}ClientToScreen(aDropPoint))); end; |
Re: Empfänger bei WM_DROPPFILES unterscheiden
Leider liefert IsDragPointInside immer False.
Delphi-Quellcode:
function TfrmSteganosaur.IsDropPointInside(const aDropPoint: TPoint; const aControl: TControl): Boolean;
begin Result := PtInRect(aControl.ClientRect, aControl.ScreenToClient({Self.}ClientToScreen(aDropPoint))); end; procedure TfrmSteganosaur.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); DragQueryPoint(Msg.WParam, DropPoint); if IsDropPointInside(DropPoint, edtCarrierFile) then edtCarrierFile.Text := DroppedFilename else if IsDropPointInside(DropPoint, edtTrailerFile) then edtTrailerFile.Text := DroppedFilename; end; DragFinish(Msg.WParam); Handled := true; end; end; |
Re: Empfänger bei WM_DROPPFILES unterscheiden
Zitat:
Gruß Hawkeye |
Re: Empfänger bei WM_DROPPFILES unterscheiden
Nein. QtyDroppedFiles hat den Wert eins, wenn ich eine Datei ziehe. Auch wenn ich sie mit FileIndex := $FFFFFFFF; initialisiere. Und DroppedFilename enthält auch den Dateinamen. Das passt also alles.
|
Re: Empfänger bei WM_DROPPFILES unterscheiden
Hast du es schon andersherum probiert? Also die Kontrollkoordinaten nach Screenkoordinaten umgerechnet?
|
Re: Empfänger bei WM_DROPPFILES unterscheiden
Noch nicht. Bin gerade an einer anderen Baustelle.
|
Re: Empfänger bei WM_DROPPFILES unterscheiden
Ich habe es mal korrigiert. So sollte es funktionieren:
Delphi-Quellcode:
Das Problem war eigentlich, dass DragQueryPoint die Clientkoordinaten des Ziels zurückgibt. In Msg.hwnd ist das Handle des Ziels (hier das Edit).
function TForm1.IsDropPointInside(const aDropPoint: TPoint; const aControl: TControl): Boolean;
begin Result := PtInRect(aControl.ClientRect, aControl.ScreenToClient(aDropPoint)); end; procedure TForm1.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); //DragQueryPoint(Msg.WParam, DropPoint); DropPoint := Msg.pt; if IsDropPointInside(DropPoint, edtCarrierFile) then edtCarrierFile.Text := DroppedFilename else if IsDropPointInside(DropPoint, edtTrailerFile) then edtTrailerFile.Text := DroppedFilename; end; DragFinish(Msg.WParam); Handled := true; end; end; |
Alle Zeitangaben in WEZ +1. Es ist jetzt 02:09 Uhr. |
Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
LinkBacks Enabled by vBSEO © 2011, Crawlability, Inc.
Delphi-PRAXiS (c) 2002 - 2023 by Daniel R. Wolf, 2024-2025 by Thomas Breitkreuz