class arrows_EF(parentObj) of EntryField(parentObj) custom /* Filename: arrows_EF.cc Date: 2017-03-21 Author: Mervyn Bick Description: A custom entryfield that detects up_arrow and down_arrow keypresses that do not trigger the control's key or onKey events. When an up or down arrow is detected the control will execute the function arrow_pressed. If a like-named function is created on the form it will be executed. 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 onGotFocus := CLASS::onGotFocus onLostFocus := CLASS::onLostFocus 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 this.oldproc = null this.newproc = null if type("this.oldproc") # "FP" this.oldproc = GetWindowLongA(this.hwnd, GWL_WNDPROC) CALLBACK CLONG wndproc(CHANDLE, CUINT, CUINT, CUINT) OBJECT this endif if type("this.newproc") # "FP" this.newproc = GetCallAddress(class::wndproc) endif return function onGotFocus SetWindowLongA(this.hwnd, GWL_WNDPROC, this.newproc) return function onLostFocus SetWindowLongA(this.hwnd, GWL_WNDPROC, this.oldproc) return function onClose if type("this.oldproc") = "FP" if this.oldproc <> null and not empty(this.oldproc) SetWindowLongA(this.hwnd, GWL_WNDPROC, this.oldproc) RELEASE CALLBACK wndproc OBJECT this endif endif return function arrow_pressed(wparam) if type("this.parent.arrow_pressed") # 'FP' if wparam = VK_UP or wparam = VK_DOWN msgbox(wparam+' Up or down arrow pressed') endif else this.parent.arrow_pressed(wparam) endif return function wndproc(hwnd,umsg,wparam,lparam) if umsg = WM_KEYDOWN if wparam = VK_UP or wparam = VK_DOWN class::arrow_pressed(wparam) endif endif return CallWindowProcA(this.oldproc, hwnd, uMsg, wParam, lParam) endclass