views:

64

answers:

1

Hello,

I am in way over my head, and am hoping anyone here can help.

I am working with an application that is running on Windows Mobile OS, version 5 and/or 6, which is written in Embedded C++. The problem is that controls in the app get all messed up and moved around when the user does something to switch the display orientation, such as opening the device's keyboard.

At this point, I have been looking at this forever and am getting a bit desperate. So, I guess I am now hoping for a quick and dirty solution to this, if one even exists. I'd like to try to effectively lock the device into portrait display, if possible, or perhaps find a way to detect an orientation switch so I can consistently force the display back to portrait mode.

I've been reading article after article (see partial list at bottom of post), but just haven't been able to work this out.

Is there some sort of event that fires that I can grab onto, and then apply code (yet to be worked out) to reset orientation?

Here's a list of some of the articles I've been trying to make sense of:

+2  A: 

This function should detect if the screen is in protrait mode:

BOOL IsPortrait()
{
  DEVMODE devmode;
  ZeroMemory(&devmode, sizeof(DEVMODE));
  devmode.dmSize = sizeof(DEVMODE);
  devmode.dmDisplayOrientation = DMDO_0;
  devmode.dmFields = DM_DISPLAYORIENTATION;
  ChangeDisplaySettingsEx(NULL, &devmode, NULL, CDS_TEST, NULL);

  return devmode.dmDisplayOrientation == DMDO_0;
}

This function should rotate to portrait mode:

void RotatePortrait(void)
{
  DEVMODE devmode;
  ZeroMemory(&devmode, sizeof(DEVMODE));
  devmode.dmSize = sizeof(DEVMODE);
  devmode.dmFields = DM_DISPLAYORIENTATION;
  devmode.dmDisplayOrientation = DMDO_0;

  ChangeDisplaySettingsEx(NULL, &devmode, NULL, 0, NULL);
}

You will need a top level window (no parent) that handles the WM_SETTINGCHANGE message to detect the rotation.

//...in WndProc...
case WM_SETTINGCHANGE:
  if (!IsPortrait())
  {
    RotatePortrait();
  }
  break;
gwell
WOW. That is exactly what I ahve been trying to figure out for ... almost a week now. You are amazing, gwell. If I could buy you a drink, I would.
campbelt