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

你。 提交于 2019-12-11 13:22:13

问题


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;
}

回答1:


#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



回答2:


The docs say

Minimum supported client
   Windows 2000 Professional [desktop apps only]

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



来源:https://stackoverflow.com/questions/20709016/why-is-monitorfromwindow-missing-not-declared-c-winapi

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!