From: JY on
"Hector Santos" wrote:

> The problem with the particular code you have is that it doesn't
> support reading a RTF file saved as UNI-GARBAGE A.K.A UNICODE.
>
> It appears you need to convert each block read in into multi-byte
> array. It works find when the RTF file is not stored in unicode.

Where exactly do I handle this? You mean I should use something like
wcstombs ?


> JY wrote:
>
> > Hi,
> >
> > I have a Wizard based application, in which I have some property pages. In
> > one of the pages, I have a CRichEditCtrl, and I try to populate its contents
> > from a RTF file. The porblem is, it works correctly if the RTF file is small
> > (about 4-5 KB), but when I use a larger file, its contents either don't
> > display at all, or gets truncated.
> >
> > The code is shown below. What can I do to show the entire contents of the
> > RTF file in the control? Also, it should work for all languages - I have
> > UNICODE defined in the project. m_RECtrl is the rich edit control.
> >
> > static DWORD CALLBACK MyStreamInCallback(DWORD dwCookie, LPBYTE pbBuff, LONG
> > cb, LONG *pcb)
> > {
> > CFile* pFile = (CFile*)(DWORD_PTR)dwCookie;
> > *pcb = pFile->Read(pbBuff, cb);
> >
> > return 0;
> > }
> >
> > BOOL CREPage::OnInitDialog()
> > {
> > CBasePage::OnInitDialog();
> >
> > if (m_strRTFFilePath.GetLength())
> > {
> > m_RECtrl.ShowScrollBar(SB_VERT, TRUE);
> > CFile eulaFile(m_strRTFFilePath, CFile::modeRead);
> > EDITSTREAM es;
> >
> > es.dwCookie = (DWORD_PTR)&eulaFile;
> > es.pfnCallback = (EDITSTREAMCALLBACK)MyStreamInCallback;
> > m_RECtrl.StreamIn(SF_RTF, es);
> > }
> >
> > return TRUE;
> > }
> >
> > int CREPage::OnCreate(LPCREATESTRUCT lpCreateStruct)
> > {
> > if (CBasePage::OnCreate(lpCreateStruct) == -1)
> > return -1;
> >
> > CRect rect;
> > GetClientRect(&rect);
> > rect.bottom -= 25;
> >
> > m_RECtrl.Create(WS_CHILD | WS_VISIBLE | WS_VSCROLL | ES_MULTILINE, rect,
> > this, IDC_RICHEDIT_EULA);
> > m_RECtrl.SetOptions(ECOOP_OR, ECO_AUTOVSCROLL | ECO_AUTOHSCROLL |
> > ECO_READONLY);
> > m_RECtrl.ModifyStyleEx(0, WS_EX_CLIENTEDGE, SWP_FRAMECHANGED);
> >
> > return 0;
> > }
> >
> > TIA,
> > JY
>
>
>
> --
> HLS
> .
>
From: Hector Santos on
JY wrote:

> "Hector Santos" wrote:
>
>> The problem with the particular code you have is that it doesn't
>> support reading a RTF file saved as UNI-GARBAGE A.K.A UNICODE.
>>
>> It appears you need to convert each block read in into multi-byte
>> array. It works find when the RTF file is not stored in unicode.
>
> Where exactly do I handle this? You mean I should use something like
> wcstombs ?


The problem is that your EULA RTF file is saved in UNICODE.

Unicode for dummies like me, is basically two bytes for each character.

The callback is just a data reader so it seems you need to convert it
there. But then again, I don't see whats all this SF_UNICODE option
and control type "RICHEDIT20W" information is for if it can't convert
it itself. So its might be possible strictly with the proper control
setup.

But to see it work as you currently have it is basically use this in
your call back code:

CFile* pFile = (CFile*)(DWORD_PTR)dwCookie;
BYTE *p = new BYTE[cb];
ZeroMemory(p,cb);
*pcb = pFile->Read(p, cb);
WideCharToMultiByte(CP_ACP,
0,
(LPCWSTR)p,-1,
(LPSTR)pbBuff, cb / sizeof(WCHAR),
NULL,
NULL);
*pcb = cb / sizeof(WCHAR);
delete p;

and that will read in a cb size block, convert it and put it into
pcBuff with 1/2 the size. You probably want to do what Goran did and
use the ctx struct to pass some state information like whether its
actually a unicode or ansi file and convert or just read it straight
into pbBuff. Joe can correct us with all the nits about all this
where I would like to know if you need this or not by using the
StreamIn(SF_XXXXX) options.

--
HLS
From: Hector Santos on
Jy, you should read about RTF in wikipedia in regards to UNICODE:

http://en.wikipedia.org/wiki/Rich_Text_Format

Unless you really need it, I would suggest using an ANSI version of
your EULA, that way people can read it using ANY editor with no
excuses. :)

Hector Santos wrote:

> JY wrote:
>
>> "Hector Santos" wrote:
>>
>>> The problem with the particular code you have is that it doesn't
>>> support reading a RTF file saved as UNI-GARBAGE A.K.A UNICODE.
>>>
>>> It appears you need to convert each block read in into multi-byte
>>> array. It works find when the RTF file is not stored in unicode.
>>
>> Where exactly do I handle this? You mean I should use something like
>> wcstombs ?
>
>
> The problem is that your EULA RTF file is saved in UNICODE.
>
> Unicode for dummies like me, is basically two bytes for each character.
>
> The callback is just a data reader so it seems you need to convert it
> there. But then again, I don't see whats all this SF_UNICODE option and
> control type "RICHEDIT20W" information is for if it can't convert it
> itself. So its might be possible strictly with the proper control setup.
>
> But to see it work as you currently have it is basically use this in
> your call back code:
>
> CFile* pFile = (CFile*)(DWORD_PTR)dwCookie;
> BYTE *p = new BYTE[cb];
> ZeroMemory(p,cb);
> *pcb = pFile->Read(p, cb);
> WideCharToMultiByte(CP_ACP,
> 0,
> (LPCWSTR)p,-1,
> (LPSTR)pbBuff, cb / sizeof(WCHAR),
> NULL,
> NULL);
> *pcb = cb / sizeof(WCHAR);
> delete p;
>
> and that will read in a cb size block, convert it and put it into pcBuff
> with 1/2 the size. You probably want to do what Goran did and use the
> ctx struct to pass some state information like whether its actually a
> unicode or ansi file and convert or just read it straight into pbBuff.
> Joe can correct us with all the nits about all this where I would like
> to know if you need this or not by using the StreamIn(SF_XXXXX) options.
>



--
HLS
From: David Ching on
"JY" <sd(a)nospamgroup.com> wrote in message
news:6ACCD426-52DD-4733-9DEF-A1A26FF5E60D(a)microsoft.com...
> Hi,
>
> I have a Wizard based application, in which I have some property pages. In
> one of the pages, I have a CRichEditCtrl, and I try to populate its
> contents
> from a RTF file. The porblem is, it works correctly if the RTF file is
> small
> (about 4-5 KB), but when I use a larger file, its contents either don't
> display at all, or gets truncated.
>
> The code is shown below. What can I do to show the entire contents of the
> RTF file in the control? Also, it should work for all languages - I have
> UNICODE defined in the project. m_RECtrl is the rich edit control.
>
> static DWORD CALLBACK MyStreamInCallback(DWORD dwCookie, LPBYTE pbBuff,
> LONG
> cb, LONG *pcb)
> {
> CFile* pFile = (CFile*)(DWORD_PTR)dwCookie;
> *pcb = pFile->Read(pbBuff, cb);
>
> return 0;
> }
>

It sounds like your callback is getting called multiple times and is not
doing the right thing after the first time. Set a breakpoint in
MyStreamInCallback and note the inputs and outputs. In particular, I've
found the callback is called until you set *pcb = 0.

I don't think Unicode has anything to do with this problem since you say it
works for short files, unless it happens your short file is not Unicode, but
the failing longer ones are.

-- David


From: JY on
"Hector Santos" wrote:

> Jy, you should read about RTF in wikipedia in regards to UNICODE:
>
> http://en.wikipedia.org/wiki/Rich_Text_Format
>
> Unless you really need it, I would suggest using an ANSI version of
> your EULA, that way people can read it using ANY editor with no
> excuses. :)
>
I need to support it in multiple languages and so ANSI is of no help.
- Jy
First  |  Prev  |  Next  |  Last
Pages: 1 2 3 4 5 6
Prev: Task
Next: compile error note