Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
//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