// 复制数据至剪切板BOOL CopyToClipboard(const char* pszData, const int nDataLen){ if(::OpenClipboard(NULL)) { ::EmptyClipboard(); HGLOBAL clipbuffer; char *buffer; clipbuffer = ::GlobalAlloc(GMEM_DDESHARE, nDataLen+1); buffer = (char *)::GlobalLock(clipbuffer); strcpy(buffer, pszData); ::GlobalUnlock(clipbuffer); ::SetClipboardData(CF_TEXT, clipbuffer); ::CloseClipboard(); return TRUE; } return FALSE;} // 从剪切板中取得数据BOOL GetTextFromClipboard(){ if(::OpenClipboard(NULL)) { //获得剪贴板数据 HGLOBAL hMem = GetClipboardData(CF_TEXT); if(NULL != hMem) { char* lpStr = (char*)::GlobalLock(hMem); if(NULL != lpStr) { //MessageBox(0, lpStr, "", 0); ::GlobalUnlock(hMem); } } ::CloseClipboard(); return TRUE; } return FALSE;} from:https://zhidao.baidu.com/question/647698977954822045.html
时间: 2024-10-10 20:58:42