This is a great forum, I have learned many things here. I have never posted in all these year, or asked a single question. I learned PHP from forums and became very good at it. I am now learning C++ and I'm quite surprised how much more code it takes to accomplish the same simple goals that a 20 character piece of PHP code can do. But it's been fun to learn and I'm really enjoying it. I have searched this forum and Google, and can't find anything on this issue I'm having. It's a mystery that makes no sense to me, but I'm a beginner with C++ and desktop application development. Perhaps I'm searching for the wrong phrases, but I can't find anything on this.
I have created a program that copies clipboard contents into a text file when the user presses ctrl+c . I spent several nights learning about this and got that to work. But it does something strange that I can't figure out.
I am creating a Windows GUI I am using Code::Blocks with standard complier. I have windows 7
My function compiles and works totally fine. But.... if I use ctrl+c on a web page in a browser, it prints the last sting, not the current content being copied. Yet this same program while running, will write the correct current highlighted content in notepad or any other application. Only in web browsers it does this where it writes the last copied data. In notepad the same keys, same function, same program, while it's still running even... will write the correct data to the text file.
How is it possible that it works 100% and shows no warnings or errors when compiled, but in web page browsers it writes old data ? If I use ctrl+c twice in a row on a web page, it then will write 2 times to the text file, first being the old content from last time I copied, and then the correct highlighted content on the web page. But it works perfect in notpad or wordpad or any of those applications.
What is going on here ? I'm so new to C++ I am not getting it. But, I can't find any questions here that seem to be same issue on windows. any help is greatly appreciated. I have been coming here for years, and never ask any questions, just read read read.... but this one's got me stumped and I'm too new to C++ to have a clue what's going on here.
// copy clipboard when user types left ctrl and c at same time.
if (key == 0x43){
if( GetAsyncKeyState( 0xA2 ) )
{
if (!OpenClipboard(NULL))
HANDLE h = GetClipboardData(CF_TEXT);
// variables f and k as clipboard dump beginning and ending
LPCSTR f = "[COPY TO CLIPBOARD]";
LPCSTR k = "[COPY TO CLIPBOARD ENDS]";
printf("%s\n", (char *)h); // prints clipboard into console
// prints clipboard content to the text output file sandwiched by f and k
fprintf(output,"%s", (char *)f);
fprintf(output,"%s",(char *)h);
fprintf(output,"%s",(char *)k);
CloseClipboard();
}
}
Any clue why I get last copied data on web sites but not in notpad ?
thanks in advance.