Clipboard data
Aug 27, 2010 at 1:18am UTC
Hi everyone, I am trying to retrieve clipboard data and after looking online I came up with the following:
1 2 3 4 5 6 7 8 9 10 11
//get data
HANDLE clip;
string clip_text = "" ;
if (OpenClipboard(NULL))
{
clip = GetClipboardData(CF_TEXT);
clip_text = (char *)clip;
cout << "Text: " <<clip_text<<endl<<endl;
CloseClipboard();
}
this results in the error message:
203 C:\Users\Chazz & Bill\Documents\prog\input\main.cpp `HANDLE' undeclared (first use this function)
althuogh this is the variable type it tells me to use online. Am i missing an include file?
So far I have:
1 2 3 4 5 6 7
#include <cstdlib>
#include <iostream>
#include <string>
#include <fstream> //file handling
#include <algorithm>
using namespace std;
If it helps I am using Dev-C.
Any ideas?
Thank you for any help you can provide :)
Last edited on Aug 27, 2010 at 1:26am UTC
Aug 27, 2010 at 1:26am UTC
SOLVED!!!
I forgot to use:
#include <windows.h>
Aug 27, 2010 at 2:07am UTC
UNSOLVED : Sort of :s
Ok i got it to copy from clipboard but now i want to set it to the clipboard.
If i use
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15
if (OpenClipboard(NULL))
{
HGLOBAL hText = GlobalAlloc(GMEM_DDESHARE, final_text.length()-1);
char * pText = (char *)GlobalLock(hText);
const string f_text = final_text;
strcpy(pText, "testing" ); //copy to clipboard
GlobalUnlock(hText);
OpenClipboard(NULL);
EmptyClipboard();
SetClipboardData(CF_TEXT, hText);
CloseClipboard();
}
it works, but as soon as i try changing:
strcpy(pText, "testing"); //copy to clipboard
to:
strcpy(pText, f_text); //copy to clipboard
to set the text copied to clipboard according to a variable it does not let me, how do i go about solving this :s its the very last part of the program and i really would like it finished asap :)
Thank you for any help you can provide :)
Aug 27, 2010 at 2:09am UTC
Maybe it takes a c string, try f_text.c_str()
intead.
Aug 27, 2010 at 2:13am UTC
:D it works thank you very much but can you explain why this works and using regular strings and constants don't please?
Topic archived. No new replies allowed.