Pocket PC 上的屏幕旋转
我正在为袖珍电脑开发一个应用程序,它应该在横向模式下运行。
我编写了函数 SetScreenOrientation(int angle),它可以旋转屏幕。 该函数在应用程序启动和关闭时调用。 当我最小化/最大化方向时,我也想更改屏幕方向。 为此,我编辑了以下函数:
void CMainFrame::OnSize(UINT nType, int cx, int cy)
{
RECT r;
GetWindowRect(&r);
RECT rstatus;
rstatus.left = 0;
rstatus.top = 0;
rstatus.right = r.right;
rstatus.bottom = TOOLBAR_HEIGHT;
m_wndStatus.MoveWindow(&rstatus, TRUE);
RECT rcamera;
rcamera.left = 0;
rcamera.top = 0;
rcamera.right = r.right;
rcamera.bottom = r.bottom - TOOLBAR_HEIGHT;
m_wndCameraView.MoveWindow(&rcamera, TRUE);
if(nType == SIZE_MAXIMIZED)
{
CScreenOrientation::SetScreenOrientation(270);
}
if(nType == SIZE_MINIMIZED)
{
CScreenOrientation::SetScreenOrientation(0);
}
}
问题是,当我最小化应用程序时,该函数会执行多次,因此屏幕首先旋转回 0 度,然后旋转到 270 度。
在调试时,我可以看到第二次执行该函数时,执行了以下 wincore 代码:
BOOL CWnd::OnWndMsg(UINT message, WPARAM wParam, LPARAM lParam, LRESULT* pResult)
{
...
switch (lpEntry->nSig)
{
...
case AfxSig_v_u_ii:
(this->*mmf.pfn_v_u_i_i)(static_cast<UINT>(wParam), LOWORD(lParam), HIWORD(lParam));
break;
...
}
}
有谁知道在应用程序最小化/最大化上设置屏幕方向的任何其他方法或任何可能阻止多个函数执行的技巧?
I am developing an application for pocket PC which should run in landscape mode.
I wrote the function SetScreenOrientation(int angle), which rotates the screen. This function is called on application start and on application close. I want to change the screen orientation when I minimize/maximize orientation as well. To do this I edited the following function:
void CMainFrame::OnSize(UINT nType, int cx, int cy)
{
RECT r;
GetWindowRect(&r);
RECT rstatus;
rstatus.left = 0;
rstatus.top = 0;
rstatus.right = r.right;
rstatus.bottom = TOOLBAR_HEIGHT;
m_wndStatus.MoveWindow(&rstatus, TRUE);
RECT rcamera;
rcamera.left = 0;
rcamera.top = 0;
rcamera.right = r.right;
rcamera.bottom = r.bottom - TOOLBAR_HEIGHT;
m_wndCameraView.MoveWindow(&rcamera, TRUE);
if(nType == SIZE_MAXIMIZED)
{
CScreenOrientation::SetScreenOrientation(270);
}
if(nType == SIZE_MINIMIZED)
{
CScreenOrientation::SetScreenOrientation(0);
}
}
The problem is that when I minimize the application the function is executed more than once so the screen first rotates back to 0 degrees and then it rotates to 270 degrees.
While debugging I can see that the second time the function is executed the following piece of wincore code is executed:
BOOL CWnd::OnWndMsg(UINT message, WPARAM wParam, LPARAM lParam, LRESULT* pResult)
{
...
switch (lpEntry->nSig)
{
...
case AfxSig_v_u_ii:
(this->*mmf.pfn_v_u_i_i)(static_cast<UINT>(wParam), LOWORD(lParam), HIWORD(lParam));
break;
...
}
}
Does anyone know any other way to set the screen orientation on application minimize/maximize or any trick that could prevent multiple function execution?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
一方面,SetScreenOrientation 似乎会给您另一个 OnSize 通知,因此您希望检测递归调用,并且在发生这种情况时不执行任何操作。
更重要的是,你如何知道用户真正想要什么方向? 当您的应用程序启动时,您可以检查方向并保存。 但是,如果用户在您碰巧跑步时改变了方向,那么当您将其改回来时,他们将不会高兴。 也许您可以检查系统设置更改的通知并检测用户是否自行更改了方向。
For one thing, it seems likely that SetScreenOrientation is going to give you another OnSize notification, so you want to detect recursive calls and do nothing when that happens.
More importantly, how do you know what orientation the user really wants? When your application starts up you can check the orientation and save that. But if the user changed the orientation while you happened to be running, they won't be happy when you change it back. Maybe you can check notifications of system settings changes and detect if the user changed the orientation themselves.