Articles   Members Online:
-Article/Tip Search
-News Group Search over 21 Million news group articles.
-Delphi/Pascal
-CBuilder/C++
-C#Builder/C#
-JBuilder/Java
-Kylix
Member Area
-Home
-Account Center
-Top 10 NEW!!
-Submit Article/Tip
-Forums Upgraded!!
-My Articles
-Edit Information
-Login/Logout
-Become a Member
-Why sign up!
-Newsletter
-Chat Online!
-Indexes NEW!!
Employment
-Build your resume
-Find a job
-Post a job
-Resume Search
Contacts
-Contacts
-Feedbacks
-Link to us
-Privacy/Disclaimer
Embarcadero
Visit Embarcadero
Embarcadero Community
JEDI
Links
How to register your own clipboard format Turn on/off line numbers in source code. Switch to Orginial background IDE or DSP color Comment or reply to this aritlce/tip for discussion. Bookmark this article to my favorite article(s). Print this article
08-Oct-02
Category
Win API
Language
Delphi 6.x
Views
113
User Rating
No Votes
# Votes
0
Replies
0
Publisher:
DSP, Administrator
Reference URL:
DKB
			Author: Jonas Bilinkevicius 

I want to write raw bytes to the clipboard, but the only functions the TClipboard 
component offers are SetText, SetAsHandle and SetComponent. Well, I need to set 
these bytes as a certain format (566 to be exact), so that rules out SetText. 
SetAsHandle didn't seem to work when I tried it, and I have no idea how 
SetComponent would do anything for me. The help files included with Delphi (6) 
weren't overly helpful in explaining how to use this class in any way, other than 
copying text and pictures.

Answer:

Here is an example:

1   uses
2     Clipbrd;
3   const
4     MyFormatName = 'My Junk Clipboard Format';
5     MySource: PChar = 'hello';
6   var
7     MyFormat: Word;
8     MySize: Integer;
9     MyMemory: THandle;
10    MyBuffer: Pointer;
11  begin
12    MyFormat := RegisterClipboardFormat(MyFormatName);
13    {Determine the size of the data to be copied. 
14  	StrLen does not count the null terminator.
15    So add one byte to be sure it will be pasted correctly as PChar.}
16    MySize := StrLen(MySource) + 1;
17    {Allocate memory for passing data to the clipboard.}
18    MyMemory := GlobalAlloc(GMEM_MOVEABLE, MySize);
19    try
20      {Copy data to the memory}
21      MyBuffer := GlobalLock(MyMemory);
22      try
23        Move(MySource^, MyBuffer^, MySize);
24      finally
25        GlobalUnlock(MyMemory);
26      end;
27      {Call TClipboard.SetAsHandle}
28      Clipboard.SetAsHandle(MyFormat, MyMemory);
29    except
30      GlobalFree(MyMemory);
31      raise;
32    end;
33  end;


			
Vote: How useful do you find this Article/Tip?
Bad Excellent
1 2 3 4 5 6 7 8 9 10

 

Advertisement
Share this page
Advertisement
Download from Google

Copyright © Mendozi Enterprises LLC