Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is it possible to determine screen orientation in a native Windows 8.1 Desktop App?

I need to account for the different orientations a device can be in. Aka landscape, landscape flipped, portrait, or portrait flipped. My app is written in native C++ and is running on Windows 8.1 as a desktop app (cross platform is not a requirement in any way).

I know that I can determine if the device is in portrait or landscape using methods outlined by Microsoft here: http://msdn.microsoft.com/en-us/library/ms812142.aspx

However, there's no way to discern between landscape and landscape flipped (or portrait and portrait flipped).

I could get exactly what I need by checking the DisplayInformation.CurrentOrientation property but it's a WinRT API. Which means if I wanted to use it, my app would have to use CLR, which is a non-starter.

Also I'd really like to keep my app as a single executable and I don't think there's a clean way to do that and call managed APIs at the same time. But then again, I'm very inexperienced with native + managed code integration.

So, does anyone know of any way of figuring out display orientation using only native code in Windows?

like image 679
YasharBahman Avatar asked Nov 18 '25 19:11

YasharBahman


1 Answers

I figured this out. It's actually a lot easier than I thought. EnumDisplaySettings() doesn't populate the dmDisplayOrientation field in the DEVMODE struct, but EnumDisplaySettingsEx() does. So it's actually really easy :)

There's a good example here.

like image 196
YasharBahman Avatar answered Nov 21 '25 09:11

YasharBahman



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!