Skip to content

Instantly share code, notes, and snippets.

@NPatch
Last active February 24, 2016 11:58
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 NPatch/926a0755398ac985b07b to your computer and use it in GitHub Desktop.
Save NPatch/926a0755398ac985b07b to your computer and use it in GitHub Desktop.
//MUST have a valid window created to obtain a correct HMONITOR from the window's hWnd. Console windows don't give a correct HMONITOR.
//Neither did it work by calling GetConsoleWindow to get a hWnd for a console application and querying the HMONITOR from the console hWnd.
//Monitor from Window
HMONITOR monitor_handle = MonitorFromWindow(hWnd, MONITOR_DEFAULTTONEAREST);
MONITORINFOEX monitor_info;
monitor_info.cbSize = sizeof(MONITORINFOEX);
GetMonitorInfo(monitor_handle, &monitor_info);
DEVMODE devmode;
EnumDisplaySettings(
monitor_info.szDevice,
ENUM_CURRENT_SETTINGS,
&devmode
);
switch (devmode.dmDisplayOrientation){
case DMDO_90:
//Portrait
break;
case DMDO_180:
//Landscape(Flipped)
break;
case DMDO_270:
//Portrait(Flipped)
break;
default:
//Landscape
}
//Display name is monitor_info.szDevice and Orientation comes from the above switch in whichever form we need
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment