是否可以在本机 Windows 8.1 桌面应用程序中确定屏幕方向
Is it possible to determine screen orientation in a native Windows 8.1 Desktop App?
我需要考虑设备可以处于的不同方向。又名横向、横向翻转、纵向或纵向翻转。我的应用是用本机C++编写的,并且作为桌面应用在 Windows 8.1 上运行(跨平台不是任何要求)。
我知道我可以使用此处概述的方法确定设备是纵向还是横向Microsoft:http://msdn.microsoft.com/en-us/library/ms812142.aspx
但是,无法区分横向和横向翻转(或纵向和纵向翻转)。
我可以通过检查 DisplayInformation.CurrentOrientation 属性来获得我需要的东西,但它是一个 WinRT API。这意味着如果我想使用它,我的应用程序必须使用 CLR,这是一个非启动器。
此外,我真的很想将我的应用程序保留为单个可执行文件,我认为没有一种干净的方法来做到这一点并同时调用托管 API。但话又说回来,我对本机 + 托管代码集成非常缺乏经验。
那么,有谁知道在Windows中仅使用本机代码来确定显示方向的任何方法?
我想
通了。这实际上比我想象的要容易得多。EnumDisplaySettings() 不会填充 DEVMODE 结构中的 dmDisplayOrientation 字段,但 EnumDisplaySettingsEx() 会填充。所以这实际上很容易:)
这里有一个很好的例子。
检测窗口大小在 XAML 中更改:
<Page x:Class="ClockCpp.MainPage"
Loaded="Page_Loaded"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:local="using:ClockCpp"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
mc:Ignorable="d"
Background="black"
SizeChanged="Page_SizeChanged">
然后使用是在纵向或横向之间切换:
Boolean t46 = true;
void ClockCpp::MainPage::Page_SizeChanged(Platform::Object^ sender, Windows::UI::Xaml::SizeChangedEventArgs^ e)
{
if (t46 == true)
{
t46 = false; // portrait
timetext->FontSize = 120; // 2/3 of 180
Othercontrols->Visibility = Windows::UI::Xaml::Visibility::Visible;
}
else
{
t46 = true; // landscape
timetext->FontSize = 180;
Othercontrols->Visibility = Windows::UI::Xaml::Visibility::Collapsed;
}
}
您还可以比较屏幕高度和宽度。如果宽度值更高,则它是横向,反之亦然。
#include <windows.h>
int theScreenWidth = GetSystemMetrics(SM_CXFULLSCREEN);
int theScreenHeight = GetSystemMetrics(SM_CYFULLSCREEN);
if (theScreenWidth > theScreenHeight)
MessageBox(NULL,"Run in landscape.","Landscape",MB_OK);
else
MessageBox(NULL,"Run in portrait.","Portrait",MB_OK);
相关文章:
- 试图在visual studio上用C++创建一个桌面应用程序
- FFmpeg:制作一个应用程序比直接使用ffmepg更好吗
- 在C应用程序中运行C++(带有STL)函数
- 使用VerQueryValue检索应用程序的文件描述
- Qt C++静态thread_local QNetworkAccessManager是线程应用程序的好选择吗
- 使用调试/崩溃报告将应用程序部署到客户端
- C++控制台应用程序阻止退出
- 码头化的C++应用程序是否向后兼容早期的内核版本
- 将应用程序从32位移植到64位时出现问题
- 如何改变c++应用程序的视觉效果
- WM_CTLCOLORSTATIC从未在WIN32应用程序中触发
- PC中的程序和PHONE中的本机描述应用程序之间的数据连接
- 应用程序崩溃并显示"symbol _ZdlPvm, version Qt_5 not defined in file libQt5Core.so.5 with link time reference"
- 示例外壳应用程序显示的 V8 "segmentation fault (core dumped)"错误
- phytec phyBOARD iMX-6在从闪存而不是SD卡运行qt5 opengles应用程序时表现不佳(FPS减半
- 为什么导入Mixed native/CLR lib.dll的本机C++应用程序没有在Mixed lib.dll中的外部变
- 在Qt中将应用程序方向锁定为横向
- 是否可以在本机 Windows 8.1 桌面应用程序中确定屏幕方向
- Qt Ui 应用程序屏幕方向
- TAB键不能在COM框架的MFC应用程序中工作.但是,方向键可以工作