The C ++ programming language has flexible application methods and powerful functions. Many functions can be easily implemented through multiple methods. Here we will introduce some common operation skills of the C ++ clipboard in detail, hoping to help you understand this.
Copy Data to clipboard in C ++ clipboard operation
- 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;
- }
C ++ clipboard operation-data acquisition from clipboard
- BOOL GetTextFromClipboard ()
- {
- If (: OpenClipboard (NULL ))
- {
- // Obtain the Clipboard data
- 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;
- }
Simulation of C ++ clipboard operation Ctrl + V
- keybd_event(VK_CONTROL,0,0,0);
- keybd_event('V',0,0,0);
- keybd_event('V',0,KEYEVENTF_KEYUP,0);
- keybd_event(VK_CONTROL,0,KEYEVENTF_KEYUP,0);