1 // 设置剪切板内容 2 void CLogic::fnCopyStrToClipboard(CString szStr) 3 { 4 if ( ::OpenClipboard(NULL) ) 5 { 6 if ( EmptyClipboard() ) 7 { 8 size_t cbStr = (szStr.GetLength()+1)*sizeof(TCHAR); 9 HGLOBAL hData = GlobalAlloc(GMEM_MOVEABLE, cbStr);10 memcpy_s(GlobalLock(hData), cbStr, szStr.LockBuffer(), cbStr);11 szStr.UnlockBuffer();12 GlobalUnlock(hData);13 UINT nFormat = (sizeof(TCHAR) == sizeof(WCHAR) ? CF_UNICODETEXT:CF_TEXT);14 if (NULL == ::SetClipboardData(nFormat, hData))15 {16 CloseClipboard();17 return;18 }19 }20 CloseClipboard(); //关闭剪切板21 }22 }