如何在C ++中获得屏幕分辨率? [英] How to get screen resolution in C++?
本文介绍了如何在C ++中获得屏幕分辨率?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
有没有办法在C ++中获得屏幕分辨率?
我搜索了MSDN,但没有运气。我发现的最近的事情是 ChangeDisplaySettingsEx(),但是似乎没有办法只需返回res而不更改它。
Is there a way to get the screen resolution in C++?
I have searched MSDN but with no luck. The closest thing I found was ChangeDisplaySettingsEx() but that doesn't seem to have a way to just return the res without changing it.
推荐答案
#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;
}
资料来源:http://cppkid.wordpress.com/2009/01/07/how-to-get-the-screen -resolution-in-pixels /
这篇关于如何在C ++中获得屏幕分辨率?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文