Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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.

like image 720
Nate Koppenhaver Avatar asked Dec 31 '11 21:12

Nate Koppenhaver


People also ask

How to check window screen size?

Use window. innerWidth and window. innerHeight to get the current screen size of a page.

How do I find my monitor size on Glfw?

The physical size of a monitor in millimetres, or an estimation of it, can be retrieved with glfwGetMonitorPhysicalSize.


2 Answers

#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/

like image 150
eboix Avatar answered Sep 19 '22 06:09

eboix


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.

like image 26
Shaun07776 Avatar answered Sep 21 '22 06:09

Shaun07776