![](https://www.cnblogs.com/Images/OutliningIndicators/ContractedBlock.gif)
Code
void CopyToClipboard(CString str)
{
if (OpenClipboard(NULL))
{
if (str.GetLength()>=40)
{
return;
}
TCHAR a[40] ;
memcpy(a,str.GetBuffer(0),(str.GetLength()+1)*2);
HGLOBAL hMem;
LPTSTR pStr;
// 分配内存空间
hMem = GlobalAlloc(GHND | GMEM_SHARE, (str.GetLength()+1)*2);
pStr = (LPTSTR)GlobalLock(hMem);
wcsncpy_s(pStr,40,a,40);
GlobalUnlock(hMem);
EmptyClipboard();
// 设置剪贴板文本
SetClipboardData(CF_UNICODETEXT, hMem);
CloseClipboard();
// 释放内存空间
GlobalFree(hMem);
}
}
posted @
2009-11-03 22:00
凌点
阅读(
268)
评论()
编辑
收藏
举报