From: adorable.rajesh on
Hi,

I am using a CDhtmlDialog with a HTML file to show some results in
this dialog.

The HTML file's head portion is given below :-

<HEAD>
<META http-equiv="Content-Type" content="text/html; charset=EUC-JP">
</HEAD>

Note the charset mentioned as EUC-JP.

I am using CDhtmlDialog::LoadFromResource() to load this HTML file in
the CDhtmlDialog dialog. LoadFromResource is invoked from
CDhtmlDialog::OnInitDialog(). Thus when the dialog is created the HTML
file is loaded automatically.

After this loading is done, I am writing some dynamic content in the
HTML file's <DIV> tag (using IHTMLElement::put_innerHTML), and this
content also gets displayed correctly.

Now the problem is that I am having some buffer in a char* variable
and this buffer is encoded in EUC-JP encoding. I am writing this
buffer in the <DIV> tag as mentioned above. But this EUC-JP encoded
buffer is not displayed correctly in the <DIV> tag.

But if I write some EUC-JP encoded string in the HTML file statically,
then this string is displayed properly since LoadFromResource() helps
in correctly recognising the charset during loading of HTML file as
resource. But if I write EUC-JP encoded string dynamically, then
CDhtmlDialog does not interpret it as EUC-JP and thus displays
incorrectly.

Kindly let me know how to solve this issue.

Rajesh
From: David Ching on
<adorable.rajesh(a)gmail.com> wrote in message
news:eae341dc-f004-4572-9d19-b9e864134f2e(a)e6g2000prf.googlegroups.com...
> Hi,
>
> I am using a CDhtmlDialog with a HTML file to show some results in
> this dialog.
>
> The HTML file's head portion is given below :-
>
> <HEAD>
> <META http-equiv="Content-Type" content="text/html; charset=EUC-JP">
> </HEAD>
>
> Note the charset mentioned as EUC-JP.
>
> I am using CDhtmlDialog::LoadFromResource() to load this HTML file in
> the CDhtmlDialog dialog. LoadFromResource is invoked from
> CDhtmlDialog::OnInitDialog(). Thus when the dialog is created the HTML
> file is loaded automatically.
>
> After this loading is done, I am writing some dynamic content in the
> HTML file's <DIV> tag (using IHTMLElement::put_innerHTML), and this
> content also gets displayed correctly.
>
> Now the problem is that I am having some buffer in a char* variable
> and this buffer is encoded in EUC-JP encoding. I am writing this
> buffer in the <DIV> tag as mentioned above. But this EUC-JP encoded
> buffer is not displayed correctly in the <DIV> tag.
>
> But if I write some EUC-JP encoded string in the HTML file statically,
> then this string is displayed properly since LoadFromResource() helps
> in correctly recognising the charset during loading of HTML file as
> resource. But if I write EUC-JP encoded string dynamically, then
> CDhtmlDialog does not interpret it as EUC-JP and thus displays
> incorrectly.
>
> Kindly let me know how to solve this issue.
>
> Rajesh

Rajesh, I use the following code to set the text of an element:

---
BOOL CDHtmlPopupDlg::SetElementText (LPCTSTR pElementName, LPCTSTR pText)
{
CComPtr<IHTMLElement> spElementText;
GetElement(pElementName, &spElementText);
if ( !spElementText )
return FALSE;

// Override
CComPtr<IHTMLStyle> spStyle;
spElementText->get_style(&spStyle);
ASSERT (spStyle);
if ( !m_strFontFamily.IsEmpty() )
spStyle->put_fontFamily(_bstr_t(m_strFontFamily));
if ( !m_strFontSize.IsEmpty() )
spStyle->put_fontSize(_variant_t(m_strFontSize));

// Change HTML formatting and text
return SUCCEEDED(spElementText->put_innerHTML (_bstr_t(pText)));
}
---

It works for text of 30 languages including Japanese. But the key is that
pText is a wchar_t (UTF-16) string and not a UTF-8 string encoded in EUC-JP.
I think put_innerHTML() requires UTF-16 strings.

-- David


 | 
Pages: 1
Prev: OnActivateView problem
Next: UNICODE conversion