整合代码如下:
/** * 复制功能 */ 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; } /* * 粘贴功能 */ void PasteInfo() { keybd_event(0x11, 0, 0, 0);// press ctrl keybd_event(0x56, 0, 0, 0); // press v keybd_event(0x56, 0, 2, 0); //release v keybd_event(0x11, 0, 2, 0); //release ctrl }