[英]How to get WNDCLASS from HWND?
I'm working now with playground SDK and need to get WNDCLASS of my game window. 我现在正在使用游乐场SDK,需要获得我游戏窗口的WNDCLASS。 I haven't found anything in SDK, thats why I'm trying to do this with hWnd of game window.
我还没有在SDK中找到任何东西,这就是为什么我试图用hWnd的游戏窗口来做这件事。 So is there any way to get WNDCLASS from HWND?
那么有没有办法从HWND获得WNDCLASS? I need this to change system cursor in game window
我需要这个来改变游戏窗口中的系统光标
I don't know about the SDK in question, but as long as it provides access to the native HWND
type, you can use native calls. 我不知道有问题的SDK,但只要它提供对本机
HWND
类型的访问,您就可以使用本机调用。
To change the cursor for all windows of that class: 要更改该类的所有窗口的光标:
Use the SetClassLongPtr
function: 使用
SetClassLongPtr
函数:
SetClassLongPtr(hwnd, GCLP_HCURSOR, reinterpret_cast<LONG_PTR>(newCursorHandle));
To change the cursor for just the game window: 要仅改变游戏窗口的光标:
First of all, there is a WM_SETCURSOR
message that you can handle to take control of what cursor is shown in the window. 首先,有一个
WM_SETCURSOR
消息,您可以处理该消息来控制窗口中显示的光标。 You can read more about that in Adam Rosenfield's comment below. 您可以在下面的Adam Rosenfield的评论中阅读更多相关内容。
That aside, there is an alternative: As per the SetCursor
documentation, first make sure the class's cursor is set to nothing ( NULL
). 除此之外,还有另一种选择:根据
SetCursor
文档,首先确保将类的光标设置为NULL
( NULL
)。 Then you can use the SetCursor
function when the mouse enters and leaves the client area. 然后,当鼠标进入和离开客户区时,您可以使用
SetCursor
功能。 To not interfere with other windows in the class, be sure to set the class cursor to NULL on mouse entry and set it back to what it was on mouse exit. 为了不干扰类中的其他窗口,请确保在鼠标输入时将类光标设置为NULL并将其设置回鼠标退出时的状态。
otherCursor = SetCursor(otherCursor);
To get the read-only WNDCLASSEX associated with a window: 要获得与窗口关联的只读WNDCLASSEX:
First, use GetClassName
to get the name of the class associated with the window: 首先,使用
GetClassName
获取与窗口关联的类的名称:
std::array<TCHAR, 256> className; //256 is max classname length
GetClassName(hwnd, className.data(), className.size());
Then, use that in a call to GetClassInfoEx
: 然后,在调用
GetClassInfoEx
使用它:
WNDCLASSEX wce;
GetClassInfoEx(GetModuleHandle(nullptr), className.data(), &wce);
Now you can access wce
to read the contents of the class structure. 现在您可以访问
wce
来读取类结构的内容。 If you need to, you can replace std::array
with std::vector
and .data()
with &className[0]
, as well as nullptr
with NULL
. 如果需要,可以使用
&className[0]
替换带有std::vector
和.data()
std::array
,以及带有NULL
nullptr
。 GetClassInfo
will return a WNDCLASS
if you need that instead of WNDCLASSEX
. 如果需要,则
GetClassInfo
将返回WNDCLASS
而不是WNDCLASSEX
。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.