-
void MainAppWindow::setLayoutOrientation(int rotate) { // initialize the DEVMODE structure DEVMODE dm; ZeroMemory(&dm, sizeof(dm)); dm.dmSize = sizeof(dm); // only change first/default display (index=0) if (0 != EnumDisplaySettings(NULL, ENUM_CURRENT_SETTINGS, &dm)) { LOG_INFO("Current orientation"); switch(dm.dmDisplayOrientation) { case DMDO_DEFAULT: LOG_INFO("DMDO_DEFAULT"); break; case DMDO_90: LOG_INFO("DMDO_90"); break; case DMDO_180: LOG_INFO("DMDO_180"); break; case DMDO_270: LOG_INFO("DMDO_270"); break; } // Determine the current orientation int currentOrientation = dm.dmDisplayOrientation; int newOrientation; // Set the new orientation switch (rotate) { case 0: newOrientation = DMDO_DEFAULT; break; case 90: newOrientation = DMDO_90; break; case 180: newOrientation = DMDO_180; break; case 270: newOrientation = DMDO_270; break; default: LOG_INFO("Something went wrong, aborting"); return; } LOG_INFO("Panning height : " + QString::number(dm.dmPanningHeight) + " Panning width: " + QString::number(dm.dmPaperWidth) ); LOG_INFO("Colour resolution : " + QString::number(dm.dmBitsPerPel) + " bits per pixel"); LOG_INFO("Height in pixels : " + QString::number(dm.dmPelsHeight)); LOG_INFO("Width in pixels : " + QString::number(dm.dmPelsWidth)); // parse parameter if(rotate != 0 && rotate != 90 && rotate != 180 && rotate != 270) { LOG_INFO("incorrect rotation selected"); } else { if ((currentOrientation == DMDO_DEFAULT && newOrientation == DMDO_90) || (currentOrientation == DMDO_90 && newOrientation == DMDO_DEFAULT) || (currentOrientation == DMDO_DEFAULT && newOrientation == DMDO_270) || (currentOrientation == DMDO_270 && newOrientation == DMDO_DEFAULT)) { // swap height and width DWORD tmp = dm.dmPelsHeight; dm.dmPelsHeight = dm.dmPelsWidth; dm.dmPelsWidth = tmp; } LOG_INFO("Height in pixels after swapping : " + QString::number(dm.dmPelsHeight)); LOG_INFO("Width in pixels after swapping : " + QString::number(dm.dmPelsWidth)); // select fields which have changed dm.dmFields = DM_PELSWIDTH | DM_PELSHEIGHT | DM_DISPLAYORIENTATION; // set angle switch(rotate) { case 0: dm.dmDisplayOrientation = DMDO_DEFAULT; break; case 90: dm.dmDisplayOrientation = DMDO_90; break; case 180: dm.dmDisplayOrientation = DMDO_180; break; case 270: dm.dmDisplayOrientation = DMDO_270; break; default: LOG_INFO("Something went wrong, aborting"); exit(0); } LONG ret = ChangeDisplaySettingsEx(NULL, &dm, NULL, 0, NULL); //CDS_RESET, NULL); //0); LOG_INFO("ChangeDisplaySettingsEx returned " + QString::number(ret)); switch(ret) { case DISP_CHANGE_SUCCESSFUL: LOG_INFO("display successfully changed"); break; case DISP_CHANGE_BADDUALVIEW: LOG_INFO("The settings change was unsuccessful because the system is DualView capable"); break; case DISP_CHANGE_BADFLAGS: LOG_INFO("An invalid set of flags was passed in."); break; case DISP_CHANGE_BADMODE: LOG_INFO("The graphics mode is not supported."); break; case DISP_CHANGE_BADPARAM: LOG_INFO("An invalid parameter was passed in. This can include an invalid flag or combination of flags."); break; case DISP_CHANGE_FAILED: LOG_INFO("The display driver failed the specified graphics mode."); break; case DISP_CHANGE_NOTUPDATED: LOG_INFO("Unable to write settings to the registry."); break; case DISP_CHANGE_RESTART: LOG_INFO("The computer must be restarted for the graphics mode to work."); break; } } } }
Hi All , I have done the orientation chnage successfully with the above code. I hope it may help some one.
Note : I handled all four possibilties which windows provides -portrait -portrait (flipped) -landscape _landscape (flipped)
we just need to call the method with the respective angle Landscape - 0 Portait - 90 landscape (flipped) - 180 portrait (flipped) - 270
-
Hi,
nice,
maybe you want to move this topic to theShowcase
category as it is not a question or an issue, but already a solution you want to share.(Or you wait until some @moderators might move it)
-