Ok, this may sound really dumb in this forum full of very smart people, but here and there i occasionally have the need for a function we used to have in VB6 called Keypreview.
Now given the fact that one can place a Menu on a form and get it to react to any of its keystrokes anywhere in the form, why cant one make a simple invisible control which has a huge choice of possible keystrokes you can select of to react on and place it on any form?
(It would be nice is it can handle different possible keystrokes and creates a separate event function for each one.)
That will make writing much faster, the event will always be available and correct and us dummies need not go and fiddle in places where we can break things :)
Any ideas how one can make and implement such a little control?
FF_PUMPHOOK is the best place for you to implement what you need. You can intercept any message destined for any control or form. You can filter out anything that you need to process and simply call your own function. You can even modify the incoming messages parameters if you need to. You can then elect to let the message continue on in the pump or return -1 and then no more processing is done. Simple. Easy.
A dedicated control to do this is simply overkill and redundant. I intercept messages in the PumpHook all the time without any trouble whatsoever.
Paul, could you provide a small example for that?
Rolf
This is a small part of FireFly's own FF_PUMPHOOK that deals with incoming messages. In the example below I show how I trap the CTRL+F7 and CTRL+F8 keystrokes to toggle closing the Functions Library, Reference Charts and Project Notes:
Select Case Msg.message
Case %WM_KEYDOWN, %WM_KEYUP
' If the window is already open then close it.
If IsWindowVisible(HWND_FRMCODESTORE) Then
If (Msg.message = %WM_KEYDOWN) And (msg.wParam = %VK_F8) Then
SendMessage HWND_FRMCODESTORE, %WM_CLOSE, 0, 0
Function = %TRUE
Exit Function
End If
End If
If IsWindowVisible(HWND_FRMREFCHARTS) Then
If (Msg.message = %WM_KEYDOWN) And (msg.wParam = %VK_F8) Then
If GetAsyncKeyState(%VK_SHIFT) And &H8000 <> 0 Then
SendMessage HWND_FRMREFCHARTS, %WM_CLOSE, 0, 0
Function = %TRUE
Exit Function
End If
End If
End If
If IsWindowVisible(HWND_FRMNOTESMAIN) Then
If (Msg.message = %WM_KEYDOWN) And (msg.wParam = %VK_F7) Then
If GetAsyncKeyState(%VK_CONTROL) And &H8000 <> 0 Then
SendMessage HWND_FRMNOTESMAIN, %WM_CLOSE, 0, 0
Function = %TRUE
Exit Function
End If
End If
End If
End Select
Thanks very much, Paul.
I am going to toy around a litte with this. Looks like it can be quite helpful in many situations.
Rolf
Thanks Paul
I did look at the pumphook and i understand the overkill a control will create.
Perhaps that's why some other languages performs worse, it because they drag all this redundant stuff around?
Just thought it would be pretty neat to catch any key and divert to any call by just dragging on the form a small control.
Was just afraid if i start messing in the pumphook I will mess up the rest of the messaging going around between controls.