如何通过其在 UNICODE 中表示的名称来确保和获取窗口句柄? [英] how to ensure and get window handle by its name represented in UNICODE?

查看:25
本文介绍了如何通过其在 UNICODE 中表示的名称来确保和获取窗口句柄?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我怎样才能确保当我转移扫雷时它会是 unicode 而不是被转换为 ASCII?

how can i make sure that when i transfer Minesweeper it will be in unicode and not will be casted to ASCII?

HWND procHnd;
HWND windowHnd=FindWindow(NULL,"Minesweeper");

进程或窗口表示的名称是否重要?

does it matter at all the name of the process or window representation?

推荐答案

您可以显式使用 Unicode 版本的 API

You can explicitly use the Unicode version of the API

HWND windowHnd = FindWindowW(NULL, L"Minesweeper");

您目前正在为 ANSI 字符构建应用程序.如果您想在整个过程中使用 Unicode,您应该更改您的项目选项以使用 Unicode.如果你这样做了,你可以简单地把它写成

You are currently building your application for ANSI characters. If you want to use Unicode throughout you should change your project options to use Unicode. If you did that you can simply write it as

HWND windowHnd = FindWindow(NULL, L"Minesweeper");

具有包含文本的参数的 Windows API 函数有两个版本,即 ANSI 版本和 Unicode 版本.例如,user32 DLL 不导出名为FindWindow 的函数.相反,它导出 FindWindowA(ANSI 版本)和 FindWindowW(Unicode 版本).Windows 头文件中的宏将 FindWindow 转换为 FindWindowAFindWindowW,具体取决于您的目标字符集.

Windows API functions that have parameters which contain text are available in two versions, an ANSI version and a Unicode version. For example the user32 DLL does not export a function called FindWindow. Instead it exports FindWindowA, the ANSI version, and FindWindowW, the Unicode version. Macros in the Windows header files convert FindWindow into either FindWindowA or FindWindowW, depending on which character set you target.

在 Visual Studio 中,您可以在 Configuration Properties | 下的项目配置中设置此选项.一般 |字符集.选择使用 Unicode 字符集.

In Visual Studio you can set this option in the project configuration under Configuration Properties | General | Character Set. Select Use Unicode Character Set.

这篇关于如何通过其在 UNICODE 中表示的名称来确保和获取窗口句柄?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆