[英]Enable Tablet Mode on Windows 10 through Code?
Ive read various way on how to detect if a Windows 10 device is in Tablet Mode, most notably the topic below; 我已经阅读了各种方法来了解如何检测Windows 10设备是否处于平板电脑模式,最明显的是下面的主题;
How can I detect when Window 10 enters tablet mode in a Windows Forms application? 如何在Windows窗体应用程序中检测Window 10何时进入平板电脑模式?
I would like to enable/disable Tablet Mode through code (.Net C#) but I cant find any resources to achieve this. 我想通过代码(.Net C#)启用/禁用平板电脑模式,但我找不到任何资源来实现这一点。 Ive tried changing the registry key and sending a HWND_BROADCAST that a change has occurred but this doesn't initiate the change to tablet mode. 我已经尝试更改注册表项并发送已发生更改的HWND_BROADCAST,但这不会启动对平板电脑模式的更改。
Ive also tried using Spy++ style applications but cant see the messages being sent. 我也尝试使用Spy ++风格的应用程序,但无法看到正在发送的消息。
Does a method exist to do this? 是否存在执行此操作的方法?
There is no real way to do this in C#. 在C#中没有真正的方法可以做到这一点。 Of course you can change the registry key, but you will need a log off/on to change from or to tablet mode. 当然,您可以更改注册表项,但是您需要注销/启用以从平板电脑模式更改为平板电脑模式。
HKEY_CURRENT_USER\SOFTWARE\Microsoft\Windows\CurrentVersion\ImmersiveShell\TabletMode
Enable: 1 or disable 0 启用:1或禁用0
Since I had a problem that my WPF-App will not appear on startup with tablet mode on, I used a AutoHotKey script. 由于我的问题是我的WPF-App在平板电脑模式启动时不会出现,我使用了AutoHotKey脚本。 You can create a .exe as well. 您也可以创建.exe。 Source: https://autohotkey.com/boards/viewtopic.php?t=15619 资料来源: https : //autohotkey.com/boards/viewtopic.php?t = 15619
#NoEnv
SetBatchLines -1
ListLines Off
#NoTrayIcon
TABLETMODESTATE_DESKTOPMODE := 0x0
TABLETMODESTATE_TABLETMODE := 0x1
TabletModeController_GetMode(TabletModeController, ByRef mode) {
return DllCall(NumGet(NumGet(TabletModeController+0),3*A_PtrSize), "Ptr", TabletModeController, "UInt*", mode)
}
TabletModeController_SetMode(TabletModeController, _TABLETMODESTATE, _TMCTRIGGER := 4) {
return DllCall(NumGet(NumGet(TabletModeController+0),4*A_PtrSize), "Ptr", TabletModeController, "UInt", _TABLETMODESTATE, "UInt", _TMCTRIGGER)
}
ImmersiveShell := ComObjCreate("{C2F03A33-21F5-47FA-B4BB-156362A2F239}", "{00000000-0000-0000-C000-000000000046}")
TabletModeController := ComObjQuery(ImmersiveShell, "{4fda780a-acd2-41f7-b4f2-ebe674c9bf2a}", "{4fda780a-acd2-41f7-b4f2-ebe674c9bf2a}")
if (TabletModeController_GetMode(TabletModeController, mode) == 0)
TabletModeController_SetMode(TabletModeController, mode == TABLETMODESTATE_DESKTOPMODE ? TABLETMODESTATE_TABLETMODE : TABLETMODESTATE_DESKTOPMODE)
ObjRelease(TabletModeController), TabletModeController := 0
ObjRelease(ImmersiveShell), ImmersiveShell := 0 ; Can be freed after TabletModeController is created, instead
Poke around in here - You will want to focus on the samples for user interaction mode. 在这里徘徊 - 您将需要关注用户交互模式的示例。
NOTE: This is for UWP (Universal Windows Platform), aka Windows 10+, and you will need code for other versions of Windows if you are not targeting Win 10 only. 注意:这适用于UWP(通用Windows平台),也称为Windows 10+,如果您不仅仅针对Win 10,则需要其他版本Windows的代码。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.