CRichEditCtrl and UNICODE
-
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; }
-
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; }
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
-
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
-
thank you. now i have to find a way to check if the text is unicode or not - istextunicode() doesnt seem to work correctly
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
-
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
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 ?