1

I'm trying out the Windows API, and I've run into a lot of problems. The most recent is this: I included Windows.h, and temporarily Winuser.h, yet the MonitorFromWindow (and the associated fields, like MONITOR_DEFAULTTONEAREST) are missing. Specifically,

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

and

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

Other methods show up just fine, like LoadImage and CreateWindow. Is there some inclusion I'm missing? I don't think it's the way I've called the methods, or even the way I included the header files, but if you ask, I can still post my code. There's not much of it.

Edit: when I check what is defined in the scope, the nearest methods are ModifyWorldTransform(...) and MonikerCommonPrefixWith(...); the nearest fields all begin with MONITOR_INFO, except for 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;
}
John P
  • 1,463
  • 3
  • 19
  • 39

2 Answers2

5
#define UNICODE
#define _WIN32_WINNT 0x0500     // Windows 2000
#include <windows.h>

auto main() -> int
{
    (void) MonitorFromWindow;
}

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


The relevant header section from the 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
Cheers and hth. - Alf
  • 142,714
  • 15
  • 209
  • 331
  • I may not have done this correctly, but I used the same definitions and inclusions as you - plus winuser.h - and it still doesn't appear to be working. Should I be using a different compiler? Edit: Eclipse still flags the calls, but the compiler is happy. I'll be back once I figure out if everything's behaving or not. – John P Dec 20 '13 at 18:03
1

The docs say

Minimum supported client
   Windows 2000 Professional [desktop apps only]

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

Simon Richter
  • 28,572
  • 1
  • 42
  • 64