BOOL PutTextToClipboard(LPCTSTR pTxtData)
{
BOOL bRet = FALSE;
if (OpenClipboard(AfxGetMainWnd()->GetSafeHwnd()))
{
EmptyClipboard();
HGLOBAL hData = GlobalAlloc(GMEM_MOVEABLE | GMEM_DDESHARE, (lstrlen(pTxtData) + 1) * sizeof(TCHAR));
if (hData != NULL)
{
LPTSTR pszData = (LPTSTR)::GlobalLock(hData);
lstrcpy(pszData, pTxtData);
GlobalUnlock(hData);
#ifdef _UNICODE
bRet = (SetClipboardData(CF_UNICODETEXT, hData) != NULL);
#else
bRet = (SetClipboardData(CF_TEXT, hData) != NULL);
#endif // _UNICODE
}
CloseClipboard();
}
return bRet;
}
posted on 2010-12-28 13:02
张志松 阅读(745)
评论(0) 编辑 收藏 引用 所属分类:
VC/MFC