Home > Software engineering >  MFC programming, c SetDlgItemText SetDlgItemTextA, what is the difference between setDlgItemTextW? H
MFC programming, c SetDlgItemText SetDlgItemTextA, what is the difference between setDlgItemTextW? H

Time:09-27

Please comment, I use VS2015 MFC application development, but now there are SetDlgItemText, SetDlgItemTextA, setDlgItemTextW this several functions, consult about how to use? How to choose? What is the difference between the several functions?

CodePudding user response:

A character encoding different

CodePudding user response:

W represents A for ANSI characters, WIDE characters, don't have the real function SetDlgItemText, but use it every time you use this, he will be based on your program USES what kind of character set, to call SetDlgItemTextA SetDlgItemTextW one of them, you see with the macro definition, use of words, search, casually SetDlgItemText (IDC_EDIT_TEST, _T (" Hello world? NO, World hello "));

CodePudding user response:

First understand Chinese GBK encoding and Unicode specific is what happened,
Such as: GBK: 0 xb0 0 xa1, Unicode - 16 LE: 0 0 x55 x4a

CodePudding user response:

SetDlgItemText SetDlgItemTextA, SetDlgItemTextW
As relationships between the three:
People, Chinese and foreigners
Or:
People, men and women

The three corresponding character encoding, respectively is:
TCHAR, char, would be/WCHAR

If you want to get the text to the char array, explicitly call SetDlgItemTextA,
If you want to get the text to WCHAR array, explicitly call SetDlgItemTextW,
If you want to get the text to the TCHAR array, call SetDlgItemText,

TCHAR is an uncertain type, may be a char or WCHAR,
SetDlgItemText is a macro name, may be defined as SetDlgItemTextA or SetDlgItemTextW,
Depending on the Visual Studio project Settings as byte code, or Unicode,

SetDlgItemText exist, it is like the existence of TCHAR,
Through the macro definition, makes SetDlgItemText and TCHAR can according to the project code set synchronous switch to the corresponding code,

CodePudding user response:

Most Windows API provides two sets of different version of the character encoding,
, the aim is to make your code can be easily transplanted to Unicode project,

CodePudding user response:

Win32 API is generally divided into two kinds of A and W at the end of the corresponding coding ANSI/unicode
Usually A apis are internal conversion ANSI for unicode. The API call again W

CodePudding user response:

 # ifdef _UNICODE 
# define SetDlgItemText SetDlgItemTextW
# the else
# define SetDlgItemText SetDlgItemTextA
# endif
  • Related