我有一个Surface,我需要“锁定”作为一种Kiosk模式。我知道正在更新"Kiosk模式“。不过,我需要在那之前做这件事。
我已经搜索了所有的互联网,但似乎你不能从屏幕上的一个滑动条中禁用魅力条。我找到了禁用履带的方法。但不幸的是,由于这款平板电脑将不带键盘,我需要禁用魅力条。
我的新想法是移动整个魅力栏HWND数千像素离开屏幕,或者,可能设置一个窗口样式,使它不会出现。我尝试使用Spy++和一个基于EnumWindows的自定义控制台应用程序来给我一些窗口句柄。然而,我不能保持魅力酒吧足够长的时间,使这些发挥作用。
因此,我的问题是:如何在Windows 8中找到用于魅力栏的窗口句柄(HWND)?或者,如何以其他方式获得对魅力栏的引用,从而向其抛出一个SetWindowLong或SetWindowPos?
发布于 2013-07-06 06:25:25
事实上,我找到了一种方法来做到这一点(显然,没有其他人这样做:/)。
对于那些好奇的人来说,像"Start8“和"SkipMetroSuite”这样的软件按下投票键就可以阻止魅力栏的出现。他们真的模拟按键在一个紧密的循环内关闭它。
我发现(我认为是)一个更好的方法。
首先是..。一些WinAPI函数:
using System.Runtime.InteropServices;
....
private enum WindowShowStyle : uint
{ // find more info at http://stackoverflow.com/a/8210120/1245420
Hide = 0, ShowNormal = 1, ShowMinimized = 2, ShowMaximized = 3,
ShowNormalNoActvate = 4, Show = 5, Minimize = 6, ShowNoActivate = 8,
Restore = 9, ShowDefault = 10, ForceMinimized = 11
}
[DllImport("user32.dll", SetLastError = true)]
static extern System.IntPtr FindWindow(string lpClassName, string lpWindowName);
[DllImport("user32.dll", EntryPoint = "FindWindow", SetLastError = true)]
static extern System.IntPtr FindWindowByCaption(System.IntPtr ZeroOnly, string lpWindowName);
[DllImport("user32.dll")]
static extern bool ShowWindow(System.IntPtr hWnd, WindowShowStyle nCmdShow);所以问题首先是魅力酒吧。这个窗口的标题原来是,Charm Bar。产生一个线程,不断寻找这个窗口,并隐藏它美丽的工作。因此,我生成了一个线程,并不断地轮询它:
System.Threading.Tasks.Task.Factory.StartNew(() => {
while (true) {
System.IntPtr hWndCharmBar = FindWindowByCaption(System.IntPtr.Zero, "Charm Bar");
ShowWindow(hWndCharmBar, 0);
System.Threading.Thread.Sleep(100); // sleep for a bit
}
});这是很好的工作,并提供了额外的好处,使魅力栏继续工作时,应用程序关闭。Thread.Sleep是用来阻止线程破坏CPU的--但是延迟也允许魅力栏出现一秒。我还没有成功地打开魅力栏,并在线程再次隐藏它之前按下一个足够快的按钮,所以这很好。很明显,降低睡眠时间会让这更快。
Windows 8的另一个问题是,如果您有某种滑块(在我的应用程序中,我有一个包含图库图像的ListBox ),那么您实际上可以滑到屏幕的一侧……把你的手指放在那儿,进入任务栏.
所以..。下一部分是关闭任务栏:
IntPtr hWndTray = FindWindow("Shell_TrayWnd", null);
ShowWindow(hWndTray, 0);..then,我在app close上再次展示了它:
IntPtr hWndTray = FindWindow("Shell_TrayWnd", null);
ShowWindow(hWndTray, 1);在功能上,这是我的应用程序所需要的全部。希望这能帮到别人。
发布于 2013-08-26 15:09:42
我还要指出,该钟载于一个以“时钟和日期”为标题的窗口中。
IntPtr hWndCharmClock = FindWindowByCaption(IntPtr.Zero, "Clock and Date");我做了一个小应用来切换魅力条:https://bitbucket.org/darkwingduck/charmsbartoggle/overview
发布于 2014-11-05 12:26:53
这是如何禁用魅力栏时,应用程序是最大化使用SHGetPropertyStoreForWindow互操作。应该很容易转换为C#:
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 Classhttps://stackoverflow.com/questions/17470664
复制相似问题