To detect the orientation (or change in orientation) is the most easy part of the problem. There is no display resolution that has the same width and height, so the orientation changes if the vertical becomes the horizontal resolution an vice versa. It is also possible to say that the width is always greater than the height.
#include <windows.h>
int theScreenWidth = GetSystemMetrics(SM_CXFULLSCREEN);
int theScreenHeight = GetSystemMetrics(SM_CYFULLSCREEN);
if (theScreenWidth > theScreenHeight)
MessageBox(NULL,"Run in landscape.","Landscape",MB_OK);
else
MessageBox(NULL,"Run in portrait.","Portrait",MB_OK);
more info:
http://msdn.microsoft.com/en-us/library/ms812142.aspx[
^]
So if you can already detect the changing of the screen resolution you can also detect orientation changes.
Information about the screen position can be found using
GetMonitorInfo
. Because the
rect
of MONITORINFO.rcMonitor is virtual, some of the coordinates could be negative if it is not the primary monitor. This is of course the case when the second monitor is left of the primary monitor.
more info:
http://msdn.microsoft.com/en-us/library/dd162826.aspx[
^]
I also found some info on where to find this info in the registry:
System\CurrentControlSet\Control\Video\{GUID}\0000
System\CurrentControlSet\Control\Video\{GUID}\0001
System\Currentcontrolset\4D36E968-E325-11CE-BFC1-08002BE10318\0000
System\Currentcontrolset\4D36E968-E325-11CE-BFC1-08002BE10318\0001
Machine\hardware\devicemap\video
Good luck!