c++ 帮我修改一下

来源:百度知道 编辑:UC知道 时间:2024/09/28 09:06:19
#include <windows.h>
#include <iostream>
using namespace std;

int main()
{
HWND w=FindWindow(NULL,"Form1");
HWND w1=FindWindowEx(w, NULL,"ThunderRT6TextBox","hello");
char s1[256];
char s2=GetWindowText(w1,s1,256);
cout<<*s2;
return 0;
}

/*error C2100: illegal indirection
执行 cl.exe 时出错.

他说这个有错 cout<<*s2;
*/

#include <windows.h>
#include <iostream>
using namespace std;

int main()
{
HWND w=FindWindow(NULL,"Form1");
HWND w1=FindWindowEx(w, NULL,"ThunderRT6TextBox","hello");
char s1[256];
GetWindowText(w,s1,256);
cout<<s1;
return 0;
}

char s2=GetWindowText(w1,s1,256); //返回值是int,为什么用char?表示执行结果
更改如下:
char s1[256];
GetWindowText(w1,s1,256);
cout<<s1;

因为s2不是指针,要输出s2的值,要用 cout<<s2。

但你这里是不是搞错了

GetWindowText 返回的是int类型,代表函数执行成功与否。

你要获得窗口的text的话,应该用 cout<<s1;

cout<<s2<<endl
可以了