Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > de.comp.lang.delphi.misc > #19077

Re: Drop File per Code?

From Jens Köhler <jkoehl@web.de>
Newsgroups de.comp.lang.delphi.misc
Subject Re: Drop File per Code?
Date 2020-06-13 15:17 +0200
Organization solani.org
Message-ID <rc2jku$fct$1@solani.org> (permalink)
References <hki5fsFpt34U1@mid.individual.net>

Show all headers | View raw


Am 12.06.2020 um 22:05 schrieb Alfred Gemsa:
> Ich hätt' da mal ne Frage:
> 
> Ist es auch möglich, per Delphi-Code einer fremden laufenden Anwendung 
> einen File z.B. per ButtonClick "zu schicken"?
> 
> Gruß, Alfred.

und eine kurze Frage an Tante Google hat das ausgespuckt:

// uses ShlObj

procedure DoDropFiles(Wnd : HWND; Files : TStringList);

var
   Size      : Cardinal;
   DropFiles : PDropFiles;
   Run       : PChar;
   MemHandle : THandle;
   I         : Integer;

begin
   // first determine size of string buffer we have to allocate
   Size := 0;
   for I := 0 to Files.Count - 1 do
   begin
     // number of characters per string (as ANSI) plus one #0 terminator
     Inc(Size, Length(Files[I]) + 1);
   end;
   if Size > 0 then
   begin
     // entire string list is terminated by another #0, add drop files 
structure size too
     Inc(Size, 1 + SizeOf(TDropFiles));
     // allocate globally accessible memory
     MemHandle := GlobalAlloc(GHND or GMEM_SHARE, Size);
     DropFiles := GlobalLock(MemHandle);
     // fill the header
     with DropFiles^ do
     begin
       pFiles := SizeOf(TDropFiles); // offset of file list, it follows 
immediately the structure
       pt     := Point(0, 0);        // drop point (client coords), not 
important here
       fNC    := False;              // is it on NonClient area }, not 
important here
       fWide  := False;              // WIDE character switch, we pass 
ANSI string in this routine
     end;
     // and finally the file names
     Run := Pointer(DropFiles);
     Inc(Run, SizeOf(TDropFiles));
     for I := 0 to Files.Count - 1 do
     begin
       StrPCopy(Run, Files[I]);
       Inc(Run, Length(Files[I]));
     end;
     // put a final #0 character at the end
     Run^ := #0;
     // release the lock we have to the memory,...
     GlobalUnlock(MemHandle);
     // ...do the message...
     SendMessage(Wnd, WM_DROPFILES, MemHandle, 0);
     // ... and finally release the memory
     GlobalFree(MemHandle);
   end;  // if Size > 0
end;  // DoDropFiles

procedure TForm1.Button1Click(Sender: TObject);

var
   List : TStringList;
   wnd  : HWND;

begin

   wnd  := FindWindow('notepad', nil);
   if wnd <> 0 then;

   List := TStringList.Create;
   try
     List.Add('d:\Test.txt');
     DoDropFiles(wnd, List);
   finally
     List.Free;
   end;
end;

Jens

Back to de.comp.lang.delphi.misc | Previous | NextPrevious in thread | Next in thread | Find similar | Unroll thread


Thread

Drop File per Code? Alfred Gemsa <gemsa@gmx.de> - 2020-06-12 22:05 +0200
  Re: Drop File per Code? Jens Köhler <jkoehl@web.de> - 2020-06-13 10:16 +0200
  Re: Drop File per Code? Jens Köhler <jkoehl@web.de> - 2020-06-13 15:17 +0200
    Re: Drop File per Code? Alfred Gemsa <gemsa@gmx.de> - 2020-06-13 21:24 +0200
      Re: Drop File per Code? Alfred Gemsa <gemsa@gmx.de> - 2020-06-13 21:34 +0200
        Re: Drop File per Code? Jens Köhler <jkoehl@web.de> - 2020-06-14 09:11 +0200
          Re: Drop File per Code? Jens Köhler <jkoehl@web.de> - 2020-06-14 09:23 +0200
            Re: Drop File per Code? Alfred Gemsa <gemsa@gmx.de> - 2020-06-14 10:31 +0200

csiph-web