Bagaimana cara mendapatkan resolusi layar dalam C++?

< Akhir dari teks yang disisipkan secara otomatis - >

Apakah ada cara untuk mendapatkan resolusi layar di C++?
Saya telah mencari di MSDN tetapi tidak berhasil. Hal terdekat yang saya temukan adalah ChangeDisplaySettingsEx() tetapi tampaknya tidak ada cara untuk mengembalikan res tanpa mengubahnya.

Larutan

#include "wtypes.h"
#include 
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 
Komentar (6)

Di Embarcadero C++ builder Anda bisa mendapatkannya seperti ini

Screen->Height;
Screen->Width;

Ini khusus untuk kerangka kerja VCL yang disertakan dengan produk Embarcadero: C++ Builder, Delphi.

Komentar (2)