Provides utilities to acess Windows Clipboard.
More...
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
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
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
const DWORD format = CF_TEXT;
const char text[] = "For my waifu!";
Set unicode text onto clipboard
const DWORD format = CF_UNICODETEXT;
const wchar_t text[] = L"For my waifu!";
Raw set onto clipboard
const DWORD format = CF_TEXT
const unit8_t data[] = {1, 2, 3, 4, 5, 0};
Use own clipboard format.
const wchar_t format_name[] = L"testing";
const uint8_t data[] = {1, 2, 3, 55, 2};
printf("Got ID=%u for my format\n", format);
printf("Successfully set data to my clipboard format.\n");
}
else {
printf("Failed to set data :(\n");
}
#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
-
0 | If 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
-
0 | On failure or if there is no more formats. |
Closes clipboard.
- Note
- Can be called only after Clipboard_open()
- Return values
-
true | On success. |
false | On failure. |
Empties clipboard.
- Note
- Can be called only after Clipboard_open().
- Return values
-
true | On success. |
false | On 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] | format | Format of clipboard to retrieve. |
[out] | ptr | Memory to hold content of clipboard. |
[in] | size | Size of memory to hold content. Content is truncated by this size if necessary. |
- Returns
- Number of copied bytes.
- Return values
-
int Clipboard_get_format_name |
( |
UINT |
format, |
|
|
wchar_t * |
buffer, |
|
|
size_t |
size |
|
) |
| |
Retrieves the name of clipboard format.
- Parameters
-
[in] | format | Format identifier. |
[out] | buffer | Memory to hold name. |
[in] | size | Number of characters to write in buffer. Including null char. |
- Returns
- Number of characters written. Excluding null char.
- Return values
-
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] | format | Format of clipboard to retrieve. |
- Returns
- Size of clipboard content in bytes.
- Return values
-
0 | Clipboard doesn't hold data of such format. |
bool Clipboard_is_format_avail |
( |
UINT |
format | ) |
|
- Parameters
-
[in] | format | Clipboard format identifier. |
- Return values
-
true | Specified format presents on clipboard. |
false | Otherwise. |
Opens clipboard for use in the current thread.
- Return values
-
true | On success. |
false | On 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] | name | New format's name. |
- Returns
- Identifier of new format.
- Return values
-
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] | format | Format of clipboard to retrieve. |
[in] | ptr | Data to set. |
[in] | size | Size of data to set. |
- Return values
-
true | On success. |
false | On 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] | text | Unicode string to set. |
- Return values
-
true | On success. |
false | On 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
-
- Return values
-
true | On success. |
false | On failure. |