disabling button with iMessageFilter

M

mauro

hi ,
i am tryng to disable buttons in the meanwhile a long
operation is running ,
i found many posts on that , and
i am tryng to use OpennetCF ApplicationEx (Application2)
with IMessagefilter .

i found an example for disabling TextBoxes to receives inputs ,
and i am tryng to make the same behave to a button , result is that the
first click is correctly disabled , but when i click again , the button
is enabled again ....if someone could help me to correct my
code in the way that i can decide when start again enebling the button ,
it would be great .



the code :

i run the form2 with Application2.Run(New Form2)

Public Class Form2
Inherits System.Windows.Forms.Form
Friend WithEvents MainMenu2 As System.Windows.Forms.MainMenu
Private custButton As clsButton

Private Sub Form2_Load(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles MyBase.Load
CreateControls()
End Sub

Private Sub cusButton_Click(ByVal sender As System.Object, ByVal e
As System.EventArgs) Handles Button1.Click
MessageBox.Show(" a ")
End Sub

Private Sub CreateControls()

custButton = New clsButton(AddressOf Form_KeyDown)
custButton.Location = New Point(66, 229)
custButton.Size = New Size(72, 20)

Me.Controls.Add(custButton)
AddHandler custButton.Click, AddressOf cusButton_Click
AddHandler custButton.GotFocus, AddressOf Button_OnClick

Application2.AddMessageFilter(custButton)

End Sub

Private Sub Button_OnClick(ByVal sender As Object, ByVal e As
System.EventArgs)
Dim thisButton As clsButton = DirectCast(sender, clsButton)
With thisButton
.Capture = True
.HWnd = GetCapture()
.Capture = False
End With

End Sub


Sub Form_KeyDown(ByVal e As KeyEventArgs, _
ByVal lparam As Integer)
MessageBox.Show("KeyDown: " + e.KeyData.ToString())
End Sub

<DllImport("coredll.dll")> _
Private Shared Function GetCapture() As IntPtr
End Function



End Class


Public Class clsButton
Inherits Button
Implements OpenNETCF.Windows.Forms.IMessageFilter
Private pHWnd As IntPtr
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 &H100
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

thank you
mauro
 
G

Guest

I don't see PreFilterMessage returning any values. Why is that? I'm
surprised it even compiles.
 
M

mauro

I don't see PreFilterMessage returning any values. Why is that? I'm
surprised it even compiles.

i have taken that from an example for disabling a textbox input :
in that example when i try to edit a textbox , i have e message
(MessageBox.Show("KeyDown: " + e.KeyData.ToString()) , and text of the
control doesn't change .

it is my first CF program , and of course it is not correct the way i
adapted it to a button , but when i try it, as i wrote , the button
is not enabled for the first click ....

i would be great to have any suggestion or documentation for that .

thank you

mauro
 
G

Guest

The return from IMessageFilter is *extremely* important. It is what
determines if the button will or will not get the message dispatched to it.
Anything else is really non-relevent.
 

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