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. Win32 clipboard

Win32 clipboard

Scheduled Pinned Locked Moved C / C++ / MFC
jsontutorialquestionlearning
3 Posts 3 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.
  • W Offline
    W Offline
    WernerP
    wrote on last edited by
    #1

    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

    M D 2 Replies Last reply
    0
    • W WernerP

      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

      M Offline
      M Offline
      Monty2
      wrote on last edited by
      #2

      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.

      1 Reply Last reply
      0
      • W WernerP

        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

        D Offline
        D Offline
        David Crow
        wrote on last edited by
        #3

        Have you used the debugger to check return values, and the value of variables such as size_type, hData, and tszData? What does SetClipboardData() return?


        "Approved Workmen Are Not Ashamed" - 2 Timothy 2:15

        "Judge not by the eye but by the heart." - Native American Proverb

        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