class pb_one_press(parentObj) of pushbutton(parentObj) custom /* Filename: pb_one_press.cc Date: 2022-11-30 Author: Mervyn Bick Description: Starting with dBASE 12 and continuing in dBASE 2019, if a user Tabs to a pushbutton control it takes two presses of the Enter key to trigger the pushbutton's onClick event. If the user uses the mouse to click on the pushbutton the onClick event fires immediately. This custom pushbutton triggers the object's onClick event immediately if the user tabs to the control and then preses the Enter key. The custom control works without a problem in dBASE 11 so there should be no adverse effects if this bug is ever fixed for dBASE 2019. This custom control will only work with dBASE Plus 8 and later as the CALLBACK feature in not avaiable in earlier versions of dBASE. */ with (this) onOpen = CLASS::onOpen onClose = CLASS::onClose endwith function onOpen() #include winuser.h if type("GetWindowLongA") # "FP" extern CLONG GetWindowLongA(CHANDLE, CINT) user32 endif if type("SetWindowLongA") # "FP" extern CLONG SetWindowLongA(CHANDLE, CINT, CLONG) user32 endif if type("CallWindowProcA") # "FP" extern CLONG CallWindowProcA(CPTR, CHANDLE, CUINT, CUINT, CUINT) user32 endif if type("this.oldproc") = 'U' this.oldproc = GetWindowLongA(this.hwnd, GWL_WNDPROC) CALLBACK CLONG wndproc(CHANDLE, CUINT, CUINT, CUINT) OBJECT this this.newproc = GetCallAddress(class::wndproc) SetWindowLongA(this.hwnd, GWL_WNDPROC, this.newproc) endif return function onClose if type("this.oldproc") = "FP" if this.oldproc <> null and not empty(this.oldproc) // must restore original window procedure for pushbutton SetWindowLongA(this.hwnd, GWL_WNDPROC, this.oldproc) RELEASE CALLBACK wndproc OBJECT this endif endif return function wndproc(hwnd,umsg,wparam,lparam) if umsg = WM_CHAR and wParam = VK_RETURN //Enter key pressed while object has focus this.onClick() endif return CallWindowProcA(this.oldproc, hwnd, uMsg, wParam, lParam) endclass