Hello people
I don't get a keyboard enter event, this is programmed on purpose?
Function frmMain_Button1_AllEvents( ByRef sender As wfxButton, ByRef e As EventArgs ) As LRESULT
Select Case e.Message
case WM_LBUTTONUP
' frmMain.Close
end select
print e.Message 'pressing enter with the keyboard does not raise any event ' No BN_CLICKED Event
Function = 0
End Function
maybe i should use frmMain_Button1_Click as usual?, and catch the event there
But the button has the keyboard focus or not?
yes, I see that the button is pressed with enter, but no event is raised
There are several ways to accomplish what you are trying to do. You should also be aware that BN_CLICKED is a notification message that is sent to the parent Form window - NOT the control itself. So trying to catch BN_CLICKED in the Button won't work.
I created a Form and added some buttons. My code below works on a button called Button2
''
''
Function frmMain_Button2_AllEvents( ByRef sender As wfxButton, ByRef e As EventArgs ) As LRESULT
Select Case e.Message
case WM_LBUTTONUP
? "WM_LBUTTONUP - AllEvents"
' frmMain.Close
end select
print e.Message 'pressing enter with the keyboard does not raise any event ' No BN_CLICKED Event
' YOU WILL NEVER GET BN_CLICKED HERE because you need to handle AllEvents for the FORM rather than the BUTTON.
Function = 0
End Function
''
''
Function frmMain_Button2_MouseUp( ByRef sender As wfxButton, ByRef e As EventArgs ) As LRESULT
if e.LButton then
? "WM_LBUTTONUP - MouseUp handler"
end if
Function = 0
End Function
''
''
Function frmMain_AllEvents( ByRef sender As wfxForm, ByRef e As EventArgs ) As LRESULT
select case e.Message
case WM_COMMAND
if hiword(e.wParam) = BN_CLICKED then
if e.lParam = frmMain.Button2.hWindow then
AfxMsg( "Button #2 clicked: BN_CLICKED from AllEvents" )
end if
end if
end select
Function = 0
End Function
The general idea behind WinFBE's visual designer is to shield you from having to deal (at least most of the time) directly with the raw Windows messages. That's why the various message event handlers exist. From the above code you can see that you can trap the WM_LBUTTONUP in the Button's AllEvents handler or the dedicated MouseUp event. You can also catch the BN_CLICKED from the Form AllEvents handler.
Or, you could simply deal with the Button's Click event handler which is the best place because you can deal with both the operations of the user clicking on the button or pressing the Enter or Space key to click on the button.
You can also look at other options like the "AcceptButton" property for the Form.
Another approach is to use the "KeyPreview" for the Form and deal with the Key* events for the Form.
You could even use the "MessagePumpHook" message handler for the Form itself to catch every message as it arrives to the form and before it even gets dispatched to the intended control.
That makes a lot clear,
the selectable AllEvents in the toolbox returns all events except the events that you can also select in the toolbox.
MessagePumpHook, great no more complex subclassing
thanks for the explanation and examples