How is it possible to copy something to the clipboard in c ? I have searched for a solution but I can't find any examples.
Would be great if you have a code example aswell. thank you
CodePudding user response:
An example to copy a text into it.
#include <windows.h>
int main(void)
{
const char* str = "Text copied to clipboard.";
const size_t len = strlen(str) 1;
HGLOBAL hgl = GlobalAlloc(GMEM_MOVEABLE, len);
memcpy(GlobalLock(hgl), str, len);
GlobalUnlock(hgl);
OpenClipboard(NULL);
EmptyClipboard();
SetClipboardData(CF_TEXT, hgl);
CloseClipboard();
return 0;
}
CodePudding user response:
You can, but it is OS specified task. Or just use QApplication::clipboard on Qt.