如何防止屏幕在平板电脑上自动旋转? [英] How to prevent the screen from automatically rotating on a tablet?

查看:327
本文介绍了如何防止屏幕在平板电脑上自动旋转?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

Microsoft在下面的链接中描述了两种方法来限制平板电脑上应用程序屏幕的旋转。



http://msdn.microsoft.com/en-ca/library/windows/apps/hh700342.aspx



发生的事情是delphi的(XE3)TRibbon无法很好地处理旋转。



正如预期的那样,MS网站描述了如何从MS开发产品中做到这一点。我在我的Delphi项目中看不到该怎么做。



方法1:



将此添加到您的appxmanifest文件中:

 < InitialRotationPreference> 
< Rotation Preference = landscape />
< Rotation Preference = landscapeFlipped />
< / InitialRotationPreference>

我还没有找到appxmanifest应该在哪里/如何成为应用程序的一部分,所以我可以



方法2:



使用代码调用此: / p>

  Windows.Graphics.Display.DisplayProperties.AutoRotationPreferences = 
Windows.Graphics.Display.DisplayOrientations.Landscape;

要将其迁移到delphi,我需要知道API DLL信息,以便可以执行类似的操作



有什么想法吗?



是否可以使用COM对象或DLL来访问此对象?

解决方案

这些调用是为了禁用WindowsRT应用程序(FKA Metro)的旋转功能,而您无法使用Delphi构建该应用程序。即使是Metropolis应用程序仍然是桌面应用程序。有一个英特尔网站上的解决方案



基于 X-Ray 我清理了代码:

  unit MetroDisplayRotation; 

(*
*用法:TMetroDisplayRotation.SetDisplayAutoRotationPreferences(
* TMetroDisplayRotation.ORIENTATION_PREFERENCE_LANDSCAPE或
* TMetroDisplayRotation.ORIENTATION_PREFERENCE_LANDSCAPE_FLIPPED));


接口

类型
TMetroDisplayRotation =类
public const
ORIENTATION_PREFERENCE_NONE = $ 0;
ORIENTATION_PREFERENCE_LANDSCAPE = $ 1;
ORIENTATION_PREFERENCE_PORTRAIT = $ 2;
ORIENTATION_PREFERENCE_LANDSCAPE_FLIPPED = $ 4;
ORIENTATION_PREFERENCE_PORTRAIT_FLIPPED = $ 8;

类过程SetDisplayAutoRotationPreferences(ORIENTATION_PREFERENCE:Integer);
结尾;

实施

使用
SysUtils,Windows;

{TMetroDisplayRotation}

类过程TMetroDisplayRotation.SetDisplayAutoRotationPreferences(
ORIENTATION_PREFERENCE:Integer);
类型
TSDARP =过程(ORIENTATION_PREFERENCE:整数); stdcall;
var
UserHandle:THandle;
SDARP:TSDARP;
开始
UserHandle:= GetModuleHandle(’User32.dll’);
@SDARP:= GetProcAddress(UserHandle, SetDisplayAutoRotationPreferences);
如果已分配(SDARP),则
SDARP(ORIENTATION_PREFERENCE);
结尾;

结尾。

您将要确保仅在Windows 8上调用此函数,因为该过程在其他地方不存在。



用法: TMetroDisplayRotation.SetDisplayAutoRotationPreferences(TMetroDisplayRotation.ORIENTATION_PREFERENCE_LANDSCAPE或TMetroDisplayRotation.ORIENTATION_PREFERENCE_LANDSCAPE_FLIPPED); b

另一个BAD选项是禁用整个平板电脑。只需在注册表中转到 HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\AutoRotation 并更改 Enable 变为 0


In the link below, Microsoft describes two ways to limit rotation of an application screen on a tablet.

http://msdn.microsoft.com/en-ca/library/windows/apps/hh700342.aspx

what's happening is that delphi's (XE3) TRibbon doesn't handle rotation well. it tends to get hung.

as would be expected, the MS web site describes how to do this from MS development products. I don't see how I can do this in my Delphi project.

Method 1:

add this to your appxmanifest file:

<InitialRotationPreference>
    <Rotation Preference="landscape"/>
    <Rotation Preference="landscapeFlipped"/>
</InitialRotationPreference>

I haven't yet found where/how the appxmanifest should be part of the application so I can do this in delphi.

Method 2:

call this with code:

 Windows.Graphics.Display.DisplayProperties.AutoRotationPreferences =
            Windows.Graphics.Display.DisplayOrientations.Landscape;

to migrate this to delphi, I'd need to know API DLL information so I could do something similar.

Any ideas?

Could there be a COM object or DLL that gives us access to this?

解决方案

Those calls are to disable rotation for a WindowsRT application (FKA Metro) which you cannot build with Delphi (yet). Even a Metropolis app is still a desktop app. There is a solution on the Intel site.

Based on feedback from X-Ray I cleaned up the code:

unit MetroDisplayRotation;

(* 
 *  Usage: TMetroDisplayRotation.SetDisplayAutoRotationPreferences(
 *           TMetroDisplayRotation.ORIENTATION_PREFERENCE_LANDSCAPE or 
 *           TMetroDisplayRotation.ORIENTATION_PREFERENCE_LANDSCAPE_FLIPPED);
 *)

interface

type
  TMetroDisplayRotation = class
  public const
    ORIENTATION_PREFERENCE_NONE = $0;
    ORIENTATION_PREFERENCE_LANDSCAPE = $1;
    ORIENTATION_PREFERENCE_PORTRAIT = $2;
    ORIENTATION_PREFERENCE_LANDSCAPE_FLIPPED = $4;
    ORIENTATION_PREFERENCE_PORTRAIT_FLIPPED = $8;

    class procedure SetDisplayAutoRotationPreferences(ORIENTATION_PREFERENCE: Integer);
  end;

implementation

uses
  SysUtils, Windows;

{ TMetroDisplayRotation }

class procedure TMetroDisplayRotation.SetDisplayAutoRotationPreferences(
  ORIENTATION_PREFERENCE: Integer);
type
  TSDARP = procedure(ORIENTATION_PREFERENCE: Integer); stdcall;
var
  UserHandle: THandle;
  SDARP: TSDARP;
begin
  UserHandle := GetModuleHandle('User32.dll');
  @SDARP := GetProcAddress(UserHandle, 'SetDisplayAutoRotationPreferences');
  if Assigned(SDARP) then
    SDARP(ORIENTATION_PREFERENCE);
end;

end.

You will want to make sure you ONLY call this on Windows 8 since that procedure doesn't exist elsewhere.

Usage: TMetroDisplayRotation.SetDisplayAutoRotationPreferences(TMetroDisplayRotation.ORIENTATION_PREFERENCE_LANDSCAPE or TMetroDisplayRotation.ORIENTATION_PREFERENCE_LANDSCAPE_FLIPPED);

Another BAD option is to disable it for the entire tablet. Just go to HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\AutoRotation in the registry and change Enable to 0.

这篇关于如何防止屏幕在平板电脑上自动旋转?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆