| Subject |
Re: radio button |
| From |
Mervyn Bick <invalid@invalid.invalid> |
| Date |
Wed, 22 Jul 2020 15:24:06 +0200 |
| Newsgroups |
dbase.getting-started |
On 2020-07-20 13:04, Andy Taylor wrote:
> Mervyn,
>
> Nice. I will study this so I can get to grips with callback !
>
The CALLBACK command has been part of dBASE since dBASE Plus 8 but very
few programmers seem to have embraced it. This is a pity as it can be
very useful and it really is easy to use.
Behind every object on a form is a Windows procedure that passes
instructions to and from the object. CALLBACK allows us to replace the
Windows procedure with our own procedure.
The Windows API function GetWindowLongA() gives us the address in the
Windows pointer to the object's wndproc. This address is saved so
things can be restored when the form is closed. Windows tends to get
upset if this isn't done.
The dBASE CALLBACK command identifies the function in the program which
Windows will be directed to in place of it's own procedure. The
arguments for the replacement function must match those of the Windows
function.
The dBASE function GetCallAddress() gets the address in memory of the
replacement function. The Windows API function SetWindowsLongA() is
then used to paste this address into the Windows pointer. From now on
instead of calling it's own function Windows will call the replacement
function.
The replacement function sees all keystrokes and mouse actions,
including those that dBASE would ignore in the normal course of events,
before the actual control sees them. For instance the onKey event of an
entryfield doesn't see the arrow, home and end keys. The cursor in the
entryfield does, however respond to them. By watching for the relevant
messages one can keep track of where the cursor is in the entryfield.
As another example, by monitoring the mousewheel a few lines of code
allows a spinbox to be set by the mousewheel.
A bug in the radiobutton class results in the onChange event firing
before the onLeftMouseDown event. By using CALLBACK to monitor the
mouse clicks the left mouse button down was seen before the onChange
event fired which made it possible for the user to cancel the change if
necessary.
The windows API function CallWindowProcA() is used to pass the
intercepted messages back to the normal Windows procedure for further
processing.
In theory one should be able to change a message before passing it back
to Windows but I haven't managed to do this.
CALLBACK can also be used to install keyboard and mouse hooks which
operate globally rather than on specific objects. Here I have been able
to "swallow" keystrokes.
Mervyn.
|
|