c++mousedirectx-11directxtk

DirectXTK no member in "Mouse" for "SetWindow(HWND hwnd)"


I was trying to implement mouse and keyboard support in my game engine using DirectXTK. It was quite simple for keyboard, but I have got a problem with implementing proper mouse support. I was following THIS for implementing mouse into my engine. This article from Microsoft wiki says that I have call SetWindow, before I will be able to change mouse mode from absolute to relative. It sounds easy, but when I try to do this like this:

auto mouse = std::make_unique<DirectX::Mouse>();
mouse->SetWindow(hwnd);
mouse->SetMode(DirectX::Mouse::Mode::MODE_RELATIVE);

I get an error:

E0135 class "DirectX::Mouse" has no member "SetWindow"

It looks like this method doesn't exist in Mouse class. It is weird, becuse if I remove this line with setting window it will compile, but I will fail in runtime due to this assertion in Mouse class:

assert(mWindow != nullptr);

So it is required to set window, but how can I do this, when this function doesn't exist? What's worse the article from wiki is not old, it's from 18 Apr 2019. Have anyone encountered this problem? How can I fix this?


Solution

  • A quick look at the header file and you'll see this

    #if (!defined(WINAPI_FAMILY) || (WINAPI_FAMILY == WINAPI_FAMILY_DESKTOP_APP)) && defined(WM_USER)
        void __cdecl SetWindow(HWND window);
        static void __cdecl ProcessMessage(UINT message, WPARAM wParam, LPARAM lParam);
    #endif
    

    So it seems likely that you don't have WINAPI_FAMILY and/or WM_USER defined in a suitable way to enable the declaration of that method in the header file.

    I believe WM_USER will be defined by #include <windows.h> so maybe all you need to do is place that include before #include <mouse.h>