当前位置: 代码迷 >> VC >> GetWindowText函数有关问题
  详细解决方案

GetWindowText函数有关问题

热度:5157   发布时间:2013-02-25 00:00:00.0
GetWindowText函数问题.
C/C++ code
#include <iostream>#include <Windows.h>#include <string>using namespace std;void main(){    HWND hwnd;    hwnd=::FindWindow(TEXT("CabinetWClass"),TEXT("我的电脑"));    string s="";    ::GetWindowText(hwnd,s,255);    cout<<s;}


错误 1 error C2664: “GetWindowTextW”: 不能将参数 2 从“std::string”转换为“LPWSTR” c:\Documents and Settings\MoBin\My Documents\Visual Studio 2008\Projects\c\c\z.cpp 11 c


------解决方案--------------------------------------------------------
GetWindowText是一个宏,根据项目所使用的字符集决定使用GetWindowTextA和GetWindowTextW其中的一个。因为你的项目使用的是Unicode字符集,所以如果后面没有A,表示使用GetWindowTextW,相应的变量都要使用宽字符。因为你要用string类型,所以要搭配GetWindowTextA;如果用GetWindowText,要把char改成wchar_t,把string改成wstring。
  相关解决方案