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. CRichEditCtrl and UNICODE

CRichEditCtrl and UNICODE

Scheduled Pinned Locked Moved C / C++ / MFC
question
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.
  • S Offline
    S Offline
    sstoyan
    wrote on last edited by
    #1

    hi i have a CRichEditCtrl in my app and it can't open UNICODE files properly (opens ANSI files ok). what do i have to do ? here's part of my code:     CRichEditCtrl * richedit = (CRichEditCtrl *)GetDlgItem(IDC_RICHEDIT1);     CFile file(filename, CFile::modeRead);     EDITSTREAM es;     es.dwCookie = (DWORD) &file;     es.pfnCallback = MyStreamInCallback;     richedit->StreamIn(SF_TEXT, es);          richedit->SetReadOnly(); the callback is straight from msdn i think .. static DWORD CALLBACK MyStreamInCallback(DWORD dwCookie, LPBYTE pbBuff, LONG cb, LONG *pcb) {    CFile* pFile = (CFile*) dwCookie;    *pcb = pFile->Read(pbBuff, cb);    return 0; }

    S 1 Reply Last reply
    0
    • S sstoyan

      hi i have a CRichEditCtrl in my app and it can't open UNICODE files properly (opens ANSI files ok). what do i have to do ? here's part of my code:     CRichEditCtrl * richedit = (CRichEditCtrl *)GetDlgItem(IDC_RICHEDIT1);     CFile file(filename, CFile::modeRead);     EDITSTREAM es;     es.dwCookie = (DWORD) &file;     es.pfnCallback = MyStreamInCallback;     richedit->StreamIn(SF_TEXT, es);          richedit->SetReadOnly(); the callback is straight from msdn i think .. static DWORD CALLBACK MyStreamInCallback(DWORD dwCookie, LPBYTE pbBuff, LONG cb, LONG *pcb) {    CFile* pFile = (CFile*) dwCookie;    *pcb = pFile->Read(pbBuff, cb);    return 0; }

      S Offline
      S Offline
      Steve S
      wrote on last edited by
      #2

      If you know it's UNICODE for certain, and you also know it's a RichEdit v2.0 or later, then try richedit->StreamIn( SF_TEXT|SF_UNICODE, es ); instead. (This isn't in the on-line help for CRichEditCtrl, but it is for EM_STREAMIN in the platform SDK docs) Steve S

      S 1 Reply Last reply
      0
      • S Steve S

        If you know it's UNICODE for certain, and you also know it's a RichEdit v2.0 or later, then try richedit->StreamIn( SF_TEXT|SF_UNICODE, es ); instead. (This isn't in the on-line help for CRichEditCtrl, but it is for EM_STREAMIN in the platform SDK docs) Steve S

        S Offline
        S Offline
        sstoyan
        wrote on last edited by
        #3

        thank you. now i have to find a way to check if the text is unicode or not - istextunicode() doesnt seem to work correctly

        S 1 Reply Last reply
        0
        • S sstoyan

          thank you. now i have to find a way to check if the text is unicode or not - istextunicode() doesnt seem to work correctly

          S Offline
          S Offline
          Steve S
          wrote on last edited by
          #4

          First off, you can check for a BOM (byte order mark), and if there isn't one, scan for EOL ('\n') BYTE using memchr(). If you find one, and there are NUL ('\0') bytes either side of it, it's almost certainly UNICODE. If your text contains only one line, this won't work, of course. Steve S

          S 1 Reply Last reply
          0
          • S Steve S

            First off, you can check for a BOM (byte order mark), and if there isn't one, scan for EOL ('\n') BYTE using memchr(). If you find one, and there are NUL ('\0') bytes either side of it, it's almost certainly UNICODE. If your text contains only one line, this won't work, of course. Steve S

            S Offline
            S Offline
            sstoyan
            wrote on last edited by
            #5

            thank you agan. i decided not to detect if it is unicode programmatically, but still a have a small problem left - when i display unicode string there is some garbage at the beginning of the text (1-2 bytes, "FF FE" usually), any idea how to avoid it? may be i should start reading the file with StreamIn from the first ASCII code ?

            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