0
votes

My Requirement Is:

I am using MFC Dialog Based application and here I want to set the title of the dialog with Japanese string.

Below is my code snippet:

CStringW str;   // Using CStringW to support unicode characters

CTestofUTF83Dlg dlg;   // CTestofUTF83Dlg is my dialog class that is derived    
                      //from CDialog

str.LoadString(IDC_TESTJAPAN); // IDC_TESTJAPAN contains my Japanese string

SetDlgItemTextW(dlg,IDD_TESTOFUTF83_DIALOG,str); // IDD_TESTOFUTF83_DIALOG is the ID of my Dialog

With the above code, the Dialog box Title is not reflecting the Japanese string.

I think it is due to the first parameter of the SetDlgItemTextW, i.e., Handle to the dialog (dlg).

Because, if I use SetDlgItemText() function I am able to set the title.

Please Help me.

1
Have you debugged to see that your LoadString does indeed put the desired string in str? - o_weisman
@weisman.. Yes, LoadString is placing desired string in str. - Yar
Is the function returning a value indicating success? - o_weisman
@o_weisman.. Yes it is indicating success and the problem is only with this line SetDlgItemTextW(dlg,IDD_TESTOFUTF83_DIALOG,str); Because if i use the message box to test by using MessageBoxW(dlg,str,0,0); it is working fine and displaying the string. - Yar

1 Answers

1
votes

Yes, that won't work. You have not created your window/dialog yet so it does not have a window handle (m_hWnd != 0 or garbage).

Call SetWindowText inside the OnInitDialog() member of your CTestofUTF83Dlg.

BOOL CTestofUTF83Dlg::OnInitDialog()
{
   CDialog::OnInitDialog();
   // SetWindowText .... blah blah
   return TRUE;
}