locked
How to change the orientation of my application window? RRS feed

  • Question

  • Hello,

    I have a problem to force the orientation of my window application. I am using the function ChangeDisplaySettingsEx to dot that but the problem is that when I loose the focus, the phone has also this new orientation. 

    So I would like to know if it is possible to associate an orientation with a specific window handle, in order to have no orientation modification when I loose the focus. It would be helpful, otherwise I think the dynamic orientation change when I loose/get focus etc.. can wake a lot of issues.

    I hope you can help m e

    See you
    Thursday, June 11, 2009 9:36 AM

Answers

  • Hi kikekoikan,

    As far as I know, we can not block orientation changed by block sliding key. This is OEM behavior. I tried to rechange it in WM_SIZE message, but it don't secceed. Like the code below:

     switch(message)
     {
     case WM_SIZE:

      int height = GetSystemMetrics (SM_CYSCREEN);
      int width = GetSystemMetrics (SM_CXSCREEN);
      if(width>height)  //landascap mode
      {
       DEVMODE dwmode1;

       dwmode1.dmSize = sizeof(DEVMODE);

       dwmode1.dmFields = DM_DISPLAYORIENTATION;

       dwmode1.dmDisplayOrientation = DMDO_0;

       ChangeDisplaySettingsEx(NULL,&dwmode1,NULL,CDS_RESET,NULL);   
       
      }
      

      break;
     }


    Best regards,
    Guang-Ming Bian - MSFT


    Please remember to mark the replies as answers if they help and unmark them if they provide no help
    Wednesday, June 17, 2009 6:30 AM

All replies

  • Hi kikekoikan,

    Please refer the link below for thr ScreenOrientation Property.

    http://msdn.microsoft.com/en-us/library/microsoft.windowsce.forms.systemsettings.screenorientation.aspx

    Hope you wil get some idea.

    Regards,
    Amit Rote
    Thursday, June 11, 2009 12:13 PM
  • Hi, please see the code if it can help you

    SystemSettings.ScreenOrientation = ScreenOrientation.Angle270;

    void OrientationWatcher_Changed(object sender, ChangeEventArgs args)
    {
          int newOrientation = (int)args.NewValue;

          if (condition on newOrientation)

               ChangeToLandscape();
    }

    public static void ChangeToLandscape()
    {
          SystemSettings.ScreenOrientation = ScreenOrientation.Angle270;
          Registry.SetValue(@"HKEY_LOCAL_MACHINE\System\GDI\ROTATION",
                   "Angle", 270, RegistryValueKind.DWord);
    }

    Friday, June 12, 2009 5:28 PM
  • Hi kikerkoikan,

    We can capture WM_Activate message to handle windows loosing or getting focus. But wParam value is different. Once we get the message, we can use ChangeDisplaySettingsEx to change its orientation. Like the code(MFC):

    void CTest2Dlg::OnActivate(UINT nState, CWnd* pWndOther, BOOL bMinimized)
    {
     CDialog::OnActivate(nState, pWndOther, bMinimized);

     // TODO: Add your message handler code here

     }

    nState is different between loosing or getting focus.

    Best regards,
    Guang-Ming Bian - MSFT


    Please remember to mark the replies as answers if they help and unmark them if they provide no help
    Monday, June 15, 2009 8:39 AM
  • Thank you for your help but it is not sufficient for my use case. Indeed I would like to force the portract mode only for my window application and deactivate all dynamically orientation change on this window (due to Accelerometer, Open/Close Keyboard, Kill/GetFocus).

    The problem with ChangeDisplaySettingsEx, is that this function freeze my application with some mobiles, if I use it in WM_ACTIVATE for example. So I would like to know if it is possible to associate an orientatin to my window application forever, and never listen other orientation change requests by the system.

    BEst Regards
    Monday, June 15, 2009 9:54 AM
  • For example I am using a LG phone with windows mobile. This phone changes the display each time the phone is turned by the user (accelerometer). 

    I would like to force the display to stay in portract. I know it is possible for others applications in the phone, and I would like to know how to do that. When the screen is rotated I receive WM_SIZE, if I return TRUE the display is rotated, so I don't know how to override this.

    Have you a clue please?
    Monday, June 15, 2009 1:27 PM
  • Hi kikekoikan,

    As far as I know, we can not block orientation changed by block sliding key. This is OEM behavior. I tried to rechange it in WM_SIZE message, but it don't secceed. Like the code below:

     switch(message)
     {
     case WM_SIZE:

      int height = GetSystemMetrics (SM_CYSCREEN);
      int width = GetSystemMetrics (SM_CXSCREEN);
      if(width>height)  //landascap mode
      {
       DEVMODE dwmode1;

       dwmode1.dmSize = sizeof(DEVMODE);

       dwmode1.dmFields = DM_DISPLAYORIENTATION;

       dwmode1.dmDisplayOrientation = DMDO_0;

       ChangeDisplaySettingsEx(NULL,&dwmode1,NULL,CDS_RESET,NULL);   
       
      }
      

      break;
     }


    Best regards,
    Guang-Ming Bian - MSFT


    Please remember to mark the replies as answers if they help and unmark them if they provide no help
    Wednesday, June 17, 2009 6:30 AM