Is this a bug in OpenNetCFG or am I wrong?

V

vbMark

Here is my code:

http://code-7sd7gs7d.notlong.com

The events are triggering fine now but the problem is that it looks as
though "Private Sub Form_KeyDown" event is getting called for every control
in the array.

I'm adding the MessageFilter like this:
ApplicationEx.AddMessageFilter(m_oTextBox(x))

What's going on?

Thanks!
 
V

vbMark

Now I have gone to the other extreem where "Private Sub Form_KeyDown"
never gets called:

To get the HWnd I do this:

Private Declare Function GetCapture Lib "CoreDll.dll" () As IntPtr

Public Sub New(ByVal DelegateFunction As MyKeyDownDelegate)
myfunc = DelegateFunction
Me.Capture = True
HWnd = GetCapture()
Me.Capture = False
End Sub

Then to compare:

Public Function PreFilterMessage(ByRef m As
Microsoft.WindowsCE.Forms.Message) As Boolean Implements
OpenNETCF.Windows.Forms.IMessageFilter.PreFilterMessage
If m.HWnd.Equals(HWnd) Then
Select Case m.Msg
Case Window.Messages.WM_KEYDOWN
myfunc.Invoke(New KeyEventArgs(m.WParam.ToInt32), _
m.LParam.ToInt32)
End Select
End If
End Function

But m.HWnd.Equals(HWnd) is NEVER true.

How do I fix?

Thanks!


Have you seen this [1] example? You must detect for which window
WM_KEYDOWN was sent:

Public Function PreFilterMessage(ByRef m As _
Microsoft.WindowsCE.Forms.Message) As Boolean _
Implements
OpenNETCF.Windows.Forms.IMessageFilter.Pre­FilterMessage
If m.HWnd = textBoxHwnd Then
...
End If
End Function


[1]
http://www.sergeybogdanov.com/Samples/TextBoxKeyDownFilter.zip

Best regards,
Sergey Bogdanov
http://www.sergeybogdanov.com
Here is my code:

http://code-7sd7gs7d.notlong.com

The events are triggering fine now but the problem is that it looks
as though "Private Sub Form_KeyDown" event is getting called for
every control in the array.

I'm adding the MessageFilter like this:
ApplicationEx.AddMessageFilter(m_oTextBox(x))

What's going on?

Thanks!
 
S

Sergey Bogdanov

A constructor is a not correct place to get HWND of native control (it
can be not initialized). Try to move GetCapture into OnParenChanged event.

Best regards,
Sergey Bogdanov
http://www.sergeybogdanov.com
Now I have gone to the other extreem where "Private Sub Form_KeyDown"
never gets called:

To get the HWnd I do this:

Private Declare Function GetCapture Lib "CoreDll.dll" () As IntPtr

Public Sub New(ByVal DelegateFunction As MyKeyDownDelegate)
myfunc = DelegateFunction
Me.Capture = True
HWnd = GetCapture()
Me.Capture = False
End Sub

Then to compare:

Public Function PreFilterMessage(ByRef m As
Microsoft.WindowsCE.Forms.Message) As Boolean Implements
OpenNETCF.Windows.Forms.IMessageFilter.PreFilterMessage
If m.HWnd.Equals(HWnd) Then
Select Case m.Msg
Case Window.Messages.WM_KEYDOWN
myfunc.Invoke(New KeyEventArgs(m.WParam.ToInt32), _
m.LParam.ToInt32)
End Select
End If
End Function

But m.HWnd.Equals(HWnd) is NEVER true.

How do I fix?

Thanks!



Have you seen this [1] example? You must detect for which window
WM_KEYDOWN was sent:

Public Function PreFilterMessage(ByRef m As _
Microsoft.WindowsCE.Forms.Message) As Boolean _
Implements
OpenNETCF.Windows.Forms.IMessageFilter.Pre­FilterMessage
If m.HWnd = textBoxHwnd Then
...
End If
End Function


[1]
http://www.sergeybogdanov.com/Samples/TextBoxKeyDownFilter.zip

Best regards,
Sergey Bogdanov
http://www.sergeybogdanov.com
Here is my code:

http://code-7sd7gs7d.notlong.com

The events are triggering fine now but the problem is that it looks
as though "Private Sub Form_KeyDown" event is getting called for
every control in the array.

I'm adding the MessageFilter like this:
ApplicationEx.AddMessageFilter(m_oTextBox(x))

What's going on?

Thanks!
 
C

Chris Tacke, eMVP

You can't call GetCapture in the ctor - the control hasn't yet been created
and therefore doesn't have focus. You are getting a HWND for something
else;

--
Chris Tacke
Co-founder
OpenNETCF.org
Has OpenNETCF helped you? Consider donating to support us!
http://www.opennetcf.org/donate


vbMark said:
Now I have gone to the other extreem where "Private Sub Form_KeyDown"
never gets called:

To get the HWnd I do this:

Private Declare Function GetCapture Lib "CoreDll.dll" () As IntPtr

Public Sub New(ByVal DelegateFunction As MyKeyDownDelegate)
myfunc = DelegateFunction
Me.Capture = True
HWnd = GetCapture()
Me.Capture = False
End Sub

Then to compare:

Public Function PreFilterMessage(ByRef m As
Microsoft.WindowsCE.Forms.Message) As Boolean Implements
OpenNETCF.Windows.Forms.IMessageFilter.PreFilterMessage
If m.HWnd.Equals(HWnd) Then
Select Case m.Msg
Case Window.Messages.WM_KEYDOWN
myfunc.Invoke(New KeyEventArgs(m.WParam.ToInt32), _
m.LParam.ToInt32)
End Select
End If
End Function

But m.HWnd.Equals(HWnd) is NEVER true.

How do I fix?

Thanks!


Have you seen this [1] example? You must detect for which window
WM_KEYDOWN was sent:

Public Function PreFilterMessage(ByRef m As _
Microsoft.WindowsCE.Forms.Message) As Boolean _
Implements
OpenNETCF.Windows.Forms.IMessageFilter.Pre­FilterMessage
If m.HWnd = textBoxHwnd Then
...
End If
End Function


[1]
http://www.sergeybogdanov.com/Samples/TextBoxKeyDownFilter.zip

Best regards,
Sergey Bogdanov
http://www.sergeybogdanov.com
Here is my code:

http://code-7sd7gs7d.notlong.com

The events are triggering fine now but the problem is that it looks
as though "Private Sub Form_KeyDown" event is getting called for
every control in the array.

I'm adding the MessageFilter like this:
ApplicationEx.AddMessageFilter(m_oTextBox(x))

What's going on?

Thanks!
 
V

vbMark

Yeah, I'm wondering if I'm getting the HWND for something else.

I'd moved it to here:

Private Sub clsComboBox_ParentChanged(ByVal sender As Object, _
ByVal e As System.EventArgs) Handles MyBase.ParentChanged
Me.Capture = True
hwnd = GetCapture()
Me.Capture = False
End Sub

But still m.HWnd.Equals(hwnd) is always false.

Any ideas?
 
A

Alex Feinman [MVP]

Try doing it in the Focus event. The window is guaranteed to exist then
 
V

vbMark

That was a good idea but still the same thing: m.HWnd.Equals(pHWnd) is
always false.

I also tried moving the GetCapture out of the class and into the main
form like this:

Me.Controls.Add(m_oTextBox(x))
With m_oTextBox(x)
.Capture = True
.HWnd = GetCapture()
.Capture = False
End With

And in the class I have this:

Public Property HWnd() As IntPtr
Set(ByVal Value As IntPtr)
pHWnd = Value
End Set
Get
Return pHWnd
End Get
End Property

I step through it and each control is getting assigned its own HWnd
value.

Here is a thought I have. The help file says that the GetCapture Method
"Retrieves the handle to the window, if any, that has captured the mouse
or stylus input."

Since the Smartphone does not have a mouse or stylus could this be the
problem?

Thanks!
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top