See the dmDisplayOrientation member of the DEVMODE structure. You can use EnumDisplaySettings to get the structure.
Identify display orientation (flipped or not) in Win32 app
Shyam Butani
330
Reputation points
Hello,
In Win32 app, I want to capture event when display orientation is changed. below is the sample code snippet to get an idea:
LRESULT CALLBACK WindowProc(HWND hWnd, UINT messageCode, WPARAM wParam, LPARAM lParam)
{
switch (messageCode)
{
case WM_DISPLAYCHANGE: {
// Handle display orientation change
int width = LOWORD(lParam);
int height = HIWORD(lParam);
if (width > height) {
// ORIENTATION_LANDSCAPE
}
else {
// ORIENTATION_PORTRAIT
}
break;
}
default:
return DefWindowProc(hWnd, messageCode, wParam, lParam);
}
return 0;
}
Using this way, I'm able to identify whether new orientation is landscape or portrait. That is fine and working.
I wanted to know if there is any way to find out that current display orientation is 'landscape' or 'landscape_flipped'?
Similar for 'portrait' and 'portrait_flipped'.
Thanks.
Accepted answer
2 additional answers
Sort by: Most helpful
-
RLWA32 45,941 Reputation points
2024-05-21T12:34:36.9566667+00:00 -
Shyam Butani 330 Reputation points
2024-05-22T06:06:01.7766667+00:00 Following worked for me.
DEVMODEW dm; // Initialize the DEVMODE structure ZeroMemory(&dm, sizeof(dm)); dm.dmSize = sizeof(dm); // Retrieve display settings if (EnumDisplaySettingsExW(NULL, ENUM_CURRENT_SETTINGS, &dm, 0)) { // Check the display orientation if (dm.dmDisplayOrientation == DMDO_DEFAULT) { printf("Display Orientation: Default\n"); } else if (dm.dmDisplayOrientation == DMDO_90) { printf("Display Orientation: 90 degrees\n"); } else if (dm.dmDisplayOrientation == DMDO_180) { printf("Display Orientation: 180 degrees\n"); } else if (dm.dmDisplayOrientation == DMDO_270) { printf("Display Orientation: 270 degrees\n"); } }