Clipboard CRLF & Control Fonts
-
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
-
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
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 yourfile
in binary mode ("b"
flag infopen
), that should fix the problem. Joaquín M López Muñoz Telefónica, Investigación y Desarrollo -
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 yourfile
in binary mode ("b"
flag infopen
), that should fix the problem. Joaquín M López Muñoz Telefónica, Investigación y DesarrolloI 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
-
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
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 functionCreateFont
... 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 -
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 functionCreateFont
... 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 DesarrolloI'll look into that. Thanks again. Sean Cody