was ist neu ¦  programmier tips ¦  indy artikel ¦  intraweb artikel ¦  informationen ¦  links ¦  interviews
 sonstiges ¦  tutorials ¦  Add&Win Gewinnspiel

Tips (1541)

Dateien (137)
Datenbanken (90)
Drucken (35)
Grafik (114)
IDE (21)
Indy (5)
Internet / LAN (130)
IntraWeb (0)
Mathematik (76)
Multimedia (45)
Oberfläche (107)
Objekte/
ActiveX (51)

OpenTools API (3)
Sonstiges (126)
Strings (83)
System (266)
VCL (242)

Tips sortiert nach
Komponente


Tip suchen

Tip hinzufügen

Add&Win Gewinnspiel

Werbung

32 Visitors Online


 
...Dateien an ein Fremdprogramm per drag&drop senden?
Autor: Hagen Reddmann
[ Tip ausdrucken ]  

Tip Bewertung (11):  
     


uses
  ShellAPI;

function MakeDrop(const FileNames: array of string): THandle;
// Creates a hDrop Object
// erzeugt ein hDrop Object
var
  I, Size: Integer;
  Data: PDragInfoA;
  P: PChar;
begin
  // Calculate memory size needed
  // berechne notwendig Speichergröße
  Size := SizeOf(TDragInfoA) + 1;
  for I := 0 to High(FileNames) do
    Inc(Size, Length(FileNames[I]) + 1);
  // allocate the memory
  // alloziere den speicher
  Result := GlobalAlloc(GHND or GMEM_SHARE, Size);
  if Result <> 0 then
  begin
    Data := GlobalLock(Result);
    if Data <> nil then
      try
        // fill up with data
        // fülle daten
        Data.uSize := SizeOf(TDragInfoA);
        P  := PChar(@Data.grfKeyState) + 4;
        Data.lpFileList := P;
        // filenames at the at of the header (separated with #0)
        // am ende des headers nun die filenamen getrennt mit #0
        for I := 0 to High(FileNames) do
        begin
          Size := Length(FileNames[I]);
          Move(Pointer(FileNames[I])^, P^, Size);
          Inc(P, Size + 1);
        end;
      finally
        GlobalUnlock(Result);
      end
    else
    begin
      GlobalFree(Result);
      Result := 0;
    end;
  end;
end;

function MyEnum(Wnd: hWnd; Res: PInteger): Bool; stdcall;
// search for a edit control with classname 'TEditControl'
// suche ein child fenster mit klassennamen 'TEditControl'
var
  N: string;
begin
  SetLength(N, MAX_PATH);
  SetLength(N, GetClassName(Wnd, Pointer(N), Length(N)));
  Result := AnsiCompareText('TEditControl', N) <> 0;
  if not Result then Res^ := Wnd;
end;

// Example: Open msdos.sys in Delphi's Editor window
// Beispiel: msdos.sys im Delphi Editor öffnen
procedure TForm1.Button1Click(Sender: TObject);
var
  Wnd: HWnd;
  Drop: hDrop;
begin
  // search for Delphi's Editor
  // suche Delphis Editor Fenster
  EnumChildWindows(FindWindow('TEditWindow', nil), @MyEnum, Integer(@Wnd));
  if IsWindow(Wnd) then
  begin
    // Delphi's Editor found. Open msdos.sys
    // Delphis editor gefunden, also öffne msdos.sys
    Drop := MakeDrop(['c:\msdos.sys']);
    if Drop <> 0 then PostMessage(Wnd, wm_DropFiles, Drop, 0);
    // Free the memory?
    // Speicher wieder freigeben?
    GlobalFree(Drop);
  end;
end;

 

Bewerten Sie diesen Tipp:

dürftig
ausgezeichnet


Copyright © by SwissDelphiCenter.ch
All trademarks are the sole property of their respective owners