Created
October 8, 2013 14:02
-
-
Save pravic/6885178 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <string> | |
#include <vector> | |
// 1. std::basic_string have continuos storage | |
std::wstring GetWindowTextW(HWND hWnd) | |
{ | |
std::wstring text(::GetWindowTextLengthW(hWnd), L'\0'); | |
size_t len = ::GetWindowTextW(hWnd, &text[0], text.size()); | |
text.resize(len); | |
return std::move(text); | |
} | |
// 2. std::basic_string doesn't have continuos storage | |
std::wstring GetWindowTextW(HWND hWnd) | |
{ | |
std::vector<wchar_t> text(::GetWindowTextLengthW(hWnd)); | |
size_t len = ::GetWindowTextW(hWnd, &text[0], text.size()); | |
text.resize(len); | |
return std::wstring(&text[0], text.size()); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment