Skip to content

Instantly share code, notes, and snippets.

@drewchapin
Created July 26, 2016 17:56
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save drewchapin/df41aed441d023bca575a3cb49e307dd to your computer and use it in GitHub Desktop.
Save drewchapin/df41aed441d023bca575a3cb49e307dd to your computer and use it in GitHub Desktop.
Gets the screen resolution and dock status of the system.
/**
* @File GetScreenRes.cpp
* @Author Drew Chapin <druciferre@gmail.com>
* @Date 2014-09-17
*
* Gets the screen resolution and dock status of the system.
*/
#include <iostream>
#include <Windows.h>
#include <WinUser.h>
#ifndef SM_SYSTEMDOCKED
#define SM_SYSTEMDOCKED 0x2004
#endif
bool CALLBACK PrintScreenRes(HMONITOR hMonitor, HDC hdcMonitor, LPRECT lprcMonitor, LPARAM dwData)
{
MONITORINFOEX mi;
mi.cbSize = sizeof(MONITORINFOEX);
if( GetMonitorInfo(hMonitor, &mi) )
{
std::cout << mi.szDevice;
if( mi.dwFlags & MONITORINFOF_PRIMARY )
std::cout << " (Primary)";
std::cout << std::endl;
std::cout << "\tResolution: " << mi.rcMonitor.right - mi.rcMonitor.left << " x " << mi.rcMonitor.bottom - mi.rcMonitor.top << std::endl;
std::cout << "\tLocation: " << mi.rcMonitor.left << ", " << mi.rcMonitor.top << std::endl;
std::cout << "\tWork: " << mi.rcWork.left << ", " << mi.rcWork.top << std::endl << std::endl;
}
return true;
}
int main( int argc, char* argv[] )
{
/* doesn't seem to work... */
int docked = GetSystemMetrics(SM_SYSTEMDOCKED);
if( docked == 0 )
std::cout << "You are not docked." << std::endl;
else
std::cout << "You are docked." << std::endl;
int x = GetSystemMetrics(SM_CXSCREEN);
int y = GetSystemMetrics(SM_CYSCREEN);
std::cout << "System Metrics: " << x << " x " << y << std::endl;
EnumDisplayMonitors(NULL, NULL, (MONITORENUMPROC)PrintScreenRes, NULL);
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment