Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C / C++ / MFC
  4. Pasting into a CEdit Control on a Dialog

Pasting into a CEdit Control on a Dialog

Scheduled Pinned Locked Moved C / C++ / MFC
visual-studioperformance
3 Posts 2 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • D Offline
    D Offline
    Doug Knudson
    wrote on last edited by
    #1

    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

    Z 1 Reply Last reply
    0
    • D 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 Knudson

      Z Offline
      Z Offline
      zt9788
      wrote on last edited by
      #2

      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(); } hi

      D 1 Reply Last reply
      0
      • Z zt9788

        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(); } hi

        D Offline
        D Offline
        Doug Knudson
        wrote on last edited by
        #3

        Thank you very much! Works like a charm! Doug Doug Knudson

        1 Reply Last reply
        0
        Reply
        • Reply as topic
        Log in to reply
        • Oldest to Newest
        • Newest to Oldest
        • Most Votes


        • Login

        • Don't have an account? Register

        • Login or register to search.
        • First post
          Last post
        0
        • Categories
        • Recent
        • Tags
        • Popular
        • World
        • Users
        • Groups