[英]How to detect tablet mode
I'm using the following code to detect if a user is in tablet mode or not. 我正在使用以下代码来检测用户是否处于平板电脑模式。 I'm on a Surface Pro and when I decouple the keyboard and make the PC into a tablet,
IsTabletMode
returns true (which it should.) When I use the "Tablet Mode" button without decoupling the screen, IsTabletMode
always returns false. 我在Surface Pro上,当我解耦键盘并将PC变为平板电脑时,
IsTabletMode
返回true(应该这样。)当我使用“平板电脑模式”按钮而不解耦屏幕时, IsTabletMode
总是返回false。 Has anyone experienced this and How can I resolve it? 有没有人经历过这个,我该如何解决?
/*
* Credit to Cheese Lover
* Retrieved From: http://stackoverflow.com/questions/31153664/how-can-i-detect-when-window-10-enters-tablet-mode-in-a-windows-forms-applicatio
*/
public static class TabletPCSupport
{
private static readonly int SM_CONVERTIBLESLATEMODE = 0x2003;
private static readonly int SM_TABLETPC = 0x56;
private Boolean isTabletPC = false;
public Boolean SupportsTabletMode { get { return isTabletPC; }}
public Boolean IsTabletMode
{
get
{
return QueryTabletMode();
}
}
static TabletPCSupport ()
{
isTabletPC = (GetSystemMetrics(SM_TABLETPC) != 0);
}
[DllImport("user32.dll", SetLastError = true, CharSet = CharSet.Auto, EntryPoint = "GetSystemMetrics")]
private static extern int GetSystemMetrics (int nIndex);
private static Boolean QueryTabletMode ()
{
int state = GetSystemMetrics(SM_CONVERTIBLESLATEMODE);
return (state == 0) && isTabletPC;
}
}
Edit 2: The SM_TABLETPC is only supported by Windows XP Tablet PC Edition and Windows Vista. 编辑2:SM_TABLETPC仅受Windows XP Tablet PC Edition和Windows Vista支持。 There doesn't seem to be any reference to Windows 10 here: https://msdn.microsoft.com/en-us/library/windows/desktop/ms700675(v=vs.85).aspx
这里似乎没有任何对Windows 10的引用: https : //msdn.microsoft.com/en-us/library/windows/desktop/ms700675(v = vs。85).aspx
You can use this: GetSystemMetrics(SM_CONVERTIBLESLATEMODE). 您可以使用此:GetSystemMetrics(SM_CONVERTIBLESLATEMODE)。 A “0” returned means it is in tablet mode.
返回“0”表示它处于平板电脑模式。 A “1” returned means it is in non-tablet mode.
返回“1”表示它处于非平板电脑模式。 https://software.intel.com/en-us/articles/how-to-write-a-2-in-1-aware-application
https://software.intel.com/en-us/articles/how-to-write-a-2-in-1-aware-application
Can you replace the QueryTabletMode method with this: 你可以用这个替换QueryTabletMode方法:
private static Boolean QueryTabletMode ()
{
int state = GetSystemMetrics(SM_CONVERTIBLESLATEMODE);
return (state == 0);
}
Edit: You might need to check this periodically as there's no event to see if the PC's tablet mode was turned on 编辑:您可能需要定期检查,因为没有事件可以查看PC的平板电脑模式是否已打开
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.