This is how you can get last text item from clipboard:
OpenClipboard(nullptr);
HANDLE hData = GetClipboardData(CF_TEXT);
char* pszText = static_cast<char*>(GlobalLock(hData));
std::string text;
if (pszText != nullptr)
{
text.assign(pszText);
}
GlobalUnlock(hData);
CloseClipboard();
std::cout << text;
This is how you can set an text item from clipboard:
std::string source("text");
if (OpenClipboard(nullptr))
{
HGLOBAL clipbuffer;
char* buffer;
EmptyClipboard();
clipbuffer = GlobalAlloc(GMEM_DDESHARE, source.length() + 1);
buffer = (char*)GlobalLock(clipbuffer);
strcpy(buffer, source.c_str());
GlobalUnlock(clipbuffer);
SetClipboardData(CF_TEXT, clipbuffer);
CloseClipboard();
}
But I don't know how to delete last text item from clipboard, I would like to be able to not let the user see that I am using the clipboard or change his clipboard so he cant paste last thing he copied...
How can I do this, delete an text item from windows clipboard using c++?
This is the strangest way to pass text from one app to another. Sending e-mail also comes to mind.
There is a Windows-native way to do that: send a WM_COPYDATA
message. See https://docs.microsoft.com/en-us/windows/win32/dataxchg/wm-copydata for details.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.