[source]
Unicode and RichEditCtrl
Unicode Strings in MFC
The easiest way to deal with Unicode strings is to use CStringW class. As it is, CStringW can edit Unicode strings. Another option is to use char* equivalent wide-byte type in MFC called LPWSTR.
Writing and reading Unicode strings to and from controls in MFC is not exactly as straight forward. GetDlgItemText and SetDlgItemText only take single byte character strings. This page explains how to send messages to set and retrieve Unicode strings to the controls without the use of those functions.
Take a look at the following functions. Those functions read and write Unicode strings from and to MFC controls (RichEditCtrl). Sending messages requires several steps. First is to specify the type of the message. The type of the message, the codepage, and other optional settings are set to a structure called GETTEXTEX and SETTEXTEX. Then calculate and prepare space to store the results.
LPWSTR GetUnicodeString(UINT id)
{
CRichEditCtrl* edit=(CRichEditCtrl*)GetDlgItem(id);
int nLength = edit->GetTextLengthEx(GTL_DEFAULT,1200);
LPWSTR lpszWChar = new WCHAR[nLength+1];
GETTEXTEX getTextEx;
getTextEx.cb=(nLength+1)*sizeof(WCHAR);
getTextEx.codepage=1200;
getTextEx.flags=GT_DEFAULT;
getTextEx.lpDefaultChar=NULL;
getTextEx.lpUsedDefChar=NULL;
edit->SendMessage(EM_GETTEXTEX, (WPARAM)&getTextEx, (LPARAM)lpszWChar);
return lpszWChar;
}
void SetUnicodeString(UINT id, LPWSTR str)
{
SETTEXTEX setTextEx;
setTextEx.codepage=1200;
setTextEx.flags=ST_DEFAULT;
CRichEditCtrl *caption=(CRichEditCtrl*)GetDlgItem(id);
if(caption!=NULL)
caption->SendMessage(EM_SETTEXTEX, (WPARAM)&setTextEx, (LPARAM)str);
}
The usage of GetUnicodeString above is shown below. Specify the ID of the RichEditCtrl control.
CStringW str=GetUnicodeString(IDC_RICHEDITCTRL);
Likewise, the usage of SetUnicodeString above is shown below. Specify the ID of the RichEditCtrl control, and the Unicode string to be set to the control.
SetUnicodeString(IDC_RICHEDITCTRL,str);
Blog Archive
Showing posts with label VC. Show all posts
Showing posts with label VC. Show all posts
Tuesday, December 30, 2008
Friday, December 19, 2008
Visual Studio 2005 SP1
From Microsoft Download Center
Visual Studio® 2005 Team Suite SP1
Visual C++ 2005 SP1 Redistributable Package (x86)
Visual Studio 2005 Service Pack 1 GDIPLUS.DLL Security Update
Integrate VS 2005 & SP1:
[HowTo]整合Visual Studio 2005與Service Pack 1
Visual Studio® 2005 Team Suite SP1
Visual C++ 2005 SP1 Redistributable Package (x86)
Visual Studio 2005 Service Pack 1 GDIPLUS.DLL Security Update
Integrate VS 2005 & SP1:
[HowTo]整合Visual Studio 2005與Service Pack 1
Saturday, July 05, 2008
Set Environment Variables for VC
If we install more than 1 version of VC compilers, it's better to set environment variable to the version that we'd like to use for compiling programs under command mode (e.g. use nmake with makefile):
VC6:
$(VS_Path)\VC98\Bin\vcvars32.bat
VC7 (2003) / VC8 (2005) / VC9 (2008):
$(VS_Path)\Common7\Tools\vsvars32.bat
VC6:
$(VS_Path)\VC98\Bin\vcvars32.bat
VC7 (2003) / VC8 (2005) / VC9 (2008):
$(VS_Path)\Common7\Tools\vsvars32.bat
Subscribe to:
Posts (Atom)