c++winapi

I included <winuser.h>, but compiler throws "was not declared" at MonitorFromWindow


There is already a post about it, but it didn't solve the error. I tried commenting out the if on winuser.h, but it did no effect.

// Header
    #include <windows.h>
    #include <winuser.h>

// Cpp
 monitorA = MonitorFromWindow(hwnd, MONITOR_DEFAULTTOPRIMARY); // Errors
    GetMonitorInfo(monitorA, &monitorAInfo); // No error

error: 'MonitorFromWindow' was not declared in this scope

error: 'MONITOR_DEFAULTTOPRIMARY' was not declared in this scope

Also, I am using Code::blocks with gcc compiler.


Solution

  • Assuming your copy of <winuser.h> actually supports MonitorFromWindow(), then make sure that you have WINVER set to 0x0500 or higher to enable MonitorFromWindow(). See the following for more details:

    Using the Windows Headers: Setting WINVER or _WIN32_WINNT

    Update WINVER and _WIN32_WINNT

    What's the difference between WINVER, _WIN32_WINNT, _WIN32_WINDOWS, and _WIN32_IE?