gpt4 book ai didi

c++ - 试图检测监视器

转载 作者:太空宇宙 更新时间:2023-11-04 15:20:44 25 4
gpt4 key购买 nike

我正在尝试获取显示器以检查它是否关闭。

在使用 GetDevicePowerState 检查之前,我尝试以这种方式检索监视器:

#include <cstdlib>
#include <iostream>
#include <windows.h>
#include <winuser.h>
using namespace std;

int main(int argc, char *argv[])
{
POINT* p = new POINT;
p->x=0;
p->y=0;
HMONITOR* monitor = MonitorFromPoint(p,DWORD.MONITOR_DEFAULTTOPRIMARY);
system("PAUSE");
return EXIT_SUCCESS;
}

但它不断地给我:

main.cpp `MonitorFromPoint' undeclared (first use this function) 

我哪里做错了?

最佳答案

您的代码有很多问题,但没有一个会导致您看到的错误消息。这是经过一些更正的代码,并添加了一些代码以至少显示某种测试结果:

#include <iostream>
#include <windows.h>

int main(int argc, char *argv[])
{
POINT p{ 0, 0 };
HMONITOR monitor = MonitorFromPoint(p, MONITOR_DEFAULTTONULL);

if (monitor == NULL)
std::cout << "No monitor found for point (0, 0)\n";
else {
MONITORINFOEX info;
info.cbSize = sizeof(info);

GetMonitorInfo(monitor, &info);
std::cout << "Monitor: " << info.szDevice << "\n";
}
}

我已经用 VC++ 2013 和 MinGW 4.8.1 测试了这个,在这两种情况下它都编译和运行没有任何问题,产生:

Monitor: \\.\DISPLAY1

...作为两种情况下的输出。

关于c++ - 试图检测监视器,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19863728/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com