HWND hwnd = FindWindow ((LPCWSTR)"#32770",(LPCWSTR)"对对碰角色版"); //获取QQ对对碰游戏的窗口句柄
if(hwnd!=NULL)
this->label2->Text ="游戏 已运行";
else this->label2 ->Text ="游戏 未运行";//判断窗口是否存在小弟初学C++的Windows编程,对这段代码中有两处不懂的地方:
1.((LPCWSTR)"#32770"这里为什么要强制转换成LPCWSTR类型才能编译通过?而去掉强制类型转换符就不行了,VB中却可以直接调用"#32770","对对碰角色版"这样的参数
2.判断hwnd是否为NULL的时候,不管我开没开QQ对对碰游戏,最后的运行结果都是hwnd为NULL。当我设置断点调试的时候,hwnd显示是未定义的值,这是怎么回事?
if(hwnd!=NULL)
this->label2->Text ="游戏 已运行";
else this->label2 ->Text ="游戏 未运行";//判断窗口是否存在小弟初学C++的Windows编程,对这段代码中有两处不懂的地方:
1.((LPCWSTR)"#32770"这里为什么要强制转换成LPCWSTR类型才能编译通过?而去掉强制类型转换符就不行了,VB中却可以直接调用"#32770","对对碰角色版"这样的参数
2.判断hwnd是否为NULL的时候,不管我开没开QQ对对碰游戏,最后的运行结果都是hwnd为NULL。当我设置断点调试的时候,hwnd显示是未定义的值,这是怎么回事?
==============
VB我不知道,不过C对类型要求严格一点而已。2.判断hwnd是否为NULL的时候,不管我开没开QQ对对碰游戏,最后的运行结果都是hwnd为NULL。当我设置断点调试的时候,hwnd显示是未定义的值,这是怎么回事?
==========
说明FindWindow这个函数没有成功,你调用一下LastError看一下出错的原因是什么
lp -> long pointer
c -> const
w -> unicode
str -> string
可见,多了个W,即unicode编码的问题。
2、你的FindWindow使用方法上有点小问题,就如2楼所说,常用一个参数就够了,用不着两个参数都写进去。
你用FindWindow (_T("#32770"),NULL);
或者FindWindow (NULL,_T("对对碰角色版"));试试
1.使用_T("#32770")或者_T("对对碰角色版")的时候 编译提示无法找到_T标识符。
使用这个的时候需要做什么声明不?这也是一个强制转换符么?功能是什么?能介绍下么
2.TEXT(
LPTSTR string
);
Parameters
string
Pointer to the string to interpret as UTF-16 or ANSI.
Res
This macro interprets an ANSI string at runtime according to the current Windows ANSI code page. Literal ANSI strings that are not strictly ASCII are interpreted differently when processed with different Windows ANSI code pages. For example, '\0xC4' in code page 1252 (Latin-1) represents Upper Case A with Dieresis ('Ä'). However, in code page 1253 (Greek), the string represents Upper Case Delta ('Δ'). These different interpretations lead to development and maintenance issues. For example, a developer might correct a string when using a different system code page from the page used by the original developer; or a build computer might use a different code page. The different interpretations also pose runtime issues, for example, when the end user computer uses a different code page to interpret a string from that used by the build computer
TEXT这个函数转换成指针指向字符串类型,还是只是字符串类型?