PreProcessMessage

  • Thread starter Thread starter Geoff Jones
  • Start date Start date
G

Geoff Jones

Hiya

Can anybody help me with the following?

I'm overriding PreProcessMessage on a DataGrid in order to capture keys.
However, the function is only called sometimes i.e. there doesn't seem to be
any pattern.

Can anybody help?

Geoff
 
oups there is something missing..

if you want to get notify for regular keys (A, b, 9, etc..) you can handle
WM_KEYDOWN too
'***
Public Class DataGridEx
Inherits DataGrid

Private Const WM_KEYDOWN As Int32 = &H100
Private Const WM_SYSKEYDOWN As Int32 = &H104
Private Const VK_DOWN As Int32 = &H28

Protected Overrides Function ProcessCmdKey(ByRef msg As
System.Windows.Forms.Message, ByVal keyData As System.Windows.Forms.Keys) As
Boolean

If (msg.Msg = WM_SYSKEYDOWN) Then
Console.WriteLine("WM_SYSKEYDOWN")
If (msg.WParam.ToInt32() = VK_DOWN) Then
Console.WriteLine("VK_DOWN")
If (Control.ModifierKeys = Keys.Alt) Then
Console.WriteLine("bingo!")
Return True
End If
End If
ElseIf (msg.Msg = WM_KEYDOWN) Then
Console.WriteLine("VK: {0}, Char: {1}", msg.WParam.ToInt32(),
CType(msg.WParam.ToInt32(), Keys).ToString())
End If

Return MyBase.ProcessCmdKey(msg, keyData)
End Function

End Class
'***

I'm not a hundred percent sure that a Virtual Key code (WParam) could be
convert into a Keys type though...
 
Thanks Zoury

Zoury said:
oups there is something missing..

if you want to get notify for regular keys (A, b, 9, etc..) you can handle
WM_KEYDOWN too
'***
Public Class DataGridEx
Inherits DataGrid

Private Const WM_KEYDOWN As Int32 = &H100
Private Const WM_SYSKEYDOWN As Int32 = &H104
Private Const VK_DOWN As Int32 = &H28

Protected Overrides Function ProcessCmdKey(ByRef msg As
System.Windows.Forms.Message, ByVal keyData As System.Windows.Forms.Keys)
As
Boolean

If (msg.Msg = WM_SYSKEYDOWN) Then
Console.WriteLine("WM_SYSKEYDOWN")
If (msg.WParam.ToInt32() = VK_DOWN) Then
Console.WriteLine("VK_DOWN")
If (Control.ModifierKeys = Keys.Alt) Then
Console.WriteLine("bingo!")
Return True
End If
End If
ElseIf (msg.Msg = WM_KEYDOWN) Then
Console.WriteLine("VK: {0}, Char: {1}", msg.WParam.ToInt32(),
CType(msg.WParam.ToInt32(), Keys).ToString())
End If

Return MyBase.ProcessCmdKey(msg, keyData)
End Function

End Class
'***

I'm not a hundred percent sure that a Virtual Key code (WParam) could be
convert into a Keys type though...
 

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

Back
Top