Identify all available formats on the Clipboard

Source: Internet
Author: User

Note: This article in the original program for VB writing. The old demon changed to CB version.

If you want to know if the Clipboard contains data from Excel, or if you want to determine if the rich Text format can be used to activate the Paste menu, the following procedure can tell you how to identify all available formats, including custom formats, on the current clipboard.

Unit1.cpp started-----------------
//---------------------------------------------------------------------------
#include <vcl.h>
#pragma hdrstop
#include "Unit1.h"
//---------------------------------------------------------------------------
#pragma package (smart_init)
#pragma resource "*.DFM"
TForm1 *form1;
The known clipboard data format is as follows:
Char *strclipboardformats[17]={"Cf_text", "Cf_bitmap", "Cf_metafilepict", "Cf_sylk",
"Cf_dif", "Cf_tiff", "Cf_oemtext", "Cf_dib", "Cf_palette",
"Cf_pendata", "Cf_riff", "Cf_wave", "Cf_unicodetext",
"Cf_enhmetafile", "Cf_hdrop", "Cf_locale", "Cf_max"};
Get the name of a custom data format
String getunknownformatname (long Lformatid);
//---------------------------------------------------------------------------
__fastcall Tform1::tform1 (tcomponent* Owner)
: Tform (Owner)
{
}
//---------------------------------------------------------------------------
void __fastcall Tform1::button1click (tobject *sender)
{
int LR;
int icount;
Listbox1->items->clear ();

if (OpenClipboard (Handle))
{
Try
{
Lr=enumclipboardformats (0);
if (lr!=0)
{
Todo
{
icount++;
if (lr<18)
Listbox1->items->add (STRCLIPBOARDFORMATS[LR]);
Else
Listbox1->items->add (Getunknownformatname (LR));
LR = Enumclipboardformats (LR);
}while (lr!=0);
}
}
catch (...)
{
CloseClipboard ();
}
}
CloseClipboard ();
}
//---------------------------------------------------------------------------
String getunknownformatname (Long Lformatid)
{
For custom formats, we can register names with the Clipboard:
Char strbuf[255];
Long LR;
LR = Getclipboardformatname (lformatid,strbuf,255);
if (lr!=0)
Return String (STRBUF);
Else
Return "-----None-------";
}
---------the end of the program--------------------

When you click the button, all available clipboard data formats are added to the listbox. The list area is set to the format name, and the data for each row is set to the ID of the Clipboard format. To see a custom format in the list, try copying something from Word, WordPad, or IE before clicking the button.

---test environment: W2K ADV Server + SP3

BCB 6.0 + SP3

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.