2014-10-17 23:19:05 +04:00
|
|
|
|
|
|
|
#include <winpr/crt.h>
|
2014-10-18 00:45:36 +04:00
|
|
|
#include <winpr/print.h>
|
2014-10-17 23:19:05 +04:00
|
|
|
#include <winpr/clipboard.h>
|
|
|
|
|
|
|
|
int TestClipboardFormats(int argc, char* argv[])
|
|
|
|
{
|
|
|
|
UINT32 index;
|
|
|
|
UINT32 count;
|
|
|
|
UINT32 formatId;
|
|
|
|
UINT32* pFormatIds;
|
|
|
|
const char* formatName;
|
|
|
|
wClipboard* clipboard;
|
2014-10-18 00:45:36 +04:00
|
|
|
UINT32 utf8StringFormatId;
|
2014-10-17 23:19:05 +04:00
|
|
|
clipboard = ClipboardCreate();
|
|
|
|
formatId = ClipboardRegisterFormat(clipboard, "text/html");
|
|
|
|
formatId = ClipboardRegisterFormat(clipboard, "image/bmp");
|
|
|
|
formatId = ClipboardRegisterFormat(clipboard, "image/png");
|
2014-10-18 02:23:07 +04:00
|
|
|
utf8StringFormatId = ClipboardRegisterFormat(clipboard, "UTF8_STRING");
|
2014-10-18 00:45:36 +04:00
|
|
|
pFormatIds = NULL;
|
|
|
|
count = ClipboardGetRegisteredFormatIds(clipboard, &pFormatIds);
|
|
|
|
|
|
|
|
for (index = 0; index < count; index++)
|
|
|
|
{
|
|
|
|
formatId = pFormatIds[index];
|
|
|
|
formatName = ClipboardGetFormatName(clipboard, formatId);
|
2016-12-14 00:47:08 +03:00
|
|
|
fprintf(stderr, "Format: 0x%08"PRIX32" %s\n", formatId, formatName);
|
2014-10-18 00:45:36 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
free(pFormatIds);
|
|
|
|
|
|
|
|
if (1)
|
|
|
|
{
|
|
|
|
BOOL bSuccess;
|
|
|
|
UINT32 SrcSize;
|
|
|
|
UINT32 DstSize;
|
2016-10-06 14:31:25 +03:00
|
|
|
const char* pSrcData = "this is a test string";
|
2014-10-18 00:45:36 +04:00
|
|
|
char* pDstData;
|
2016-08-10 11:29:59 +03:00
|
|
|
|
2015-06-17 23:08:02 +03:00
|
|
|
if (!pSrcData)
|
|
|
|
{
|
|
|
|
fprintf(stderr, "Memory allocation failed\n");
|
|
|
|
return -1;
|
|
|
|
}
|
2014-10-18 00:45:36 +04:00
|
|
|
|
2016-08-10 11:29:59 +03:00
|
|
|
SrcSize = (UINT32)(strlen(pSrcData) + 1);
|
2016-10-06 14:31:25 +03:00
|
|
|
bSuccess = ClipboardSetData(clipboard, utf8StringFormatId, pSrcData,
|
2016-08-10 11:29:59 +03:00
|
|
|
SrcSize);
|
2016-12-14 00:47:08 +03:00
|
|
|
fprintf(stderr, "ClipboardSetData: %"PRId32"\n", bSuccess);
|
2014-10-18 00:45:36 +04:00
|
|
|
DstSize = 0;
|
|
|
|
pDstData = (char*) ClipboardGetData(clipboard, utf8StringFormatId, &DstSize);
|
|
|
|
fprintf(stderr, "ClipboardGetData: %s\n", pDstData);
|
|
|
|
free(pDstData);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (1)
|
|
|
|
{
|
|
|
|
UINT32 DstSize;
|
|
|
|
char* pSrcData;
|
|
|
|
WCHAR* pDstData;
|
|
|
|
DstSize = 0;
|
|
|
|
pDstData = (WCHAR*) ClipboardGetData(clipboard, CF_UNICODETEXT, &DstSize);
|
|
|
|
pSrcData = NULL;
|
|
|
|
ConvertFromUnicode(CP_UTF8, 0, pDstData, -1, &pSrcData, 0, NULL, NULL);
|
|
|
|
fprintf(stderr, "ClipboardGetData (synthetic): %s\n", pSrcData);
|
|
|
|
free(pDstData);
|
|
|
|
free(pSrcData);
|
|
|
|
}
|
2014-10-17 23:19:05 +04:00
|
|
|
|
|
|
|
pFormatIds = NULL;
|
|
|
|
count = ClipboardGetFormatIds(clipboard, &pFormatIds);
|
|
|
|
|
|
|
|
for (index = 0; index < count; index++)
|
|
|
|
{
|
|
|
|
formatId = pFormatIds[index];
|
|
|
|
formatName = ClipboardGetFormatName(clipboard, formatId);
|
2016-12-14 00:47:08 +03:00
|
|
|
fprintf(stderr, "Format: 0x%08"PRIX32" %s\n", formatId, formatName);
|
2014-10-17 23:19:05 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
free(pFormatIds);
|
|
|
|
ClipboardDestroy(clipboard);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|