Delphi-PRAXiS

Delphi-PRAXiS (https://www.delphipraxis.net/forum.php)
-   Win32/Win64 API (native code) (https://www.delphipraxis.net/17-win32-win64-api-native-code/)
-   -   Delphi Dateien in Zwischenablege kopieren (aber mit WideStrings!) (https://www.delphipraxis.net/143255-dateien-zwischenablege-kopieren-aber-mit-widestrings.html)

martinf16 12. Nov 2009 15:38


Dateien in Zwischenablege kopieren (aber mit WideStrings!)
 
Hallo,

mit dieser Prozedur kann ich Dateien in die Zwischenablage kopieren:

Delphi-Quellcode:
procedure CopyFilesToClipboard(FileList: string);
var
  DropFiles: PDropFiles;
  hGlobal: THandle;
  iLen: Integer;
begin
  iLen := Length(FileList) + 2;
  FileList := FileList + #0#0;
  hGlobal := GlobalAlloc(GMEM_SHARE or GMEM_MOVEABLE or GMEM_ZEROINIT,
    SizeOf(TDropFiles) + iLen);
  if (hGlobal = 0) then raise Exception.Create('Could not allocate memory.');
  begin
    DropFiles := GlobalLock(hGlobal);
    DropFiles^.pFiles := SizeOf(TDropFiles);
    Move(FileList[1], (PChar(DropFiles) + SizeOf(TDropFiles))^, iLen);
    GlobalUnlock(hGlobal);
    Clipboard.SetAsHandle(CF_HDROP, hGlobal);
  end;
end;
Nun hab ich aber einige Dateien im Format WideString, die Zeichen beinhalten, die nicht mit ANSI darstellbar sind. Ich habe nun schon einiges ausprobiert, zum Beispiel die Strings in WideStrings umbenannt oder es mit iLen := Length(Filelist)*SizeOf(WideChar) probiert, aber es passiert leider nichts.

Ich denke es ist eine Kleinigkeit die Funktion umzuschreiben, aber ich komm nicht drauf - vielleicht muss man die Konstanten ändern?! Bitte helft mir.. Danke.. :)

himitsu 12. Nov 2009 15:44

Re: Dateien in Zwischenablege kopieren (aber mit WideStrings
 
Ich würde dir dann wohl erstmal diese Lektüre empfehlen
http://www.codeproject.com/KB/shell/...rdragdrop.aspx

und auch noch die vom Hersteller persönlich (MSDN-Library durchsuchenCF_HDROP)
http://msdn.microsoft.com/en-us/libr....aspx#CF_HDROP

martinf16 13. Nov 2009 04:32

Re: Dateien in Zwischenablege kopieren (aber mit WideStrings
 
Ich habs:

Delphi-Quellcode:
procedure CopyFilesToClipboard(FileList: string);
var
  DropFiles: PDropFiles;
  hGlobal: THandle;
  iLen: Integer;
begin
  iLen := Length(FileList);
  hGlobal := GlobalAlloc(GMEM_SHARE or GMEM_MOVEABLE or GMEM_ZEROINIT, SizeOf(TDropFiles) + ((iLen + 2) * SizeOf(Char)));
  if (hGlobal = 0) then raise Exception.Create('Could not allocate memory.');
  try
    DropFiles := GlobalLock(hGlobal);
    try
      DropFiles^.pFiles := SizeOf(TDropFiles);
      DropFiles^.fWide := True;
 
      if FileList <> '' then
        Move(FileList[1], (PChar(DropFiles) + SizeOf(TDropFiles))^, iLen * SizeOf(Char));
    finally
      GlobalUnlock(hGlobal);
    end;
    Clipboard.SetAsHandle(CF_HDROP, hGlobal);
  except
    GlobalFree(hGlobal);
  end;
end;


Alle Zeitangaben in WEZ +1. Es ist jetzt 07:46 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