Capturing the "home" button on Smartphones using VB.Net

  • Thread starter Thread starter Tim Ricker
  • Start date Start date
T

Tim Ricker

Hi,

I have been searching high and low to find a solution for capturing the
"home" hardware button on Smartphones using VB.Net.

I have managed to find some code snippets using C# utilising the
RegisterHotKey and core.dll, however havent been able to get them to
work, and more so not been able to find a solution in VB.Net.

Here's the C# solution I found:
http://blog.opennetcf.org/ayakhnin/PermaLink.aspx?guid=6F3656EC-B669-4A2
3-987A-A2455FBD2FC4

Effectively what I'm trying to do is disable this button, stopping the
user from returning the user to the phones "home" menu, when it is
pushed on the handset.

All help would be greatly appreciated!

Thanks,
-- Tim.
 
I tried the conversion - and I seem to get an issue with trying to call
the HomeKeyPress event of the msgWin instance of the MessageWin class I
create.

The reason I wish to disable the Home button is because I am trying to
create an application that takes complete control of the device for
employees of our company using the phones are demonstration units within
our company. I cant have them exiting the app and playing around with
the phone.

Here's the class code converted to VB.Net:

Imports System
Imports Microsoft.WindowsCE.Forms
Imports System.Windows.Forms
Imports System.Runtime.InteropServices

Public Class MessageWin
Inherits MessageWindow

'event for client
Public Shared HomeKeyPress As System.EventHandler

Private VK_LWIN As Integer = &H5B
Private WM_HOTKEY As Integer = &H312

Public Sub New()

RegisterHotKey(Me.Hwnd, VK_LWIN, 8, VK_LWIN)

End Sub 'New

'Overloads Overrides Sub Finalize()
' 'Unregister()
' MyBase.Finalize()
'End Sub 'Finalize

Protected Overrides Sub WndProc(ByRef m As Message)

If m.Msg = WM_HOTKEY Then

If m.WParam.Equals(VK_LWIN) Then

'Raise event
If Not (HomeKeyPress Is Nothing) Then
HomeKeyPress(Me, Nothing)
End If

End If

End If

MyBase.WndProc(m)

End Sub 'WndProc

<DllImport("coredll.dll")> Public Shared _
Function RegisterHotKey(ByVal hWnd As IntPtr, ByVal id As Integer,
ByVal Modifiers As Integer, ByVal key As Integer) As Boolean
End Function 'RegisterHotKey


End Class


The following code I have on my main form of the application which I
call from the New() sub. This is where I am having problems. VB.Net is
saying that HomeKeyPress is not an event of msgWin.

'-----------------------------------------

Dim msgWin As MessageWin = New MessageWin
AddHandler msgWin.HomeKeyPress, AddressOf msgWin_HomeKeyPress

'-----------------------------------------


Then obviously I have the callback function also on the main form:

'-----------------------------------------

Private Sub msgWin_HomeKeyPress(ByVal sender As Object, ByVal e As
System.EventArgs)

MessageBox.Show("Home Key Pressed.")

End Sub


Your help & comments would be fantastic.

Thanks!

-- Tim.
 
Back
Top