Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

binary clipboard data

Status
Not open for further replies.

cfxdel

Programmer
Jul 28, 2007
3
GB
I'm using Delphi 4 and want to write a program which uses clipboard data produced by another application.

The data seems to be some kind of custom clipboard format.

I don't know how the data is formatted or how large the data is, so I would like to just get a binary copy of the data to analyse it.

I can say that running this code:
for I := 0 to Clipboard.FormatCount-1 do
ListBox1.Items.Add(IntToStr(Clipboard.Formats));
produces this list:

49161
49683
1
49171
16
7
13

How do you obtain a complete binary data copy of everything on the clipboard ?

 
Found what I needed:

The following url has a set of procedures which uses a stream to dump the binary contents of the clipboard to a file, which can then be viewed with a hex editor.


Also useful for analysing the clipboard are the programs "clipboard viewer X" and "cbdump" at:


and



Now I just need to figure out how the application I'm using has actually encoded data on the clipboard.
 
You'll find everything you need to know in the delphi help file. Search for topic "TClipboard". Be sure to add "Clipbrd" to your uses clause. Add a global var ClipBoard: TClipBoard;
Clipboard.Formats is an array (0..Clipboard.FormatCount-1) of integer.

Helpful constants from Windows.pas:
CF_TEXT = 1;
CF_BITMAP = 2;
CF_METAFILEPICT = 3;
CF_SYLK = 4;
CF_DIF = 5;
CF_TIFF = 6;
CF_OEMTEXT = 7;
CF_DIB = 8;
CF_PALETTE = 9;
CF_PENDATA = 10;
CF_RIFF = 11;
CF_WAVE = 12;
CF_UNICODETEXT = 13;
CF_ENHMETAFILE = 14;
CF_HDROP = 15;
CF_LOCALE = $10;
CF_MAX = 17;
CF_DIBV5 = 17;
CF_MAX_XP = 18;

Example usage:
Code:
procedure TForm1.Button1Click(Sender: TObject);
begin
if Clipboard.HasFormat(CF_TEXT) then
  Edit1.Text := Clipboard.AsText
else
  MessageDlg('There is no text on the Clipboard', mtInformation, [mbOK], 0);
end;

HTH

Roo
Delphi Rules!
 
This should tell you what format type you are dealing with:
Code:
for I := 0 to Clipboard.FormatCount-1 do
  case i of 
    0: ListBox1.Items.Add('unknown ' + IntToStr(Clipboard.Formats[I]));
    1: ListBox1.Items.Add('TEXT ' + IntToStr(Clipboard.Formats[I]));
    2: ListBox1.Items.Add('BITMAP ' + IntToStr(Clipboard.Formats[I]));
    3: ListBox1.Items.Add('METAFILEPICT ' + IntToStr(Clipboard.Formats[I]));
    4: ListBox1.Items.Add('SYLK ' + IntToStr(Clipboard.Formats[I]));
    5: ListBox1.Items.Add('DIF ' + IntToStr(Clipboard.Formats[I]));
    6: ListBox1.Items.Add('TIFF ' + IntToStr(Clipboard.Formats[I]));
    7: ListBox1.Items.Add('OEMTEXT ' + IntToStr(Clipboard.Formats[I]));
    8: ListBox1.Items.Add(DIB ' + IntToStr(Clipboard.Formats[I]));
    9: ListBox1.Items.Add('PALETTE ' + IntToStr(Clipboard.Formats[I]));
    10: ListBox1.Items.Add('PENDATA ' + IntToStr(Clipboard.Formats[I]));
    11: ListBox1.Items.Add('RIFF ' + IntToStr(Clipboard.Formats[I]));
    12: ListBox1.Items.Add('WAVE ' + IntToStr(Clipboard.Formats[I]));
    13: ListBox1.Items.Add('UNICODETEXT ' + IntToStr(Clipboard.Formats[I]));
    14: ListBox1.Items.Add('ENHMETAFILE ' + IntToStr(Clipboard.Formats[I]));
    15: ListBox1.Items.Add('HDROP ' + IntToStr(Clipboard.Formats[I]));
    16: ListBox1.Items.Add('LOCALE ' + IntToStr(Clipboard.Formats[I]));
    17: ListBox1.Items.Add('DIBV5 ' + IntToStr(Clipboard.Formats[I]));
  end; //case

Roo
Delphi Rules!
 
Roo, I have already responded to my original post to say that I have found what I needed and given a link to a page with the answer. Your post does not answer the question of handling custom formats and neither does the help file as you suggest.
 
Sorry, I read your post rather quickly and had the code at hand for another assist. I hoped that knowing the clip format type would assist. Perhaps someone else will find the info helpful. :p
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top