I'm having problems when a program that should receive notifications about Input Pane (the on-screen keyboard showed by TabTip.exe on Windows) runs under elevated privileges. In this situation, no notifications are received.
My code implements IFrameworkInputPane and calls AdviseWithHWND to get notified when the Input Pane is showing or hiding. I tried to run TabTip.exe under elevated privileges too, but even in this case, my program receives no notification about the status of the Input Pane. Here is my sample code. When running under elevated privileges (which is necessary in my real case), methods Hiding and Showing are never called:
' Code for test. Just Add a button and a Textbox to the Form
Imports System.ComponentModel
Imports System.Runtime.InteropServices
Public Class Form1
' Variables ----------------------------------------------------------
Private moPaneHandler As FrameworkInputPaneHandler
Private moFrameworkInputPane As IFrameworkInputPane
Private miCookie As Integer
' Definitions --------------------------------------------------------
Public Enum HRESULT As Integer
S_OK = 0
S_FALSE = 1
E_NOINTERFACE = &H80004002
E_NOTIMPL = &H80004001
E_FAIL = &H80004005
E_UNEXPECTED = &H8000FFFF
E_OUTOFMEMORY = &H8007000E
End Enum
Public Structure RECT
Public Left As Integer
Public Top As Integer
Public Right As Integer
Public Bottom As Integer
Public Sub New(
ByVal Left As Integer,
ByVal Top As Integer,
ByVal Right As Integer,
ByVal Bottom As Integer)
Me.Left = Left
Me.Top = Top
Me.Right = Right
Me.Bottom = Bottom
End Sub
End Structure
<ComImport(), Guid("D5120AA3-46BA-44C5-822D-CA8092C1FC72")
Public Class FrameworkInputPane
End Class
<ComImport()>
<Guid("226C537B-1E76-4D9E-A760-33DB29922F18")>
<InterfaceType(ComInterfaceType.InterfaceIsIUnknown)>
Public Interface IFrameworkInputPaneHandler
Function Showing(ByRef prcInputPaneScreenLocation As RECT,
ByVal fEnsureFocusedElementInView As Boolean) As HRESULT
Function Hiding(ByVal fEnsureFocusedElementInView As Boolean) As HRESULT
End Interface
<ComImport()>
<Guid("5752238B-24F0-495A-82F1-2FD593056796")>
<InterfaceType(ComInterfaceType.InterfaceIsIUnknown)>
Public Interface IFrameworkInputPane
Function Advise(ByVal pWindow As IntPtr,
ByVal pHandler As Object,
ByRef pdwCookie As Integer) As HRESULT
Function AdviseWithHWND(ByVal hwnd As IntPtr,
ByVal pHandler As IFrameworkInputPaneHandler,
ByRef pdwCookie As Integer) As HRESULT
Function Unadvise(ByVal dwCookie As Integer) As HRESULT
Function Location(ByRef prcInputPaneScreenLocation As RECT) As HRESULT
End Interface
Public Class FrameworkInputPaneHandler
Implements IFrameworkInputPaneHandler
Public Function Hiding(ByVal fEnsureFocusedElementInView As Boolean) As HRESULT Implements IFrameworkInputPaneHandler.Hiding
With Form1.Textbox1
.Text = .Text & Now & " - "
.Text = .Text & "Hiding" & vbCrLf
End With
Return HRESULT.S_OK
End Function
Public Function Showing(ByRef prcInputPaneScreenLocation As RECT, ByVal fEnsureFocusedElementInView As Boolean) As HRESULT Implements IFrameworkInputPaneHandler.Showing
With Form1.Textbox1
.Text = .Text & Now & " - "
.Text = .Text & " Showing "
.Text = .Text & " Top: " & prcInputPaneScreenLocation.Top
.Text = .Text & " Left: " & prcInputPaneScreenLocation.Left
.Text = .Text & " Height: " & prcInputPaneScreenLocation.Bottom - prcInputPaneScreenLocation.Top
.Text = .Text & " Width: " & prcInputPaneScreenLocation.Right - prcInputPaneScreenLocation.Left & vbCrLf
End With
Return HRESULT.S_OK
End Function
End Class
Private Sub Button1_Click(ByVal sender As Object, ByVal e As EventArgs) Handles Button1.Click
Dim slRetCode As HRESULT = HRESULT.E_FAIL
Dim stRect As RECT = New RECT()
miCookie = 0
moPaneHandler = New FrameworkInputPaneHandler()
moFrameworkInputPane = New FrameworkInputPane
If (moFrameworkInputPane IsNot Nothing) Then
slRetCode = moFrameworkInputPane.AdviseWithHWND(Me.Handle, moPaneHandler, miCookie)
If slRetCode = HRESULT.S_OK Then
Textbox1.Text = Textbox1.Text & "Advise OK! Cookie " & miCookie & vbCrLf
Else
Textbox1.Text = Textbox1.Text & "Advise Error " & slRetCode
End If
End If
End Sub
Private Sub Form1_Load(sender As Object, e As EventArgs) Handles Me.Load
Button1.Text = "Advise Input Pane"
End Sub
Private Sub Form1_Closing(sender As Object, e As CancelEventArgs) Handles Me.Closing
If miCookie <> 0 Then
Call moFrameworkInputPane.Unadvise(miCookie)
End If
moPaneHandler = Nothing
End Sub
End Class
Everything works fine if the program runs "de-elevated". Does anybody has an idea on how to make this work?
Thank you.