Einzelnen Beitrag anzeigen

Benutzerbild von SirThornberry
SirThornberry
(Moderator)

Registriert seit: 23. Sep 2003
Ort: Bockwen
12.235 Beiträge
 
Delphi 2006 Professional
 

Re: wm_dropfiles an Anwendung senden (SendMessage)

  Alt 12. Mär 2005, 13:04
Habs jetzt hinnbekommen:
Delphi-Quellcode:
function DropFilesOnWnd(AWnd: HWND; AFiles: String): Boolean; overload;
var LInfo: PDragInfoA;
    LRes: Boolean;
    LHGlobal: Cardinal;
begin
  LRes := False;
  if copy(AFiles, length(AFiles), 1) <> #0 then
    AFiles := AFiles + #0;
  LHGlobal := GlobalAlloc(GMEM_SHARE or GMEM_MOVEABLE or GMEM_ZEROINIT, SizeOf(TDragInfoA) + length(AFiles) + 1);
  if LHGlobal <> 0 then
  begin
    LInfo := GlobalLock(LHGlobal);
    if LInfo <> nil then
    begin
      LInfo.uSize := SizeOf(TDragInfoA);
      Move(AFiles[1], PChar(Cardinal(LInfo) + LInfo.uSize)^, length(AFiles));
      GlobalUnlock(LHGlobal);
      LRes := PostMessage(AWnd, WM_DROPFILES, LHGlobal, 0);
    end;
    if not(LRes) then
      GlobalFree(LHGlobal);
  end;
  result := LRes;
end;

function DropFilesOnWnd(AWnd: HWnd; AFiles: TStringlist): Boolean; overload;
begin
  result := DropFilesOnWnd(AWnd, StringReplace(AFiles.Text, #13#10, #0, [rfReplaceAll]));
end;
Allerdings funktioniert das ganze nur mit PostMessage. Sobald ich PostMessage durch SendMessage ersetze kommt bei der Ziel-Anwendung -1 als Dateianzahl an.
Jens
Mit Source ist es wie mit Kunst - Hauptsache der Künstler versteht's
  Mit Zitat antworten Zitat