wpf 如何关闭 Windows 8.1 手势并在我的触摸屏上设置魅力栏
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/19889683/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
How do I turn off windows 8.1 gestures and setting charm bar on my touch Screen
提问by user2976052
I Have an Touch screen Dell and Windows 8.1 Single language installed, When I move my finger from Right edge towards the middle, Windows 8 will bring up setting charm bar OR when i move my finger from middle top edge towards down windows 8 hide my application and bring up start menu.
我安装了触摸屏戴尔和 Windows 8.1 单语言,当我将手指从右边缘向中间移动时,Windows 8 将显示设置魅力栏,或者当我将手指从中间顶部边缘向下移动时,Windows 8 隐藏我的应用程序并调出开始菜单。
This is a problem because I'am developing a Kiosk Application on WPF, and i can't let user see setting or close Kiosk application.
这是一个问题,因为我正在 WPF 上开发 Kiosk 应用程序,我不能让用户看到设置或关闭 Kiosk 应用程序。
I tried to disabled that, but couldn't, the easy solution would be to run on another OS or downgrade to windows 7, but the machines will be running Windows 8.1 single language and there's not much I can do about that.
我试图禁用它,但不能,简单的解决方案是在另一个操作系统上运行或降级到 Windows 7,但机器将运行 Windows 8.1 单一语言,对此我无能为力。
回答by Ron Schuler
Here is a way to do it via .NET interop instead of compiling a C++ native DLL:
这是一种通过 .NET 互操作而不是编译 C++ 本机 DLL 来实现的方法:
Imports System.Runtime.InteropServices
Imports System.Runtime.CompilerServices
Public Class EdgeGestureUtil
Private Shared DISABLE_TOUCH_SCREEN As Guid = New Guid("32CE38B2-2C9A-41B1-9BC5-B3784394AA44")
Private Shared IID_PROPERTY_STORE As Guid = New Guid("886d8eeb-8cf2-4446-8d02-cdba1dbdcf99")
Private Shared VT_BOOL As Short = 11
#Region "Structures"
<StructLayout(LayoutKind.Sequential, Pack:=4)> _
Public Structure PropertyKey
Public Sub New(guid As Guid, pid As UInt32)
fmtid = guid
Me.pid = pid
End Sub
<MarshalAs(UnmanagedType.Struct)> _
Public fmtid As Guid
Public pid As UInteger
End Structure
<StructLayout(LayoutKind.Explicit)> _
Public Structure PropVariant
<FieldOffset(0)> _
Public vt As Short
<FieldOffset(2)> _
Private wReserved1 As Short
<FieldOffset(4)> _
Private wReserved2 As Short
<FieldOffset(6)> _
Private wReserved3 As Short
<FieldOffset(8)> _
Private cVal As SByte
<FieldOffset(8)> _
Private bVal As Byte
<FieldOffset(8)> _
Private iVal As Short
<FieldOffset(8)> _
Public uiVal As UShort
<FieldOffset(8)> _
Private lVal As Integer
<FieldOffset(8)> _
Private ulVal As UInteger
<FieldOffset(8)> _
Private intVal As Integer
<FieldOffset(8)> _
Private uintVal As UInteger
<FieldOffset(8)> _
Private hVal As Long
<FieldOffset(8)> _
Private uhVal As Long
<FieldOffset(8)> _
Private fltVal As Single
<FieldOffset(8)> _
Private dblVal As Double
<FieldOffset(8)> _
Public boolVal As Boolean
<FieldOffset(8)> _
Private scode As Integer
'CY cyVal;
<FieldOffset(8)> _
Private [date] As DateTime
<FieldOffset(8)> _
Private filetime As System.Runtime.InteropServices.ComTypes.FILETIME
'CLSID* puuid;
'CLIPDATA* pclipdata;
'BSTR bstrVal;
'BSTRBLOB bstrblobVal;
<FieldOffset(8)> _
Private blobVal As Blob
'LPSTR pszVal;
<FieldOffset(8)> _
Private pwszVal As IntPtr
'LPWSTR
'IUnknown* punkVal;
'IDispatch* pdispVal;
' IStream* pStream;
' IStorage* pStorage;
' LPVERSIONEDSTREAM pVersionedStream;
' LPSAFEARRAY parray;
' CAC cac;
' CAUB caub;
' CAI cai;
' CAUI caui;
' CAL cal;
' CAUL caul;
' CAH cah;
' CAUH cauh;
' CAFLT caflt;
' CADBL cadbl;
' CABOOL cabool;
' CASCODE cascode;
' CACY cacy;
' CADATE cadate;
' CAFILETIME cafiletime;
' CACLSID cauuid;
' CACLIPDATA caclipdata;
' CABSTR cabstr;
' CABSTRBLOB cabstrblob;
' CALPSTR calpstr;
' CALPWSTR calpwstr;
' CAPROPVARIANT capropvar;
' CHAR* pcVal;
' UCHAR* pbVal;
' SHORT* piVal;
' USHORT* puiVal;
' LONG* plVal;
' ULONG* pulVal;
' INT* pintVal;
' UINT* puintVal;
' FLOAT* pfltVal;
' DOUBLE* pdblVal;
' VARIANT_BOOL* pboolVal;
' DECIMAL* pdecVal;
' SCODE* pscode;
' CY* pcyVal;
' DATE* pdate;
' BSTR* pbstrVal;
' IUnknown** ppunkVal;
' IDispatch** ppdispVal;
' LPSAFEARRAY* pparray;
' PROPVARIANT* pvarVal;
'
''' <summary>
''' Helper method to gets blob data
''' </summary>
Private Function GetBlob() As Byte()
Dim Result As Byte() = New Byte(blobVal.Length - 1) {}
Marshal.Copy(blobVal.Data, Result, 0, Result.Length)
Return Result
End Function
''' <summary>
''' Property value
''' </summary>
Public ReadOnly Property Value() As Object
Get
Dim ve As VarEnum = vt
Select Case ve
Case VarEnum.VT_I1
Return bVal
Case VarEnum.VT_I2
Return iVal
Case VarEnum.VT_I4
Return lVal
Case VarEnum.VT_I8
Return hVal
Case VarEnum.VT_INT
Return iVal
Case VarEnum.VT_UI4
Return ulVal
Case VarEnum.VT_LPWSTR
Return Marshal.PtrToStringUni(pwszVal)
Case VarEnum.VT_BLOB
Return GetBlob()
End Select
Throw New NotImplementedException("PropVariant " + ve.ToString())
End Get
End Property
End Structure
Friend Structure Blob
Public Length As Integer
Public Data As IntPtr
'Code Should Compile at warning level4 without any warnings,
'However this struct will give us Warning CS0649: Field [Fieldname]
'is never assigned to, and will always have its default value
'You can disable CS0649 in the project options but that will disable
'the warning for the whole project, it's a nice warning and we do want
'it in other places so we make a nice dummy function to keep the compiler
'happy.
Private Sub FixCS0649()
Length = 0
Data = IntPtr.Zero
End Sub
End Structure
#End Region
#Region "Interfaces"
<ComImport, Guid("886D8EEB-8CF2-4446-8D02-CDBA1DBDCF99"), InterfaceType(ComInterfaceType.InterfaceIsIUnknown)> _
Interface IPropertyStore
<MethodImpl(MethodImplOptions.InternalCall, MethodCodeType:=MethodCodeType.Runtime)> _
Sub GetCount(<Out> ByRef cProps As UInteger)
<MethodImpl(MethodImplOptions.InternalCall, MethodCodeType:=MethodCodeType.Runtime)> _
Sub GetAt(<[In]> iProp As UInteger, ByRef pkey As PropertyKey)
<MethodImpl(MethodImplOptions.InternalCall, MethodCodeType:=MethodCodeType.Runtime)> _
Sub GetValue(<[In]> ByRef key As PropertyKey, ByRef pv As PropVariant)
<MethodImpl(MethodImplOptions.InternalCall, MethodCodeType:=MethodCodeType.Runtime)> _
Sub SetValue(<[In]> ByRef key As PropertyKey, <[In]> ByRef pv As PropVariant)
<MethodImpl(MethodImplOptions.InternalCall, MethodCodeType:=MethodCodeType.Runtime)> _
Sub Commit()
<MethodImpl(MethodImplOptions.InternalCall, MethodCodeType:=MethodCodeType.Runtime)> _
Sub Release()
End Interface
#End Region
#Region "Methods"
<DllImport("shell32.dll", SetLastError:=True)> _
Private Shared Function SHGetPropertyStoreForWindow(handle As IntPtr, ByRef riid As Guid, ByRef propertyStore As IPropertyStore) As Integer
End Function
Public Shared Sub EnableEdgeGestures(ByVal hwnd As IntPtr, ByVal enable As Boolean)
Dim pPropStore As IPropertyStore = Nothing
Dim hr As Integer
hr = SHGetPropertyStoreForWindow(hwnd, IID_PROPERTY_STORE, pPropStore)
If hr = 0 Then
Dim propKey As New PropertyKey
propKey.fmtid = DISABLE_TOUCH_SCREEN
propKey.pid = 2
Dim var As New PropVariant
var.vt = VT_BOOL
var.boolVal = enable
pPropStore.SetValue(propKey, var)
Marshal.FinalReleaseComObject(pPropStore)
End If
End Sub
#End Region
End Class
回答by Geurti
I have the same problem. I have used a Windows system properties named : PKEY_EdgeGesture_DisableTouchWhenFullscreen(http://msdn.microsoft.com/en-us/library/windows/desktop/jj553591(v=vs.85).aspx).
我也有同样的问题。我使用了名为 PKEY_EdgeGesture_DisableTouchWhenFullscreen(http://msdn.microsoft.com/en-us/library/windows/desktop/jj553591(v=vs.85 ) .aspx)的 Windows 系统属性。
c# --> call dll via P/Invoke --> set PKEY_EdgeGesture_DisableTouchWhenFullscreen property.
c# --> 通过 P/Invoke 调用 dll --> 设置 PKEY_EdgeGesture_DisableTouchWhenFullscreen 属性。
Nota Bene : This solution doesn't work for a Modern UI app. For Modern UI app use kiosk mode : Assigned Access http://technet.microsoft.com/en-us/library/dn465334.aspx.
注意:此解决方案不适用于现代 UI 应用程序。对于现代 UI 应用程序,请使用 kiosk 模式:分配访问http://technet.microsoft.com/en-us/library/dn465334.aspx。
Snippet code DLL:
片段代码 DLL:
extern "C" __declspec(dllexport) bool SetTouchDisableProperty(HWND hWnd)
{
PROPVARIANT var;
var.vt = VT_BOOL;
var.boolVal = VARIANT_TRUE;
// Get window properties
IPropertyStore* pPropStore;
IID_PPV_ARGS(&pPropStore);
HRESULT hrReturnValue = SHGetPropertyStoreForWindow(hWnd, IID_PPV_ARGS(&pPropStore));
// set PKEY_EdgeGesture_DisableTouchWhenFullscreen property
if (SUCCEEDED(hrReturnValue))
{
hrReturnValue = pPropStore->SetValue(PKEY_EdgeGesture_DisableTouchWhenFullscreen, var);
pPropStore->Release();
}
return TRUE;
}
Snippet code c# to call dll :
代码段 c# 调用 dll :
[DllImport("libDisableTouchDll.dll", EntryPoint = "SetTouchDisableProperty"
, ExactSpelling = false, CallingConvention = CallingConvention.Cdecl)]
static extern bool SetTouchDisableProperty(IntPtr hWnd);
static void Main(string[] args)
{
// dirty get inPtr process for firefox
IntPtr intPtr = System.Diagnostics.Process.GetProcessesByName("firefox")[0].MainWindowHandle;
SetTouchDisableProperty(intPtr);
}
回答by Stig-Rune Skansg?rd
I would use Win 8.1s built-in kiosk mode to do this, as I assume you are developing a Win 8.1 app: http://www.geek.com/microsoft/windows-8-1-kiosk-mode-locks-systems-to-a-single-app-1552963/
我会使用 Win 8.1s 内置 kiosk 模式来执行此操作,因为我假设您正在开发 Win 8.1 应用程序:http: //www.geek.com/microsoft/windows-8-1-kiosk-mode-locks-系统到单个应用程序-1552963/
http://www.howtogeek.com/173562/how-to-easily-put-a-windows-pc-into-kiosk-mode-with-assigned-access/
http://www.howtogeek.com/173562/how-to-easily-put-a-windows-pc-into-kiosk-mode-with-assigned-access/

