

This approach is more efficient than having a separate std::vector for buffer allocation, with a separate dynamic memory allocation, and then a deep-copy into the std::wstring. However, you have to pass the whole destination buffer length (*including* the terminating NUL) to GetWindowText() as third parameter. Note that the length value returned by GetWindowTextLength() excludes the terminating NUL. Str.resize(len) // make enough room in string Something like this: int len = GetWindowTextLength(hwnd)

Tab characters are displayed as vertical bar (|) characters.Then how are you supposed to get any window text ?Īn option would be to make enough room inside the string for storing text in it. The SetWindowText function does not expand tab characters (ASCII code 0x09). To set the text of a control in another process, send the WM_SETTEXT message directly instead of calling SetWindowText. If the control is a list box control created with the WS_CAPTION style, however, SetWindowText sets the text for the control, not for the list box entries. If the target window is owned by the current process, SetWindowText causes a WM_SETTEXT message to be sent to the specified window or control. To get extended error information, call GetLastError. If the function fails, the return value is zero. If the function succeeds, the return value is nonzero. Syntax BOOL SetWindowTextW(Ī handle to the window or control whose text is to be changed. However, SetWindowText cannot change the text of a control in another application. If the specified window is a control, the text of the control is changed. Changes the text of the specified window's title bar (if it has one).
