开发者

How to Detect Screen Orientation Change Event in Windows Mobile 5 & 6 App, With Embedded C++?

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

I am working with an application that is running on W开发者_Go百科indows 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:

  • Changing Screen Orientation Programmatically http://msdn.microsoft.com/en-us/library/ms812499.aspx

  • ChangeDisplaySettingsEx Function http://msdn.microsoft.com/en-us/library/dd183413(VS.85).aspx

  • ChangeDisplaySettingsEx http://msdn.microsoft.com/en-us/library/aa923082.aspx

  • "Adapt Your App" http://social.msdn.microsoft.com/Forums/en-US/vssmartdevicesnative/thread/6656f82e-6de8-4fc7-8e17-61dbe6bc5f77

  • Getting Started With Windows Mobile Application Development

    http://www.eetimes.com/design/other/4006712/Getting-Started-With-Windows-Mobile-Application-Development

  • How Applications Detect and Respond to Screen Rotation

    http://msdn.microsoft.com/en-us/library/bb158688.aspx

  • DEVMODE http://msdn.microsoft.com/en-us/library/dd183565(VS.85).aspx


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;


Calling ChangeDisplaySettingsEx() with the CDS_TEST flag only tests if the mode could be set; it does not query the current settings. Instead, use EnumDisplaySettingsEx() with ENUM_CURRENT_SETTINGS:

DEVMODE devmode;
ZeroMemory(&devmode, sizeof(devmode));
devmode.dmSize = sizeof(DEVMODE);
EnumDisplaySettings(NULL, ENUM_CURRENT_SETTINGS, &devmode);

// returned rotation is relative to the natural (default) rotation for this display
switch(devmode.dmDisplayOrientation)
    {
    case DMDO_90  : ...
    case DMDO_180 : ...
    case DMDO_270 : ...
    case DMDO_DEFAULT : ...
    }
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜