16,472
社区成员
发帖
与我相关
我的任务
分享
class TEXTNODE
{
string content;
//下面这些信息是对这一段文字内容的格式描述,枚举类型的。
COLOR color;
SIZE size;
//下面就可能会有一堆get或是set方法,可能mingw就是复制到系统剪贴板的时候,没有用get方法去获取或是怎的??
....
}
#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\n", 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("\n");
}
printf("%02x ",(UCHAR)lpStr[dw]);
}
printf("\n");
GlobalUnlock(hMem);
CloseClipboard();
return 0;
}
//打开剪贴板
if ( OpenClipboard() )
{
//清空剪贴板
EmptyClipboard();
//建立Window共享文件
CSharedFile shareFile( GMEM_MOVEABLE|GMEM_DDESHARE|GMEM_ZEROINIT);
//将共享文件与ar关联,以便进行序列化操作
CArchive ar(&shareFile, CArchive::store);
//保存图形个数
int iSelCount = this->GetSelCount();
int iAllCount = pDoc->m_objItems.GetCount();
ar<<iSelCount;
//把选中的图形存入内存文件
CItem *pItem;
for (int i=iAllCount-1; i>=0; i--)
{
pItem = (CItem*)pDoc->m_objItems[i];
if ( pItem->m_bSelected )
{
ar<<pItem;
}
}
ar.Close();//关闭序列化
HGLOBAL hMem = shareFile.Detach(); //获得共享文件的句柄
if (!hMem)
{
return;
}
SetClipboardData(m_uClipBoardItem, hMem);
//关闭剪贴板
CloseClipboard();
}