问题描述
我不知所措,希望这里的任何人都能提供帮助.
I am in way over my head, and am hoping anyone here can help.
我正在使用在Windows Mobile OS版本5和/或6上运行的应用程序,该应用程序是用Embedded C ++编写的.问题在于,当用户执行某些操作来切换显示方向(例如打开设备的键盘)时,应用程序中的控件会变得一团糟并四处移动.
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:
ChangeDisplaySettingsEx函数 http://msdn.microsoft.com/zh-CN/library/dd183413(VS.85).aspx
ChangeDisplaySettingsEx http://msdn.microsoft.com/en-us/library/aa923082.aspx
Windows Mobile应用程序开发入门
http://www.eetimes.com/design/other/4006712/Windows Mobile应用程序开发入门
应用程序如何检测和响应屏幕旋转
http://msdn.microsoft.com/en-us/library/bb158688.aspx
DEVMODE http://msdn.microsoft.com/zh-CN/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);
}
您将需要一个顶级窗口(无父窗口)来处理 WM_SETTINGCHANGE
消息以检测旋转.
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;
这篇关于如何在Windows Mobile 5和更高版本中检测屏幕方向更改事件6应用程序,带有嵌入式C ++?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!