V
vbmark
Hello,
I'm really stuck on this problem. I can't get it to work and really need
it to. I've seen the C# example for this code and translated it to
vb.net. I'm using the Smartphone emulator.
I have a bunch of text boxes and combo boxes that get rearranged during
the program running. The problem is that when the user hits the up or
down arrow the focus does not go to the control above or below since the
order of the controls have changed. So I want to control this by
capturing the up and down arrow key presses.
I have all the code in place and everything seems to be working except
for this one thing. On this line: "If m.HWnd.Equals(pHWnd) Then" the
HWNd of the message is NEVER equal to the HWnd of the control!
Here is the relevant code of the TextBox:
Public Class clsTextBox
Inherits TextBox
Implements OpenNETCF.Windows.Forms.IMessageFilter
Private pHWnd As IntPtr
Delegate Sub MyKeyDownDelegate(ByVal e As KeyEventArgs, _
ByVal lparam As Integer)
Private myfunc As MyKeyDownDelegate
Public Sub New(ByVal DelegateFunction As MyKeyDownDelegate)
myfunc = DelegateFunction
End Sub
Public Function PreFilterMessage(ByRef m As _
Microsoft.WindowsCE.Forms.Message) _
As Boolean Implements _
OpenNETCF.Windows.Forms.IMessageFilter.PreFilterMessage
Try
If m.HWnd.Equals(pHWnd) Then
Select Case m.Msg
Case Window.Messages.WM_KEYDOWN
myfunc.Invoke(New KeyEventArgs(m.WParam.ToInt32), _
m.LParam.ToInt32)
End Select
End If
Catch ex As Exception
'MsgBox(ex.ToString)
End Try
End Function
Public Property HWnd() As IntPtr
Set(ByVal Value As IntPtr)
pHWnd = Value
End Set
Get
Return pHWnd
End Get
End Property
End Class
Here is the relevant code in my main form:
Imports OpenNETCF
Imports OpenNETCF.Windows.Forms
Imports System.Runtime.InteropServices
' Interop declarations
<DllImport("coredll.dll")> _
Private Shared Function GetCapture() As IntPtr
End Function
' This is to allow the interception of the KeyDown events.
Public Shared Sub Main()
ApplicationEx.Run(New frmMain)
End Sub
Private Sub CreateControls()
I'm really stuck on this problem. I can't get it to work and really need
it to. I've seen the C# example for this code and translated it to
vb.net. I'm using the Smartphone emulator.
I have a bunch of text boxes and combo boxes that get rearranged during
the program running. The problem is that when the user hits the up or
down arrow the focus does not go to the control above or below since the
order of the controls have changed. So I want to control this by
capturing the up and down arrow key presses.
I have all the code in place and everything seems to be working except
for this one thing. On this line: "If m.HWnd.Equals(pHWnd) Then" the
HWNd of the message is NEVER equal to the HWnd of the control!
Here is the relevant code of the TextBox:
Public Class clsTextBox
Inherits TextBox
Implements OpenNETCF.Windows.Forms.IMessageFilter
Private pHWnd As IntPtr
Delegate Sub MyKeyDownDelegate(ByVal e As KeyEventArgs, _
ByVal lparam As Integer)
Private myfunc As MyKeyDownDelegate
Public Sub New(ByVal DelegateFunction As MyKeyDownDelegate)
myfunc = DelegateFunction
End Sub
Public Function PreFilterMessage(ByRef m As _
Microsoft.WindowsCE.Forms.Message) _
As Boolean Implements _
OpenNETCF.Windows.Forms.IMessageFilter.PreFilterMessage
Try
If m.HWnd.Equals(pHWnd) Then
Select Case m.Msg
Case Window.Messages.WM_KEYDOWN
myfunc.Invoke(New KeyEventArgs(m.WParam.ToInt32), _
m.LParam.ToInt32)
End Select
End If
Catch ex As Exception
'MsgBox(ex.ToString)
End Try
End Function
Public Property HWnd() As IntPtr
Set(ByVal Value As IntPtr)
pHWnd = Value
End Set
Get
Return pHWnd
End Get
End Property
End Class
Here is the relevant code in my main form:
Imports OpenNETCF
Imports OpenNETCF.Windows.Forms
Imports System.Runtime.InteropServices
' Interop declarations
<DllImport("coredll.dll")> _
Private Shared Function GetCapture() As IntPtr
End Function
' This is to allow the interception of the KeyDown events.
Public Shared Sub Main()
ApplicationEx.Run(New frmMain)
End Sub
Private Sub CreateControls()