Pasting into a CEdit Control on a Dialog
-
Hi All, In VS 6 I copy data from a custom control on a dialog using my own clipboard management (see code below) and would like to paste it into a CEdit on the same dialog. I believe I am getting it to the clipboard correctly, in CF_TEXT format because I can paste the text into WordPad or Notepad just fine. I am unable, however, to paste my clipboard contents to the CEdit either with the CEdit context menu or Ctrl+V. Making this all the more confusing is that if I copy text from Wordpad, which presumably is in CF_TEXT format, I am able to paste into the standard CEdit just fine. Any ideas would be greatly appreaciated! Thanks, Doug
// This just simulates the text I want to get to the clipboard CString cellText = "This is a test"; // Open the clipboard and empty it OpenClipboard(); EmptyClipboard(); // Get a chunk of memory for the formatted text int dataStringLen = cellText.GetLength(); HANDLE dataHandle = GlobalAlloc(GMEM_MOVEABLE | GMEM_ZEROINIT,dataStringLen + 1); char *memPtr = (char *)GlobalLock(dataHandle); // Copy the data to our mem block memcpy(memPtr,(char *)(LPCTSTR)cellText,dataStringLen + 1); memPtr[dataStringLen] = '\0'; // Unlock the handle, place the data on the clipboard and then free the // handle GlobalUnlock(dataHandle); SetClipboardData(CF_TEXT,dataHandle); GlobalFree(dataHandle); CloseClipboard();
Doug Knudson -
Hi All, In VS 6 I copy data from a custom control on a dialog using my own clipboard management (see code below) and would like to paste it into a CEdit on the same dialog. I believe I am getting it to the clipboard correctly, in CF_TEXT format because I can paste the text into WordPad or Notepad just fine. I am unable, however, to paste my clipboard contents to the CEdit either with the CEdit context menu or Ctrl+V. Making this all the more confusing is that if I copy text from Wordpad, which presumably is in CF_TEXT format, I am able to paste into the standard CEdit just fine. Any ideas would be greatly appreaciated! Thanks, Doug
// This just simulates the text I want to get to the clipboard CString cellText = "This is a test"; // Open the clipboard and empty it OpenClipboard(); EmptyClipboard(); // Get a chunk of memory for the formatted text int dataStringLen = cellText.GetLength(); HANDLE dataHandle = GlobalAlloc(GMEM_MOVEABLE | GMEM_ZEROINIT,dataStringLen + 1); char *memPtr = (char *)GlobalLock(dataHandle); // Copy the data to our mem block memcpy(memPtr,(char *)(LPCTSTR)cellText,dataStringLen + 1); memPtr[dataStringLen] = '\0'; // Unlock the handle, place the data on the clipboard and then free the // handle GlobalUnlock(dataHandle); SetClipboardData(CF_TEXT,dataHandle); GlobalFree(dataHandle); CloseClipboard();
Doug Knudsonif(OpenClipboard()){ CString cellText = "This is a test"; HGLOBAL clipbuffer; EmptyClipboard(); clipbuffer = GlobalAlloc(GMEM_DDESHARE, cellText.GetLength()+1); char * buffer; buffer = (char*)GlobalLock(clipbuffer); strcpy(buffer, LPCSTR(cellText)); GlobalUnlock(clipbuffer); SetClipboardData(CF_TEXT,clipbuffer); CloseClipboard(); }
hi -
if(OpenClipboard()){ CString cellText = "This is a test"; HGLOBAL clipbuffer; EmptyClipboard(); clipbuffer = GlobalAlloc(GMEM_DDESHARE, cellText.GetLength()+1); char * buffer; buffer = (char*)GlobalLock(clipbuffer); strcpy(buffer, LPCSTR(cellText)); GlobalUnlock(clipbuffer); SetClipboardData(CF_TEXT,clipbuffer); CloseClipboard(); }
hiThank you very much! Works like a charm! Doug Doug Knudson