Why is MonitorFromWindow missing / not declared? (C ++ / WINAPI)

I am testing the Windows API and I am having a lot of problems. Most recent: I turned on Windows.h and temporarily Winuser.h, but MonitorFromWindow (and related fields such as MONITOR_DEFAULTTONEAREST) ​​are missing. In particular,

...'MONITOR_DEFAULTTONEAREST' was not declared in this scope 

and

 ...'MonitorFromWindow' was not declared in this scope. 

Other methods are displayed just fine, like LoadImage and CreateWindow. Is there some kind of inclusion that I am missing? I don’t think this is the way I called the methods, or even the way I included the header files, but if you ask, I can still post my code. There are not many.

Edit: when I check what is defined in scope, the closest methods are ModifyWorldTransform (...) and MonikerCommonPrefixWith (...); nearby fields begin with MONITOR_INFO, with the exception of MONITOR_ENUMPROC. No MONITOR_DEFAULTTONEAREST / NULL / etc.

Edit 2:

 #define UNICODE #define _WIN32_WINNT 0x0500 #include <iostream> #include <process.h> #include <windows.h> #include <winuser.h> 

...

 HMONITOR monitor = NULL; HWND CreateFullScreenWindow(HWND hwnd){ if(monitor==NULL){ monitor = MonitorFromWindow(hwnd, MONITOR_DEFAULTTONEAREST); } return hwnd; } 
+1
source share
2 answers
 #define UNICODE #define _WIN32_WINNT 0x0500 // Windows 2000 #include <windows.h> auto main() -> int { (void) MonitorFromWindow; } 

This is a problem only if the toolchain supports Windows 2000 or earlier, as the MinGW g ++ compiler does.


Corresponding header section from MinGW g ++ 4.7.2 <winuser.h> :

 #if (_WIN32_WINNT >= 0x0500 || _WIN32_WINDOWS >= 0x0410) WINUSERAPI HMONITOR WINAPI MonitorFromPoint(POINT,DWORD); WINUSERAPI HMONITOR WINAPI MonitorFromRect(LPCRECT,DWORD); WINUSERAPI HMONITOR WINAPI MonitorFromWindow(HWND,DWORD); #endif 
+5
source

docs say

 Minimum supported client Windows 2000 Professional [desktop apps only] 

I suspect you need to set WINVER to 0x500 or more.

+1
source

All Articles