Lazy WinAPI
Macros | Functions
Clipboard

Provides utilities to acess Windows Clipboard. More...

Macros

#define Clipboard_get_seq_num()   GetClipboardSequenceNumber()
 Alias to GetClipboardSequenceNumber(). More...
 
#define Clipboard_next_avail_format()   EnumClipboardFormats(0)
 Alias to EnumClipboardFormats(0). More...
 
#define Clipboard_count_avail_formats()   CountClipboardFormats()
 Alias to CountClipboardFormats(). More...
 

Functions

bool Clipboard_open ()
 Opens clipboard for use in the current thread. More...
 
bool Clipboard_close ()
 Closes clipboard. More...
 
bool Clipboard_empty ()
 Empties clipboard. More...
 
size_t Clipboard_get_size (UINT format)
 Retrieves size in bytes of clipboard content. More...
 
size_t Clipboard_get (UINT format, uint8_t *ptr, size_t size)
 Gets clipboard content of specific format. More...
 
bool Clipboard_set (UINT format, const uint8_t *ptr, size_t size)
 Sets clipboard content of specific format. More...
 
bool Clipboard_set_wide_string (const wchar_t *text)
 Sets string onto clipboard as format CF_UNICODETEXT. More...
 
bool Clipboard_set_string (const char *text)
 Sets wide string onto clipboard as format CF_TEXT. More...
 
bool Clipboard_is_format_avail (UINT format)
 
UINT Clipboard_register_format (const wchar_t *name)
 Registers new clipboard format. More...
 
int Clipboard_get_format_name (UINT format, wchar_t *buffer, size_t size)
 Retrieves the name of clipboard format. More...
 

Detailed Description

Provides utilities to acess Windows Clipboard.

Warning
Access to Clipboard from multiple threads isn't safe.

General information

Open clipboard

To access any information inside clipboard it is necessary to open it by means of Clipboard_open().

After that Clipboard cannot be opened anymore until Clipboard_close() is called.

Examples

Depending on the way of installation header can be included either as clipboard.h or lazy_winapi/clipboard.h.

Get current text on clipboard

#include "clipboard.h"
const DWORD format = CF_TEXT;
char extract_text[50] = {0};
Clipboard_get(format, (uint8_t*)extract_text, sizeof(extract_text));
printf("Content of clipboard=%s\n", extract_text);
}
else {
printf("No text on clipboard... \n");
}

Get current unicode text on clipboard

#include "clipboard.h"
const DWORD format = CF_UNICODETEXT;
wchar_t extract_text[50] = {0};
Clipboard_get(format, (uint8_t*)extract_text, sizeof(extract_text));
printf("Content of clipboard=%ls\n", extract_text);
}
else {
printf("No unicode on clipboard... \n");
}

Set text onto clipboard

#include "clipboard.h"
const DWORD format = CF_TEXT;
const char text[] = "For my waifu!";

Set unicode text onto clipboard

#include "clipboard.h"
const DWORD format = CF_UNICODETEXT;
const wchar_t text[] = L"For my waifu!";

Raw set onto clipboard

#include "clipboard.h"
const DWORD format = CF_TEXT
const unit8_t data[] = {1, 2, 3, 4, 5, 0};
Clipboard_set(format, data, sizeof(data));

Use own clipboard format.

#include "clipboard.h"
const wchar_t format_name[] = L"testing";
const UINT format = Clipboard_register_format(format_name);
const uint8_t data[] = {1, 2, 3, 55, 2};
printf("Got ID=%u for my format\n", format);
if (Clipboard_set(format, data, sizeof(data))) {
printf("Successfully set data to my clipboard format.\n");
}
else {
printf("Failed to set data :(\n");
}

Macro Definition Documentation

#define Clipboard_count_avail_formats ( )    CountClipboardFormats()

Alias to CountClipboardFormats().

Returns
Number of formats currently available on clipboard.
#define Clipboard_get_seq_num ( )    GetClipboardSequenceNumber()

Alias to GetClipboardSequenceNumber().

Returns
Current value of clipboard sequence number.
Return values
0If you do not have WINSTA_ACCESSCLIPBOARD access.
#define Clipboard_next_avail_format ( )    EnumClipboardFormats(0)

Alias to EnumClipboardFormats(0).

Note
Can be called only after Clipboard_open().
Returns
Next available clipboard format.
Return values
0On failure or if there is no more formats.

Function Documentation

bool Clipboard_close ( )

Closes clipboard.

Note
Can be called only after Clipboard_open()
Return values
trueOn success.
falseOn failure.
bool Clipboard_empty ( )

Empties clipboard.

Note
Can be called only after Clipboard_open().
Return values
trueOn success.
falseOn failure.
size_t Clipboard_get ( UINT  format,
uint8_t *  ptr,
size_t  size 
)

Gets clipboard content of specific format.

Note
Can be called only after Clipboard_open().
Parameters
[in]formatFormat of clipboard to retrieve.
[out]ptrMemory to hold content of clipboard.
[in]sizeSize of memory to hold content. Content is truncated by this size if necessary.
Returns
Number of copied bytes.
Return values
0On failure.
int Clipboard_get_format_name ( UINT  format,
wchar_t *  buffer,
size_t  size 
)

Retrieves the name of clipboard format.

Parameters
[in]formatFormat identifier.
[out]bufferMemory to hold name.
[in]sizeNumber of characters to write in buffer. Including null char.
Returns
Number of characters written. Excluding null char.
Return values
0On failure.
size_t Clipboard_get_size ( UINT  format)

Retrieves size in bytes of clipboard content.

GlobalSize is used to determine size of content.

Note
Can be called only after Clipboard_open().
Parameters
[in]formatFormat of clipboard to retrieve.
Returns
Size of clipboard content in bytes.
Return values
0Clipboard doesn't hold data of such format.
bool Clipboard_is_format_avail ( UINT  format)
Parameters
[in]formatClipboard format identifier.
Return values
trueSpecified format presents on clipboard.
falseOtherwise.
bool Clipboard_open ( )

Opens clipboard for use in the current thread.

Return values
trueOn success.
falseOn failure.
UINT Clipboard_register_format ( const wchar_t *  name)

Registers new clipboard format.

If format with such name already exists, its identifier is returned.

Parameters
[in]nameNew format's name.
Returns
Identifier of new format.
Return values
0On failure.
bool Clipboard_set ( UINT  format,
const uint8_t *  ptr,
size_t  size 
)

Sets clipboard content of specific format.

Note
Can be called only after Clipboard_open().
Parameters
[in]formatFormat of clipboard to retrieve.
[in]ptrData to set.
[in]sizeSize of data to set.
Return values
trueOn success.
falseOn failure.
bool Clipboard_set_string ( const char *  text)

Sets wide string onto clipboard as format CF_TEXT.

Note
Can be called only after Clipboard_open().
Parameters
[in]textUnicode string to set.
Return values
trueOn success.
falseOn failure.
bool Clipboard_set_wide_string ( const wchar_t *  text)

Sets string onto clipboard as format CF_UNICODETEXT.

Note
Can be called only after Clipboard_open().
Parameters
[in]textString to set.
Return values
trueOn success.
falseOn failure.