A System-Wide Example
This example shows how to set up and install a system-wide
WH_SYSMSGFILTER
hook. You must place the filter
function and the functions that install and remove the hook in a
Win32 DLL. First I will show you the code contained in the VB EXE
that loads and uses the DLL. Figure 16-2 shows a
screenshot of the VB application.
Figure 16-2. Screenshot of the VB EXE
Table 16-2 presents the nondefault properties of the form and its controls.
Table 16-2. Nondefault Properties of the Form and Its Controls
Object |
Property Name |
Property Value |
---|---|---|
Form |
BorderStyle |
3-Fixed Dialog |
Form |
Caption |
“No Hooks Installed” |
Form |
Top |
330 |
Form |
Left |
45 |
Form |
Height |
1155 |
Form |
Width |
4905 |
Command Button1 |
Name |
cmdHook |
Command Button1 |
Caption |
“SYSMSGFILTER” |
Command Button1 |
Top |
120 |
Command Button1 |
Left |
1755 |
Command Button1 |
Height |
315 |
Command Button1 |
Width |
1395 |
Command Button2 |
Name |
cmdUnhook |
Command Button2 |
Caption |
“UNHOOK” |
Command Button2 |
Top |
660 |
Command Button2 |
Left |
1755 |
Command Button2 |
Height |
315 |
Command Button2 |
Width |
1395 |
The application contains a SYSMSGFILTER button that installs the system-wide hook and an UNHOOK button that removes the hook. The VB code that Example 16-1 illustrates is placed behind each button in the SysForm2.frm module.
Example 16-1. Event Procedures for the cmdHook and cmdUnhook Buttons
Private Sub cmdHook_Click( ) Call ...
Get Subclassing and Hooking with Visual Basic now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.