How to get screen resolution in C++? [duplicate]

本小妞迷上赌 提交于 2019-12-29 19:21:07

问题


Possible Duplicate:
How to get the Monitor Screen Resolution from an hWnd?

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.


回答1:


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

Source: http://cppkid.wordpress.com/2009/01/07/how-to-get-the-screen-resolution-in-pixels/




回答2:


In Embarcadero C++ builder you can get it like this

Screen->Height;
Screen->Width;

This is specific for VCL framework which is supplied with Embarcadero products: C++ Builder, Delphi.



来源:https://stackoverflow.com/questions/8690619/how-to-get-screen-resolution-in-c

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