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. Clipboard CRLF & Control Fonts

Clipboard CRLF & Control Fonts

Scheduled Pinned Locked Moved C / C++ / MFC
helpcsharpvisual-studioquestion
5 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.
  • N Offline
    N Offline
    NullStream
    wrote on last edited by
    #1

    I have 2 questions the first is there a simple way to change the font size of a particlar control (eg. listbox). The second is that I have a simple function (attached) which just reads a file and places it's textual contents into the clipboard. When I paste the info in notepad it is one continuous line with the crlf characters a little boxes though if i paste into other things (like in visual studio) it is fine. Is there some way I can preserve the carriage return/line feeds in the clipboard so that pasting into notepad and anything else will have the proper contents of the file?

    // function is cut down to limit the spaming of useless code
    EmptyClipboard();
    GlobalBuff = GlobalAlloc(GMEM_MOVEABLE,size+1);
    
    buffer = (char*)GlobalLock(GlobalBuff);
    while(!feof(file)) {
         fread(readbuffer,1,255,file);
         if(ferror(file)) {
              MessageBox(NULL,strerror(errno),"Error",MB_ICONERROR);
              exit(1);
         }
         strcat(buffer,readbuffer);
         memset(readbuffer,0,strlen(readbuffer));
    }
    
    GlobalUnlock(GlobalBuff);
    if(SetClipboardData(CF_TEXT,GlobalBuff) == NULL) 
         return FALSE;
    CloseClipboard();
    

    If posting of this code is not appropriate please let me know and forgive my insolence. Any help or suggestions are greatly appricated. Thanks, Sean Cody

    J 1 Reply Last reply
    0
    • N NullStream

      I have 2 questions the first is there a simple way to change the font size of a particlar control (eg. listbox). The second is that I have a simple function (attached) which just reads a file and places it's textual contents into the clipboard. When I paste the info in notepad it is one continuous line with the crlf characters a little boxes though if i paste into other things (like in visual studio) it is fine. Is there some way I can preserve the carriage return/line feeds in the clipboard so that pasting into notepad and anything else will have the proper contents of the file?

      // function is cut down to limit the spaming of useless code
      EmptyClipboard();
      GlobalBuff = GlobalAlloc(GMEM_MOVEABLE,size+1);
      
      buffer = (char*)GlobalLock(GlobalBuff);
      while(!feof(file)) {
           fread(readbuffer,1,255,file);
           if(ferror(file)) {
                MessageBox(NULL,strerror(errno),"Error",MB_ICONERROR);
                exit(1);
           }
           strcat(buffer,readbuffer);
           memset(readbuffer,0,strlen(readbuffer));
      }
      
      GlobalUnlock(GlobalBuff);
      if(SetClipboardData(CF_TEXT,GlobalBuff) == NULL) 
           return FALSE;
      CloseClipboard();
      

      If posting of this code is not appropriate please let me know and forgive my insolence. Any help or suggestions are greatly appricated. Thanks, Sean Cody

      J Offline
      J Offline
      Joaquin M Lopez Munoz
      wrote on last edited by
      #2

      As for the first question, use SetFont. Read Mike Dunn's C++ FAQ for common mistakes prople make when using this method. With regard to your second problem, I guess what's happening is that notepad requires lines to be separated by CR-LF pairs ("\r\n" in C++ code) and you are feeding it with LF separated text. Try opening your file in binary mode ("b" flag in fopen), that should fix the problem. Joaquín M López Muñoz Telefónica, Investigación y Desarrollo

      N 1 Reply Last reply
      0
      • J Joaquin M Lopez Munoz

        As for the first question, use SetFont. Read Mike Dunn's C++ FAQ for common mistakes prople make when using this method. With regard to your second problem, I guess what's happening is that notepad requires lines to be separated by CR-LF pairs ("\r\n" in C++ code) and you are feeding it with LF separated text. Try opening your file in binary mode ("b" flag in fopen), that should fix the problem. Joaquín M López Muñoz Telefónica, Investigación y Desarrollo

        N Offline
        N Offline
        NullStream
        wrote on last edited by
        #3

        I should have specified I am only using C and the bare Win32 API (no MFC) so that method will not work for me. :( Though the fopen suggestion worked great. Thanks! Sean Cody

        J 1 Reply Last reply
        0
        • N NullStream

          I should have specified I am only using C and the bare Win32 API (no MFC) so that method will not work for me. :( Though the fopen suggestion worked great. Thanks! Sean Cody

          J Offline
          J Offline
          Joaquin M Lopez Munoz
          wrote on last edited by
          #4

          I should have specified I am only using C and the bare Win32 API (no MFC) so that method will not work for me. There are direct equivalents in Win32: message WM_SETFONT, Win32 function CreateFont... so you should have no problems translating the solution to raw C/Win32. Joaquín M López Muñoz Telefónica, Investigación y Desarrollo

          N 1 Reply Last reply
          0
          • J Joaquin M Lopez Munoz

            I should have specified I am only using C and the bare Win32 API (no MFC) so that method will not work for me. There are direct equivalents in Win32: message WM_SETFONT, Win32 function CreateFont... so you should have no problems translating the solution to raw C/Win32. Joaquín M López Muñoz Telefónica, Investigación y Desarrollo

            N Offline
            N Offline
            NullStream
            wrote on last edited by
            #5

            I'll look into that. Thanks again. Sean Cody

            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