C++ c++;GetWindowText并忽略非ANSI字符

C++ c++;GetWindowText并忽略非ANSI字符,c++,string,ansi,C++,String,Ansi,您好,我正在使用以下代码在Windows中获取窗口标题。我也在使用ANSI编码 HWND handle = GetForegroundWindow(); int bufsize = GetWindowTextLength(handle) +1; std::basic_string<char> title(bufsize, 0); GetWindowText(handle, &title[0], bufsize); std::cout

您好,我正在使用以下代码在Windows中获取窗口标题。我也在使用ANSI编码

    HWND handle = GetForegroundWindow();
    int bufsize = GetWindowTextLength(handle) +1;

    std::basic_string<char>  title(bufsize, 0);
    GetWindowText(handle, &title[0], bufsize);
    std::cout << title << std::endl;
HWND handle=getforegroughindow();
int bufsize=GetWindowTextLength(句柄)+1;
std::基本字符串标题(bufsize,0);
GetWindowText(句柄和标题[0],bufsize);

std::不能只使用
std::wstring
并让它处理其他字符。您希望如何处理您获得的信息?或者换句话说,对于有效字符中的字符,您想做什么?“我也在使用ANSI编码。”这当然是问题的根源。问题是GetWindowText()调用使用的代码页(默认系统代码页)与控制台使用的代码页不同。437通常使用传统OEM代码页。所以™ 在代码页1252中为0x99,在代码页437中显示为Ö。Unicode即将庆祝它的22岁生日,它被允许驾驶机动车和订购酒精饮料。