ImageEn for Delphi and C++ Builder ImageEn for Delphi and C++ Builder

 

ImageEn Forum
Profile    Join    Active Topics    Forum FAQ    Search this forumSearch
Forum membership is Free!  Click Join to sign-up
Username:
Password:
Save Password
Forgot your Password?

 All Forums
 ImageEn Library for Delphi, C++ and .Net
 ImageEn and IEvolution Support Forum
 How to add specific custom information to Clipboard
 New Topic  Reply to Topic
Author Previous Topic Topic Next Topic  

PeterPanino

561 Posts

Posted - Jul 15 2021 :  08:44:41  Show Profile  Reply
From a TIEBitmap, I copy to the clipboard with this code:

MyIEBitmap.CopyToClipboard(True, True);


Together with this copy action, is it possible to additionally add some unique ID to the clipboard content, for example:

A specific custom Clipboard Format?
A specific textual information inside the clipboard "IMAGEEN RAW FORMAT"?

The purpose is: I need to unambiguously identify the clipboard content created with the above copy action.

PS: Please allow longer posting titles.

PeterPanino

561 Posts

Posted - Jul 15 2021 :  10:28:16  Show Profile  Reply
I've tried this workaround, but it does not work and even blocks MyIEBitmap.CopyToClipboard to copy to the clipboard:

procedure SetBuffer(Format: Word; const Buffer; Size: Integer);
var
  DataPtr: Pointer;
  Data: THandle;
begin
  Data := GlobalAlloc(GMEM_MOVEABLE+GMEM_DDESHARE, Size);
  try
    DataPtr := GlobalLock(Data);
    try
      Move(Buffer, DataPtr^, Size);
      Win32Check(SetClipboardData(Format, Data) <> 0);
    finally
      GlobalUnlock(Data);
    end;
  except
    GlobalFree(Data);
    raise;
  end;
end;

Clipboard.Open;
try
  MyIEBitmap.CopyToClipboard(True, True);
  const ThisID: string = 'UniqueID';
  SetBuffer(CF_UNICODETEXT, Text[1], ByteLength(ThisID));
finally
  Clipboard.Close;
end;


Go to Top of Page

PeterPanino

561 Posts

Posted - Jul 15 2021 :  12:04:50  Show Profile  Reply
This seems to work:

Clipboard.Open;
try
  Clipboard.Assign(MyIEBitmap.VclBitmap);
  Clipboard.AsText := 'MyUniqueID';
finally
  Clipboard.Close;
end;


Is this correct and can this be optimized?
Go to Top of Page

xequte

6248 Posts

Posted - Jul 15 2021 :  19:26:08  Show Profile  Reply
Hi Peter

If you copy a layer (image), then its associated meta-data is copied. This is not done for bitmap raw format.

You might want to create your own clipboard format to handle it (raw image + string). There will be examples on the internet to do this. The code in your final example may work as long as you are the only one to use the clipboard data (i.e. cannot guarantee how third party apps will perform when there is both text and an image on the clipboard).

I've lifted the subject length limitation.

Nigel
Xequte Software
www.imageen.com
Go to Top of Page

PeterPanino

561 Posts

Posted - Jul 16 2021 :  05:36:17  Show Profile  Reply
Hi Nigel

Thank you for lifting the subject length limitation.

I have tested with several applications (including my own app that uses ImageEn): None of them has a problem with pasting a clipboard image with an additional text format on the clipboard.
Go to Top of Page
  Previous Topic Topic Next Topic  
 New Topic  Reply to Topic
Jump To: