Default Button - Enter Key

Started by Haakon Birkeland, September 25, 2005, 02:52:52 AM

Previous topic - Next topic

Haakon Birkeland

I have a button that has focus. How do I make it respond to the return key so it acts as if I clicked on it with the mouse?
I use this code to make it work but shoult it not respond to the enter key natively

Function JOBFORM_SAVEBTN_CUSTOM ( _
                               ControlIndex  As Long,  _  ' index in Control Array
                               hWndForm      As Dword, _  ' handle of Form
                               hWndControl   As Dword, _  ' handle of Control
                               wMsg          As Long,  _  ' type of message
                               wParam        As Dword, _  ' first message parameter
                               lParam        As Long   _  ' second message parameter
                               ) As Long
If wMsg = 135 And wParam = %VK_RETURN Then
JOBFORM_SAVEBTN_BN_CLICKED 0,HWND_JOBFORM,HWND_JOBFORM_SAVEBTN,IDC_JOBFORM_SAVEBTN
End If


Bert
Haakon 8o)

TechSupport

In Windows, the ENTER key can be a big problem because it is possible to have situations where the ENTER key does something different depending on the situation. For example, if you are in a multiline textbox the ENTER key can insert a new line; If a "default" button exists on your Form the the ENTER key will fire a BTN_CLICKED notification for that button even though the focus may be currently on a different button. It can get confusing sometimes.

The accepted way in Windows to "click" a button using the keyboard is by pressing the SPACEBAR key. This is something that can be quite confusing for DOS users migrating to a Windows application.

BTW, I don't see anything wrong with your approach of catching the ENTER key for your button. You could have used the equate instead of the actual decimal value for the message:

If wMsg = 135

If wMsg = %WM_GETDLGCODE