Welcome: Hunan Intelligent Applications Tecgnology CO.,ltd.-HNIAT.com
Language: Chinese ∷  English

Basic knowledge

SetWindowText usage

SetWindowTextW indicates that the set string is WCHAR (double-byte character)
SetWindowTextA indicates that the set string is CHAR (single-byte character)
SetWindowText indicates whether the set string automatically matches the character environment of the current item is single-byte or double-byte characters

#ifdef UNICODE

#define SetWindowText SetWindowTextW

#else

#define SetWindowText SetWindowTextA

#ENDIF //! UNICODE

First explain the different meanings of A and W:

In fact, in MFC, all API functions related to string processing are available in A and W versions.

The A at the end uses ANSI encoding: The Chinese Windows operating system generally corresponds to GBK. GBK occupies one byte and two Chinese characters in memory.

Representation at the end of W:

UTF-16 version --- two bytes in English, two bytes in Chinese characters

UTF-32 version --- four bytes in English, four bytes in Chinese characters

If you are sure that your software will only need English or Chinese characters in the future, then choose the A version of the API. If it is possible to use multiple languages, then it is best to use the W version of the API.

The source code in MFC actually only exists in SetWindowTextW and SetWindowTextA. If your entire project character set is a character set in UNICODE format, then SetWindowText and SetWindowTextW are actually one thing. If it is not UNICODE, SetWindowText is one thing.

Function: This function changes the text content of the title bar of the specified window (if the window has a title bar). If the specified window is a control, change the text content of the control. However, the SetWindowText function does not change the text content of controls in other applications.

Function prototype: BOOL SetWindowText (HWND hwnd, LPCTSTR lpString);

Parameters:

HWnd: The handle of the window or control whose text content is to be changed.

LpString: Pointer to a null-terminated string that will be used as the new text for the window or control.

Return value: If the function succeeds, the return value is non-zero; if the function fails, the return value is zero. For more error information, call GetLastError.

Note: If the target window belongs to the current process, the SetWindowText function will cause the WM_SETTEXT message to be sent to the specified window or control. However, if the control is a list box control created in the WS_CAPTION style, the SetWindowText function will set the text for the control, not the list item.

The SetWindowText function does not expand the tab character (ASCII code 0 × 09), and the Tab character is displayed as the character '}'.

 

 What exactly are ANSI and Unicode

 general speaking:
ANSI is an American standard (I do n’t use exact words, I just mean something), each number, letter, punctuation mark is represented by one byte, and Chinese characters are represented by 2 bytes;
UNICODE is an international standard (I do n’t use words precisely, just to indicate the meaning), each number, letter, punctuation mark, Chinese character is represented by 2 bytes;

ANSI is an intermediate product of historical development. Eventually, it is to be eliminated. Although our current PC is still ANSI by default, it is to be compatible with the previous ANSI. New things such as mobile phones basically use UNICODE.

CONTACT US

Contact: Manager Xu

Phone: 13907330718

Tel: 0731-22222718

Email: hniatcom@163.com

Add: Room 603, 6th Floor, Shifting Room, No. 2, Orbit Zhigu, No. 79 Liancheng Road, Shifeng District, Zhuzhou City, Hunan Province

Scan the qr codeClose
the qr code