GetClipboardData
获取剪贴板内容
用OpenClipboard打开剪贴板
EnumClipboardFormats加while来循环出一个可用的剪贴板格式
使用GetClipboardData获得剪贴板的内存块首地址
用GlobalLock锁定剪贴板那内存块
GlobalSize可以用来获取该内存块的大小
使用GlobalUnlock解除锁定
CloseClipboard关闭剪贴板
示例代码:
#include <windows.h>
#include <stdio.h>
int main(int argc, char *argv[])
{
if (!OpenClipboard(NULL))
{
return 0;
}
HGLOBAL hMem = NULL;
LPCTSTR lpStr = NULL;
UINT uFormat = NULL;
while (TRUE)
{
uFormat = EnumClipboardFormats(uFormat);
if (uFormat > 0)
{
hMem = GetClipboardData(uFormat);
lpStr = (LPCTSTR)::GlobalLock(hMem);
if (lpStr != NULL)
{
printf("The address is 0x%0x
", hMem);
break;
}
}
else
{
return 0;
}
}
DWORD dwSize = GlobalSize(hMem);
printf("The size of clipboard : %ld",dwSize);
for (DWORD dw = 0 ;dw<dwSize;dw++)
{
if (dw%21 == 0)
{
printf("
");
}
printf("%02x ",(UCHAR)lpStr[dw]);
}
printf("
");
GlobalUnlock(hMem);
CloseClipboard();
return 0;
}