Reputation: 479
HWND ForeWindow = GetForegroundWindow();
wchar_t WindowTxt[1024] = { L'\0' };
GetWindowTextW(ForeWindow, WindowTxt, 1024);
wprintf(L"%s\n", WindowTxt);
std::wstring Str(WindowTxt);
std::wcout << L"Wnd: " << Str << L"\n";
Using the above code to get the window of skype which is "Skype™" i get the output:
"Skype?"
(the wcout line fails to execute)
1) Why is the wide character version of GetWindowText unable to handle this character
2) Why does std::wstring fail to parse the wchar_t array and then print it to the console
Upvotes: 1
Views: 550
Reputation: 47962
CMD consoles don't handle Unicode well. Send the output to a file and open it in and editor, and I suspect you'll get the actual character you expect.
Upvotes: 2