Win32 clipboard
-
Hi, I have tried to use the Win32 clipboard API to copy text to the clipboard, but ist doesn't show up when I try to paste it to a text editor. There is also no Clipboard Format available in the clipboard when I use EnumClipboardFormats. I've used a tutorial cooking book to write that code. Can you say what's wrong? Thanks. void Clipboard::setTo(string const strData) { string::size_type const sizeData = strData.size() * sizeof(TCHAR); HANDLE hData = ::GlobalAlloc(GMEM_MOVEABLE|GMEM_ZEROINIT, sizeData); if (hData) { LPTSTR tszData = static_cast( ::GlobalLock(hData) ); memcpy(tszData, strData.c_str(), sizeData); ::GlobalUnlock(hData); ::OpenClipboard(NULL); ::EmptyClipboard(); ::SetClipboardData(CF_TEXT, hData); } UINT uiFmt = 0; do { uiFmt = ::EnumClipboardFormats(uiFmt); } while (0 != uiFmt); ::CloseClipboard(); } Werner
-
Hi, I have tried to use the Win32 clipboard API to copy text to the clipboard, but ist doesn't show up when I try to paste it to a text editor. There is also no Clipboard Format available in the clipboard when I use EnumClipboardFormats. I've used a tutorial cooking book to write that code. Can you say what's wrong? Thanks. void Clipboard::setTo(string const strData) { string::size_type const sizeData = strData.size() * sizeof(TCHAR); HANDLE hData = ::GlobalAlloc(GMEM_MOVEABLE|GMEM_ZEROINIT, sizeData); if (hData) { LPTSTR tszData = static_cast( ::GlobalLock(hData) ); memcpy(tszData, strData.c_str(), sizeData); ::GlobalUnlock(hData); ::OpenClipboard(NULL); ::EmptyClipboard(); ::SetClipboardData(CF_TEXT, hData); } UINT uiFmt = 0; do { uiFmt = ::EnumClipboardFormats(uiFmt); } while (0 != uiFmt); ::CloseClipboard(); } Werner
void CopyToClipBoard(char * buf,DWORD MAXSIZE)
{
HANDLE handle;
char * str; //This has the data that is to be copied to the clipboard
if(OpenClipboard(NULL))
{
EmptyClipboard();handle = GlobalAlloc(GMEM\_MOVEABLE,MAXSIZE+1); if(handle) { str = (LPTSTR)GlobalLock(handle); memcpy(str,buf,MAXSIZE); GlobalUnlock(handle); SetClipboardData(CF\_TEXT, handle); } CloseClipboard(); }
}
Does this work?
I don't believe in failure. It is not failure if you enjoyed the process.
-
Hi, I have tried to use the Win32 clipboard API to copy text to the clipboard, but ist doesn't show up when I try to paste it to a text editor. There is also no Clipboard Format available in the clipboard when I use EnumClipboardFormats. I've used a tutorial cooking book to write that code. Can you say what's wrong? Thanks. void Clipboard::setTo(string const strData) { string::size_type const sizeData = strData.size() * sizeof(TCHAR); HANDLE hData = ::GlobalAlloc(GMEM_MOVEABLE|GMEM_ZEROINIT, sizeData); if (hData) { LPTSTR tszData = static_cast( ::GlobalLock(hData) ); memcpy(tszData, strData.c_str(), sizeData); ::GlobalUnlock(hData); ::OpenClipboard(NULL); ::EmptyClipboard(); ::SetClipboardData(CF_TEXT, hData); } UINT uiFmt = 0; do { uiFmt = ::EnumClipboardFormats(uiFmt); } while (0 != uiFmt); ::CloseClipboard(); } Werner
Have you used the debugger to check return values, and the value of variables such as
size_type
,hData
, andtszData
? What doesSetClipboardData()
return?
"Approved Workmen Are Not Ashamed" - 2 Timothy 2:15
"Judge not by the eye but by the heart." - Native American Proverb