Domanda

I'm working now with playground SDK and need to get WNDCLASS of my game window. I haven't found anything in SDK, thats why I'm trying to do this with hWnd of game window. So is there any way to get WNDCLASS from HWND? I need this to change system cursor in game window

È stato utile?

Soluzione

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.


To change the cursor for all windows of that class:

Use the SetClassLongPtr function:

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. You can read more about that in Adam Rosenfield's comment below.

That aside, there is an alternative: As per the SetCursor documentation, first make sure the class's cursor is set to nothing (NULL). Then you can use the SetCursor function when the mouse enters and leaves the client area. 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.

otherCursor = SetCursor(otherCursor);

To get the read-only WNDCLASSEX associated with a window:

First, use GetClassName to get the name of the class associated with the window:

std::array<TCHAR, 256> className; //256 is max classname length
GetClassName(hwnd, className.data(), className.size());

Then, use that in a call to GetClassInfoEx:

WNDCLASSEX wce;
GetClassInfoEx(GetModuleHandle(nullptr), className.data(), &wce);

Now you can access wce to read the contents of the class structure. If you need to, you can replace std::array with std::vector and .data() with &className[0], as well as nullptr with NULL. GetClassInfo will return a WNDCLASS if you need that instead of WNDCLASSEX.

Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top