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 copy an image and text to the clipboard at the same time 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
copy an image and text to the clipboard at the same time 29-Jul-04
Category
Win API
Language
Delphi 3.x
Views
203
User Rating
No Votes
# Votes
0
Replies
0
Publisher:
DSP, Administrator
Reference URL:
DKB
			Author: Harley Pebley 

How to copy an image and text to the clipboard at the same time

Answer:

The clipboard can have multiple items in different formats on it. However, you need 
to add the various items to the clipboard using API functions rather than the 
Delphi object wrappers. The Delphi wrappers assume they are the only item on the 
clipboard and clear everything else off. The following shows one way to put both a 
bitmap and text on the clipboard.

1   { ... }
2   var
3     lBmpFmt: TBMPExportFormat;
4     lTmpBmp: Graphics.TBitmap;
5     lData: THandle;
6     lFormat: Word;
7     lPalette: HPALETTE;
8     lTxtFmt: TSeriesDataText;
9     Data: THandle;
10    DataPtr: Pointer;
11    lTxt: PChar;
12  begin
13    Clipboard.Open;
14    try
15      {Make sure the clipboard is cleared every time. Someone may have put some
16      other formats on it that hide the things we're going to put on it (since 
17  		there's a search protocol for appropriate types and our types may be lower
18      in the protocol and so not be found when it comes time to paste).}
19      Clipboard.Clear;
20      {Save as a bitmap}
21      lBmpFmt := TBMPExportFormat.Create;
22      try
23        lBmpFmt.Panel := Self;
24        lTmpBmp := lBmpFmt.Bitmap;
25        try
26          lPalette := 0;
27          lTmpBmp.SaveToClipboardFormat(lFormat, lData, lPalette);
28          SetClipboardData(lFormat, lData);
29          if lPalette <> 0 then
30            SetClipboardData(CF_PALETTE, lPalette);
31        finally
32          lTmpBmp.Free;
33        end;
34      finally
35        lBmpFmt.Free;
36      end;
37      {Save as text}
38      lTxtFmt := TSeriesDataText.Create(Self);
39      try
40        lTxt := PChar(lTxtFmt.AsString);
41      finally
42        lTxtFmt.Free;
43      end;
44      Data := GlobalAlloc(GMEM_MOVEABLE + GMEM_DDESHARE, StrLen(lTxt) + 1);
45      try
46        DataPtr := GlobalLock(Data);
47        try
48          Move(lTxt^, DataPtr^, StrLen(lTxt) + 1);
49          if SetClipboardData(CF_TEXT, Data) = 0 then
50            ShowMessage(SysErrorMessage(GetLastError));
51        finally
52          GlobalUnlock(Data);
53        end;
54      except
55        GlobalFree(Data);
56        raise;
57      end;
58    finally
59      Clipboard.Close;
60    end;
61  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