[Turn] SetWindowText usage

Setting a character string is represented SetWindowTextW WCHAR (double byte character)
the SetWindowTextA is represented by a string of characters CHAR (single byte character)
the SetWindowText string representing the character set is automatically match the current environment is a single item or a double-byte byte character

#ifdef UNICODE

#define    SetWindowText      SetWindowTextW

#else

#define    SetWindowText      SetWindowTextA

#ENDIF //! UNICODE

A first explain the different meanings and W:

In fact, MFC, all involved in string handling API functions have two versions of A and W

A representation of the end use ANSI encoding: Chinese Windows operating system corresponding general is GBK, GBK byte in memory occupied by the English, Chinese character two bytes. 

W at the end, he said:

UTF-16 version --- English two-byte, two-byte characters 

UTF-32 version --- English four bytes, four bytes of characters

If it is determined your future software needs only English or Chinese language characters, then select the A version of the API, if it is possible to use many languages, it is best to use the W version of the API.

MFC source code, in fact, there are actually only SetWindowTextW and SetWindowTextA, if your entire project is set UNICODE character format character set that SetWindowText and SetWindowTextW is actually a thing, if that is not UNICODE SetWindowText on and SetWindowTextA is a thing.

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

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

  parameter:

  hWnd: handle of the window to change or control the content of the text.

  lpString: Pointer to a null-terminated string, the string will be as a new window or text control.

  Return Value: If the function succeeds, the return value is zero; if the function fails, the return value is zero. To get extended error information, call GetLastError.

  Note: If the target window belonging to the current process, SetWindowText WM_SETTEXT function will send a message to the specified window or control. However, if the control is a list box control WS_CAPTION style created, SetWindowText control function will set the text, instead of setting the text for the list item.

  SetWindowText is not extended tab character (ASCII codes 0 × 09), Tab character '}' characters to be displayed.

 

Guess you like

Origin www.cnblogs.com/zhangbing12304/p/11118222.html