OK All I think it's time for a recap.
1. Get a clipboard viewer. I use
https://www.freeclipboardviewer.com/FreeClipViewer.zip2. Run the program.
3. Open Explorer, and find an image file and copy it to the clipboard.
4. Note the changes in the clipboard viewer.
5. Open Wordpad. You should be able to paste the previously copied image into Wordpad.
6. My opening question was
Hi All,
How do I copy a file to the clipboard?
To which it was suggested to try the following code
procedure CopyFileToClipboard(FileList : string);
var
DropFiles: PDropFiles;
hGlobal: THandle;
iLen: integer;
CFSTR_FILEDESCRIPTOR, CFSTR_FILECONTENTS : UINT;
begin
//CFSTR_FILEDESCRIPTOR := RegisterClipboardFormat();
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);
OpenClipboard(Form1.Handle);
EmptyClipboard;
SetClipboardData(CF_HDROP, hGlobal);
CloseClipboard;
end;
end;
procedure TForm1.Button1Click(Sender: TObject);
begin
CopyFileToClipboard('d:\Lazarus\Icons\bug-64.ico');
end;
Which copies a list of files to the clipboard. Which is NOT what I need.
I need a way to copy the file as in step 1.
I was advised to look at
https://docs.microsoft.com/en-us/windows/win32/controls/using-rich-edit-com which looks promising but I don't speak 'C'.