C++ 如何在C++;?
可能重复:C++ 如何在C++;?,c++,windows,winapi,screen-resolution,C++,Windows,Winapi,Screen Resolution,可能重复: 在C++中有没有一种方法可以获得屏幕分辨率? 我已经搜索了MSDN,但没有运气。我发现的最接近的东西是,它似乎没有办法只返回RES而不改变它。 < P>在ActuCabeRC++ C++ Builder中,你可以得到这样的 Screen->Height; Screen->Width; 这是针对提供了带有BuilCabeRo产品的VCL框架:C++ Builder,Delphi ./P> 包含“WyType .h” #include "wtypes.h" #includ
在C++中有没有一种方法可以获得屏幕分辨率?
我已经搜索了MSDN,但没有运气。我发现的最接近的东西是,它似乎没有办法只返回RES而不改变它。 < P>在ActuCabeRC++ C++ Builder中,你可以得到这样的
Screen->Height;
Screen->Width;
这是针对提供了带有BuilCabeRo产品的VCL框架:C++ Builder,Delphi ./P> <代码>包含“WyType .h”
#include "wtypes.h"
#include <iostream>
using namespace std;
// Get the horizontal and vertical screen sizes in pixel
void GetDesktopResolution(int& horizontal, int& vertical)
{
RECT desktop;
// Get a handle to the desktop window
const HWND hDesktop = GetDesktopWindow();
// Get the size of screen to the variable desktop
GetWindowRect(hDesktop, &desktop);
// The top left corner will have coordinates (0,0)
// and the bottom right corner will have coordinates
// (horizontal, vertical)
horizontal = desktop.right;
vertical = desktop.bottom;
}
int main()
{
int horizontal = 0;
int vertical = 0;
GetDesktopResolution(horizontal, vertical);
cout << horizontal << '\n' << vertical << '\n';
return 0;
}
#包括
使用名称空间std;
//以像素为单位获取水平和垂直屏幕大小
void GetDesktopResolution(整数和水平、整数和垂直)
{
矩形桌面;
//获取桌面窗口的句柄
const HWND hDesktop=GetDesktopWindow();
//获取可变桌面的屏幕大小
GetWindowRect(hDesktop和桌面);
//左上角将有坐标(0,0)
//右下角有坐标
//(水平、垂直)
水平=桌面。右;
垂直=桌面。底部;
}
int main()
{
int水平=0;
int垂直=0;
GetDesktopResolution(水平、垂直);
cout-Related:好的,这个问题的一个答案是有效的。(
GetSystemMetrics()
)标记为重复项这对多个监视器有效吗?以下是如何对多个监视器进行此操作(在答案中):这将为您提供不带TaskBar的桌面大小。对于Windows 10中分辨率为3840 x 2160的4K屏幕,此方法返回1536 x 864。有人能解释一下吗?…因此,在winMain中添加SetProcessDPIAware();
作为第一件事似乎可以解决此问题。此答案适用于其他Embarcadero编译器,如Delphi(即width:=Screen.width;)。OP没有明确说明目标平台或编译器,因此此答案没有错(指定的是Embarcadero)。include Display*disp=XOpenDisplay(NULL);Screen*scrn=DefaultScreenOfDisplay(disp);int height=scrn->height;int width=scrn->width;使用链接器选项-lX11
。