Hello,
So I'm trying to use copy to clipboard function in order to copy a string to the clipboard. The problem is to create another string after the first string has been copied using cin.get();
Example:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15
void clipBoard()
{
constchar* output = "Hello!";
const size_t len = strlen(output) + 1;
HGLOBAL hMem = GlobalAlloc(GMEM_MOVEABLE, len);
memcpy(GlobalLock(hMem), output, len);
GlobalUnlock(hMem);
OpenClipboard(0);
EmptyClipboard();
SetClipboardData(CF_TEXT, hMem);
CloseClipboard();
cout << "'" << output << "'" << " has been successfully copied\n";
cin.get()
//Right here I want another string to be copied to clipboard after a button has been pressed due to 'cin.get();'
}
I'm still not sure what the interpretation of that is. Is the existing contents of the clipboard to be replaced by the new string, or appended to it?
"Hello" - first string
" 2" - second string
append second string to first, result = "Hello 2"
Or - is the second string "Hello 2" and the result to be "HelloHello 2".
Lets say
"Hello" - first string
"There" - second string
What is the required contents of the clipboard after copying the second string, please.
The program runs >> Copies to clipboard 'Hello'. Once you press a key because of cin.get(); Hello has to be cleared from clipboard than another string will be copied for example: Bye
So >> Copy first first string which is 'Hello'
After you press a button clear hello from clipboard
Copy 'Bye' to clipboard.
No need to thank me, I should thank you :)! I'l try to overwrite the variable output to another char text, If I can't figure it out can you help me? Thanks a lot for your help.
I would prefer to keep the function clipBoard() as simple as possible, so that it does just one thing - it copies the supplied string to the clipboard.
Then put any other logic in the code which calls that function.
A simpler approach might be to change the function definition to use a std::string as its parameter then the function could just be called like this: clipBoard(output);
Though that requires a couple of minor changes to the function: