Crazy D
February 3rd, 2000, 07:18 AM
Hi,
I created a kind of toolbar control; it has commandbuttons on it, and the user can both click or use the function keys.
I set up a keyboard hook so you don't have to use the forms keydown event to check for the funtionkeys. I save a pointer to the usercontrol as property of the window and I use GetActiveWindow to get the hwnd to read out the property; copymemory to copy the pointer to a variable of the type usercontrol and I call a function. That function raises an event. This works nice. Oh, I setup the hook in the show event of the control and remove it in the hide event.
But the problem is, when I show a 2nd form as vbModal and both forms do have the control placed on it, the form that is shown modal gets the event twice. I'm sure this is because of the CallNextHook function. It works perfectly if I return 1 in my keyboardproc, but I'm wondering what can happen if I do that. I haven't setup much keyboard hooks (actually none,, wanted to do it using subclassing, but that didn't work...) and I'm not sure if I can safely return 1. This is what msdn says:
"If nCode is greater than or equal to zero, and the hook procedure did not process the message, it is highly recommended that you call CallNextHookEx and return the value it returns; otherwise, other applications that have installed WH_KEYBOARD hooks will not receive hook notifications and may behave incorrectly as a result. If the hook procedure processed the message, it may return a nonzero value to prevent the system from passing the message to the rest of the hook chain or the target window procedure"
Any thoughts on this?
Crazy D :-)
"One ring rules them all"
I created a kind of toolbar control; it has commandbuttons on it, and the user can both click or use the function keys.
I set up a keyboard hook so you don't have to use the forms keydown event to check for the funtionkeys. I save a pointer to the usercontrol as property of the window and I use GetActiveWindow to get the hwnd to read out the property; copymemory to copy the pointer to a variable of the type usercontrol and I call a function. That function raises an event. This works nice. Oh, I setup the hook in the show event of the control and remove it in the hide event.
But the problem is, when I show a 2nd form as vbModal and both forms do have the control placed on it, the form that is shown modal gets the event twice. I'm sure this is because of the CallNextHook function. It works perfectly if I return 1 in my keyboardproc, but I'm wondering what can happen if I do that. I haven't setup much keyboard hooks (actually none,, wanted to do it using subclassing, but that didn't work...) and I'm not sure if I can safely return 1. This is what msdn says:
"If nCode is greater than or equal to zero, and the hook procedure did not process the message, it is highly recommended that you call CallNextHookEx and return the value it returns; otherwise, other applications that have installed WH_KEYBOARD hooks will not receive hook notifications and may behave incorrectly as a result. If the hook procedure processed the message, it may return a nonzero value to prevent the system from passing the message to the rest of the hook chain or the target window procedure"
Any thoughts on this?
Crazy D :-)
"One ring rules them all"