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. Can CFile set/get the text file font type?

Can CFile set/get the text file font type?

Scheduled Pinned Locked Moved C / C++ / MFC
questiontutorial
7 Posts 5 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.
  • Z Offline
    Z Offline
    zeus_master
    wrote on last edited by
    #1

    I wanna save some value into the a txt type file. for example, I save the value in *.txt file as follow,if the font is not matching, the columns/lines maybe become curve,sach as: 90 91 92 93 94 95 96 97 98 99 9A 9B 9C 9D 9E 9F A0 A1 A2 A3 A4 A5 A6 A7 A8 A9 AA AB AC AD AE AF B0 B1 B2 B3 B4 B5 B6 B7 B8 B9 BA BB BC BD BE BF 1>How can I set the text file display font in my code? 2>How can I get the exact single vaule that saved before?

    N C K K 4 Replies Last reply
    0
    • Z zeus_master

      I wanna save some value into the a txt type file. for example, I save the value in *.txt file as follow,if the font is not matching, the columns/lines maybe become curve,sach as: 90 91 92 93 94 95 96 97 98 99 9A 9B 9C 9D 9E 9F A0 A1 A2 A3 A4 A5 A6 A7 A8 A9 AA AB AC AD AE AF B0 B1 B2 B3 B4 B5 B6 B7 B8 B9 BA BB BC BD BE BF 1>How can I set the text file display font in my code? 2>How can I get the exact single vaule that saved before?

      N Offline
      N Offline
      Nibu babu thomas
      wrote on last edited by
      #2

      zeus_master wrote:

      2>How can I get the exact single vaule that saved before?

      Use fprintf to write and fscanf to read.


      Nibu thomas Software Developer

      1 Reply Last reply
      0
      • Z zeus_master

        I wanna save some value into the a txt type file. for example, I save the value in *.txt file as follow,if the font is not matching, the columns/lines maybe become curve,sach as: 90 91 92 93 94 95 96 97 98 99 9A 9B 9C 9D 9E 9F A0 A1 A2 A3 A4 A5 A6 A7 A8 A9 AA AB AC AD AE AF B0 B1 B2 B3 B4 B5 B6 B7 B8 B9 BA BB BC BD BE BF 1>How can I set the text file display font in my code? 2>How can I get the exact single vaule that saved before?

        C Offline
        C Offline
        Cedric Moonen
        wrote on last edited by
        #3

        I don't understand what you mean... If I pasted the lines you posted in a txt file and I open it with notepad, all columns are well aligned. A file is just 'data' (binary or text) and it cannot contain font information (or the only way to do that is to have your own file format and your own program that will read the file).

        Z 1 Reply Last reply
        0
        • Z zeus_master

          I wanna save some value into the a txt type file. for example, I save the value in *.txt file as follow,if the font is not matching, the columns/lines maybe become curve,sach as: 90 91 92 93 94 95 96 97 98 99 9A 9B 9C 9D 9E 9F A0 A1 A2 A3 A4 A5 A6 A7 A8 A9 AA AB AC AD AE AF B0 B1 B2 B3 B4 B5 B6 B7 B8 B9 BA BB BC BD BE BF 1>How can I set the text file display font in my code? 2>How can I get the exact single vaule that saved before?

          K Offline
          K Offline
          kk tvm
          wrote on last edited by
          #4

          Hi Use CFile with binary mode by KK

          1 Reply Last reply
          0
          • Z zeus_master

            I wanna save some value into the a txt type file. for example, I save the value in *.txt file as follow,if the font is not matching, the columns/lines maybe become curve,sach as: 90 91 92 93 94 95 96 97 98 99 9A 9B 9C 9D 9E 9F A0 A1 A2 A3 A4 A5 A6 A7 A8 A9 AA AB AC AD AE AF B0 B1 B2 B3 B4 B5 B6 B7 B8 B9 BA BB BC BD BE BF 1>How can I set the text file display font in my code? 2>How can I get the exact single vaule that saved before?

            K Offline
            K Offline
            kakan
            wrote on last edited by
            #5

            If you want to display the lines with straight columns, then you have to use a monospaced font (where all characters has got the same width), such as "Courier New" or "System" In a text file, you can't choose what font to use when the file is viewed. If you need to do that, try a .rtf, .doc or a .pdf file.

            Z 1 Reply Last reply
            0
            • C Cedric Moonen

              I don't understand what you mean... If I pasted the lines you posted in a txt file and I open it with notepad, all columns are well aligned. A file is just 'data' (binary or text) and it cannot contain font information (or the only way to do that is to have your own file format and your own program that will read the file).

              Z Offline
              Z Offline
              zeus_master
              wrote on last edited by
              #6

              please see my code below: BYTE regdata[5][0x10][0x10]; BOOL CxxDlg::OnInitDialog() { CDialog::OnInitDialog(); // Add "About..." menu item to system menu. // IDM_ABOUTBOX must be in the system command range. ASSERT((IDM_ABOUTBOX & 0xFFF0) == IDM_ABOUTBOX); ASSERT(IDM_ABOUTBOX < 0xF000); CMenu* pSysMenu = GetSystemMenu(FALSE); if (pSysMenu != NULL) { CString strAboutMenu; strAboutMenu.LoadString(IDS_ABOUTBOX); if (!strAboutMenu.IsEmpty()) { pSysMenu->AppendMenu(MF_SEPARATOR); pSysMenu->AppendMenu(MF_STRING, IDM_ABOUTBOX, strAboutMenu); } } // Set the icon for this dialog. The framework does this automatically // when the application's main window is not a dialog SetIcon(m_hIcon, TRUE); // Set big icon SetIcon(m_hIcon, FALSE); // Set small icon // TODO: Add extra initialization here BYTE h,i,j; for (h=0x00;h<5;h++) { for (i=0x00;i<0x10;i++) { for (j=0x00;j<0x10;j++) { regdata[h][i][j]=(BYTE)(i*0x10)+j; } } } return TRUE; // return TRUE unless you set the focus to a control } void CxxDlg::OnButtonSave() { // TODO: Add your control notification handler code here CString buf; CString buf1=" "; BYTE h,i,j; for (h=0x00;h<5;h++) { buf1.Format("\r\n\r\nBank%x: \r\n-----",h); buf +=buf1; for (j=0x00;j<0x10;j++) { buf1.Format("-%02X-",j); buf +=buf1; } for (i=0x00;i<0x10;i++) { buf1.Format("\r\n-%02X- ",i); buf +=buf1; for (j=0x00;j<0x10;j++) { buf1.Format("%02X ",regdata[h][i][j]); buf +=buf1; } } } CFileDialog fdlg(FALSE,"PJ",NULL,OFN_OVERWRITEPROMPT, "text File(*.txt)|*.txt|map file(*.map)|*.map|All files(*.*)|*.*||",this); fdlg.m_ofn.lpstrTitle="Data saving"; if (fdlg.DoModal()==IDOK) { m_strCurFile=fdlg.GetPathName(); CStdioFile csfile(m_strCurFile,CFile::modeCreate|CFile::modeReadWrite|CFile::typeText); csfile.WriteString(buf); csfile.Close(); } } I saved the values in *.txt or *.map file, but when it was opened by notepad with the defaut font, the columns becomed unaligned. So I want to know that is there any way to set the font view of the files? or they are only related with operating system? As the code above, I saved the value of array regdata[5][0x10][0x10] as hex-string in the *.txt file. how can I read the value back to regdata[5][0x10][0x10] one-by-one?:((

              1 Reply Last reply
              0
              • K kakan

                If you want to display the lines with straight columns, then you have to use a monospaced font (where all characters has got the same width), such as "Courier New" or "System" In a text file, you can't choose what font to use when the file is viewed. If you need to do that, try a .rtf, .doc or a .pdf file.

                Z Offline
                Z Offline
                zeus_master
                wrote on last edited by
                #7

                see http://www.codeproject.com/script/comments/forums.asp?msg=1473641&forumid=1647&XtraIDs=1647&searchkw=zeus_master&sd=2%2F3%2F2006&ed=5%2F4%2F2006#xx1473641xx[^]

                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