我正在使用以下代码来检测用户是否处于平板电脑模式.我在Surface Pro上,当我解除键盘并将PC变成平板电脑时,IsTabletMode返回true(应该这样.)当我使用"平板电脑模式"按钮而不解耦屏幕时,IsTabletMode总是返回false.有没有人经历过这个,我该如何解决?
/*
* 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;
}
}
Run Code Online (Sandbox Code Playgroud)
编辑 2:\nSM_TABLETPC 仅受 Windows XP Tablet PC Edition 和 Windows Vista 支持。\n这里似乎没有任何对 Windows 10 的引用:https://msdn.microsoft.com/en-us/library/windows/desktop/ms700675 (v=vs.85).aspx
\n\n您可以使用这个:\nGetSystemMetrics(SM_CONVERTIBLESLATEMODE)。返回的 \xe2\x80\x9c0\xe2\x80\x9d 表示它处于平板电脑模式。返回的 \xe2\x80\x9c1\xe2\x80\x9d 表示它处于非平板电脑模式。\n https://software.intel.com/en-us/articles/how-to-write-a-2合一感知应用程序
\n\n您可以将 QueryTabletMode 方法替换为:
\n\n private static Boolean QueryTabletMode ()\n {\n int state = GetSystemMetrics(SM_CONVERTIBLESLATEMODE);\n return (state == 0);\n }\nRun Code Online (Sandbox Code Playgroud)\n\n编辑:\n您可能需要定期检查此项,因为没有事件可查看 PC 的平板电脑模式是否已打开
\n| 归档时间: |
|
| 查看次数: |
1572 次 |
| 最近记录: |