通过代码在Windows 10上启用平板电脑模式? [英] Enable Tablet Mode on Windows 10 through Code?

查看:93
本文介绍了通过代码在Windows 10上启用平板电脑模式?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经阅读了有关如何检测Windows 10设备是否处于平板电脑模式的各种方法,最值得注意的是以下主题;

Ive read various way on how to detect if a Windows 10 device is in Tablet Mode, most notably the topic below;

如何检测Windows 10在Windows Forms应用程序中何时进入平板电脑模式?

我想通过代码(.Net C#)启用/禁用平板电脑模式,但是我找不到任何资源来实现此目的.香港专业教育学院试图更改注册表项,并发送HWND_BROADCAST发生了更改,但这不会启动对平板电脑模式的更改.

I would like to enable/disable Tablet Mode through code (.Net C#) but I cant find any resources to achieve this. 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.

我也尝试过使用Spy ++样式的应用程序,但看不到正在发送的消息.

Ive also tried using Spy++ style applications but cant see the messages being sent.

是否存在执行此操作的方法?

Does a method exist to do this?

推荐答案

在C#中没有真正的方法来做到这一点.当然,您可以更改注册表项,但是您需要注销/登录才能在平板电脑模式之间切换.

There is no real way to do this in 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

启用:1或禁用0

由于我有一个问题,我的WPF应用程序在平板电脑模式下启动时不会出现,因此我使用了AutoHotKey脚本.您也可以创建一个.exe.来源: https://autohotkey.com/boards/viewtopic.php?t=15619

Since I had a problem that my WPF-App will not appear on startup with tablet mode on, I used a AutoHotKey script. You can create a .exe as well. Source: 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   

这篇关于通过代码在Windows 10上启用平板电脑模式?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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