OWLNext    7.0
Borland's Object Windows Library for the modern age
Loading...
Searching...
No Matches
owl::TClipboard Class Reference

The clipboard class encapsulates the methods for the clipboard object of Windows. More...

#include <owl/clipboar.h>

Public Member Functions

 TClipboard (HWND hWnd, bool mustOpen=true)
 Constructs a clipboard object to grab the clipboard given a window handle.
 
 ~TClipboard ()
 Destruct a clipboard object & close the clipboard if open.
 
void CloseClipboard ()
 If the Clipboard is opened (IsOpen is true), closes the Clipboard.
 
bool OpenClipboard (HWND hWnd)
 Opens the Clipboard and associates it with the window specified in Wnd.
 
 operator bool () const
 Return true if the clipboard is currently owned by this application.
 
HANDLE GetClipboardData (uint format) const
 Retrieves data from the Clipboard in the format specified by format.The following formats are supported:
 
HWND GetOpenClipboardWindow () const
 Retrieves the handle of the window that currently has the Clipboard open.
 
HWND GetClipboardOwner () const
 Retrieves the handle of the window that currently owns the Clipboard, otherwise returns NULL.
 
HWND GetClipboardViewer () const
 Retrieves the handle of the first window in the Clipboard-view chain.
 
int GetClipboardFormatName (uint format, TCHAR *formatName, int maxCount) const
 Retrieves the name of the registered format specified by format and copies the format to the buffer pointed to by formatName.
 
int GetPriorityClipboardFormat (uint *priorityList, int count) const
 Returns the first Clipboard format in a list.
 
int CountClipboardFormats () const
 Returns a count of the number of types of data formats the Clipboard can use.
 
bool IsClipboardFormatAvailable (uint format) const
 Indicates if the format specified in format exists for use in the Clipboard.
 
bool EmptyClipboard ()
 Clears the Clipboard and frees any handles to the Clipboard's data.
 
uint RegisterClipboardFormat (const tstring &formatName) const
 Registers a new Clipboard format.
 
HANDLE SetClipboardData (uint format, HANDLE handle)
 Copy the data onto the clipboard in the format.
 
HWND SetClipboardViewer (HWND hWnd) const
 Adds the window specified by Wnd to the chain of windows that WM_DRAWCLIPBOARD notifies whenever the contents of the Clipboard change.
 

Static Public Attributes

static LPCTSTR DefaultProtocol = _T("StdFileEditing")
 Points to a string that specifies the name of the protocol the client needs.
 

Detailed Description

The clipboard class encapsulates the methods for the clipboard object of Windows.

TClipboard encapsulates and manipulates Clipboard data.

You can open, close, empty, and paste data in a variety of data formats between the Clipboard and the open window. An object on the Clipboard can exist in a variety of Clipboard formats, which range from bitmaps to text.

Usually, the window is in charge of manipulating Clipboard interactions between the window and the Clipboard. It does this by responding to messages sent between the Clipboard owner and the application. The following ObjectWindows event-handling functions encapsulate these Clipboard messages: EvRenderFormat - Responds to a WM_RENDERFORMAT message sent to the Clipboard owner if a specific Clipboard format that an application has requested hasn't been rendered. After the Clipboard owner renders the data in the requested format, it callsSetClipboardData to place the data on the Clipboard. EvRenderAllFormats - Responds to a message sent to the Clipboard owner if the Clipboard owner has delayed rendering a Clipboard format. After the Clipboard owner renders data in all of possible formats, it calls SetClipboardData.

The following example tests to see If there is a palette on the Clipboard. If one exists, TClipboard retrieves the palette, realizes it, and then closes the Clipboard.

if (clipboard.IsClipboardFormatAvailable(CF_PALETTE)) {
newPal = new TPalette(TPalette(clipboard)); // make a copy
}
// Try DIB format first
if (clipboard.IsClipboardFormatAvailable(CF_DIB)) {
newDib = new TDib(TDib(clipboard)); // make a copy
newBitmap = new TBitmap(*newDib, newPal); // newPal==0 is OK
// try metafile Second
//
} else if (clipboard.IsClipboardFormatAvailable(CF_METAFILEPICT)) {
if (!newPal)
newBitmap = new TBitmap(TMetaFilePict(clipboard), *newPal,
GetClientRect().Size());
...
// Gets a bitmap , keeps it, and sets up data on the clipboard.
//
delete Bitmap;
Bitmap = newBitmap;
if (!newDib)
newDib = new TDib(*newBitmap, newPal);
#endif // ????
delete Dib;
Dib = newDib;
delete Palette;
Palette = newPal ? newPal : new TPalette(*newDib);
Palette->GetObject(Colors);
PixelWidth = Dib->Width();
PixelHeight = Dib->Height();
SetCaption("(Clipboard)");
clipboard.CloseClipboard();
TBitmap is the GDI bitmap class derived from TGdiObject.
Definition gdiobjec.h:510
Pseudo-GDI object Device Independent Bitmap (DIB) class.
Definition gdiobjec.h:795
TPalette is the GDI Palette class derived from TGdiObject.
Definition gdiobjec.h:413

Definition at line 32 of file clipboar.h.

Constructor & Destructor Documentation

◆ TClipboard()

owl::TClipboard::TClipboard ( HWND hWnd,
bool mustOpen = true )

Constructs a clipboard object to grab the clipboard given a window handle.

This is the preferred method of getting the clipboard; Throws an exception on open failure if mustOpen is true (default) mustOpen can be passed as false for compatability

Definition at line 90 of file clipboar.cpp.

References OpenClipboard().

◆ ~TClipboard()

owl::TClipboard::~TClipboard ( )

Destruct a clipboard object & close the clipboard if open.

Definition at line 100 of file clipboar.cpp.

References CloseClipboard().

Member Function Documentation

◆ CloseClipboard()

void owl::TClipboard::CloseClipboard ( )

If the Clipboard is opened (IsOpen is true), closes the Clipboard.

Closing the Clipboard allows other applications to access the Clipboard.

Definition at line 111 of file clipboar.cpp.

References CloseClipboard().

◆ CountClipboardFormats()

int owl::TClipboard::CountClipboardFormats ( ) const
inline

Returns a count of the number of types of data formats the Clipboard can use.

Definition at line 224 of file clipboar.h.

◆ EmptyClipboard()

bool owl::TClipboard::EmptyClipboard ( )
inline

Clears the Clipboard and frees any handles to the Clipboard's data.

Returns true if the Clipboard is empty, or false if an error occurs.

Definition at line 255 of file clipboar.h.

◆ GetClipboardData()

HANDLE owl::TClipboard::GetClipboardData ( uint Format) const
inline

Retrieves data from the Clipboard in the format specified by format.The following formats are supported:

  • CF_BITMAP Data is a handle to a bitmap format
  • CF_DIB Data is memory bitmap with a BITMAPINFO structure
  • CF_DIBV5 Data is memory bitmap with a BITMAPV5HEADER structure
  • CF_DIF Data is in a Data Interchange Format (DIF).
  • CF_DSPBITMAP Data is a handle to a private bitmap format
  • CF_DSPENHMETAFILE Data is a handle to a private enhanced metafile.
  • CF_DSPMETAFILEPICT Data is in a private metafile format.
  • CF_DSPTEXT Data is in a private text format.
  • CF_ENHMETAFILE Data is a handle to an enhanced metafile.
  • CF_GDIOBJFIRST Data is the start of a range of integer values for application-defined GDI object clipboard formats.
  • CF_GDIOBJLAST Data is the last of a range of integer values for application-defined GDI object clipboard formats.
  • CF_HDROP Data is a handle to type HDROP that identifies a list of files.
  • CF_LOCALE Data is a handle to the locale identifier associated with the clipboard text.
  • CF_METAFILEPICT Data is in a metafile structure.
  • CF_OEMTEXT Data is an array of text characters in OEM character set.
  • CF_OWNERDISPLAT Data is in a special format that the application must display.
  • CF_PALETTE Data is in a color palette format.
  • CF_PENDATA Data is used for pen format.
  • CF_PRIVATEFIRST Data is the start of a range of integer values for private clipboard formats.
  • CF_PRIVATELAST Data is the last of a range of integer values for private clipboard formats.
  • CF_RIFF Data is in Resource Interchange File Format (RIFF).
  • CF_SYLK Data is in symbolic Link format (SYLK).
  • CF_TEXT Data is stored as an array of text characters.
  • CF_TIFF Data is in Tag Image File Format (TIFF).
  • CF_UNICODETEXT Data is stored as an array of Unicode text characters.
  • CF_WAVE Data is in a sound wave format.

Definition at line 173 of file clipboar.h.

◆ GetClipboardFormatName()

int owl::TClipboard::GetClipboardFormatName ( uint Format,
TCHAR * FormatName,
int MaxCount ) const
inline

Retrieves the name of the registered format specified by format and copies the format to the buffer pointed to by formatName.

maxCount specifies the maximum length of the name of the format. If the name is longer than maxCount, it is truncated.

Definition at line 208 of file clipboar.h.

◆ GetClipboardOwner()

HWND owl::TClipboard::GetClipboardOwner ( ) const
inline

Retrieves the handle of the window that currently owns the Clipboard, otherwise returns NULL.

Definition at line 190 of file clipboar.h.

◆ GetClipboardViewer()

HWND owl::TClipboard::GetClipboardViewer ( ) const
inline

Retrieves the handle of the first window in the Clipboard-view chain.

Returns NULL if there is no viewer.

Definition at line 198 of file clipboar.h.

◆ GetOpenClipboardWindow()

HWND owl::TClipboard::GetOpenClipboardWindow ( ) const
inline

Retrieves the handle of the window that currently has the Clipboard open.

If the Clipboard is not open, the return value is NULL. Once the Clipboard is opened, applications cannot modify the data.

Definition at line 182 of file clipboar.h.

◆ GetPriorityClipboardFormat()

int owl::TClipboard::GetPriorityClipboardFormat ( uint * priorityList,
int count ) const
inline

Returns the first Clipboard format in a list.

priorityList points to an array that contains a list of the Clipboard formats arranged in order of priority. See GetClipboardData for the Clipboard formats.

Definition at line 217 of file clipboar.h.

◆ IsClipboardFormatAvailable()

bool owl::TClipboard::IsClipboardFormatAvailable ( uint format) const
inline

Indicates if the format specified in format exists for use in the Clipboard.

See GetClipBoardData for a description of Clipboard data formats. The following code tests if the Clipboard can support the specified formats:

void
TBmpViewWindow::CePaste(TCommandEnabler& ce)
{
TClipboard& clipboard = OpenClipboard();
ce.Enable(
clipboard && (
)
);
clipboard.CloseClipboard();
The clipboard class encapsulates the methods for the clipboard object of Windows.
Definition clipboar.h:32
bool OpenClipboard(HWND hWnd)
Opens the Clipboard and associates it with the window specified in Wnd.
Definition clipboar.cpp:125
bool IsClipboardFormatAvailable(uint format) const
Indicates if the format specified in format exists for use in the Clipboard.
Definition clipboar.h:247
void CloseClipboard()
If the Clipboard is opened (IsOpen is true), closes the Clipboard.
Definition clipboar.cpp:111
Base class for an extensible interface for auto enabling/disabling of commands (menu items,...
Definition window.h:209

Definition at line 247 of file clipboar.h.

◆ OpenClipboard()

bool owl::TClipboard::OpenClipboard ( HWND hWnd)

Opens the Clipboard and associates it with the window specified in Wnd.

Other applications cannot change the Clipboard data until the Clipboard is closed. Returns true if successful; otherwise, returns false.

Definition at line 125 of file clipboar.cpp.

References OpenClipboard().

◆ operator bool()

owl::TClipboard::operator bool ( ) const
inline

Return true if the clipboard is currently owned by this application.

Definition at line 139 of file clipboar.h.

◆ RegisterClipboardFormat()

uint owl::TClipboard::RegisterClipboardFormat ( const tstring & formatName) const
inline

Registers a new Clipboard format.

formatName points to a character string that identifies the new format. If the format can be registered, the return value indicates the registered format. If the format can't be registered, the return value is 0. Once the format is registered, it can be used as a valid format in which to render the data.

Definition at line 266 of file clipboar.h.

◆ SetClipboardData()

HANDLE owl::TClipboard::SetClipboardData ( uint Format,
HANDLE Handle )
inline

Copy the data onto the clipboard in the format.

Sets a handle to the block of data at the location indicated by handle. format specifies the format of the data block. The Clipboard must have been opened before the data handle is set. format can be any one of the valid Clipboard formats (for example, CF_BITMAP or CF_DIB). See GetClipboardData for a list of these formats. handle is a handle to the memory location where the data data is stored. If successful, the return value is a handle to the data; if an error occurs, the return value is 0. Before the window is updated with the Clipboard data, the Clipboard must be closed.

Definition at line 282 of file clipboar.h.

◆ SetClipboardViewer()

HWND owl::TClipboard::SetClipboardViewer ( HWND hWnd) const
inline

Adds the window specified by Wnd to the chain of windows that WM_DRAWCLIPBOARD notifies whenever the contents of the Clipboard change.

Definition at line 290 of file clipboar.h.

Member Data Documentation

◆ DefaultProtocol

LPCTSTR owl::TClipboard::DefaultProtocol = _T("StdFileEditing")
static

Points to a string that specifies the name of the protocol the client needs.

The default protocol is "StdFileEditing," which is the name of the object linking and embedding protocol.

Definition at line 77 of file clipboar.h.


The documentation for this class was generated from the following files: