Introduction (Windows 101)

Akemi Window Spy

Our philosophy at Akemi is that "Windows is meant to be easy, and Visual Basic is meant to be easy".  This is not intended to belittle the efforts of the millions of Visual Basic programmers who are producing serious professional code.  It merely a statement of one of the key reasons for the widespread success of Visual Basic.

By making the "hard" parts of Windows programming easier, we hope to give you the programmer, more time to concentrate on what you do best - writing applications that do stuff.

Akemi Spy Library is an ActiveX DLL which encapsulates some of the functionality of Windows Hooks.

Windows Hooks are used to monitor the system for certain types of events.  These events are associated with a specific thread or with all threads in the same desktop as the calling thread.

This is slightly different from the usual way of Visual Basic programming, where events are associated with a form or a visual control placed on a form.

What counts as a window?

Under Microsoft Windows, a window is a (usually rectangular) area managed by the operating system and assigned a window handle (also known as an hWnd).

A window can be a top-level or Mdi child window.  This is what end-users are usually referring to when they say "window".  In Win32 programming, a window can also be an ActiveX control, or an invisible window used to process a Message Queue.

Messages

The operating system sends messages to individual windows in response to user actions.  For example, whenever you move your mouse pointer, the system is dispatching a series of WM_MOUSEMOVE messages to whichever window the mouse is over.

Every window which processes messages must have a Window Procedure.  When you design a form in Visual Basic, Visual Basic creates a window procedure which raises events that you can handle through Visual Basic code.

To handle messages which are not implemented as Visual Basic events requires the use of a technique known as subclassing.  Subclassing can only be used to process messages received by windows owned by the thread which processes them.  Subclassing is not a part of Akemi Spy Library.

Hooks (more information than you need to know, if you are using Akemi Spy Library)

Under Win32, hooks are the only way of trapping events in processes other than your own.

Hooks can be set by calling the Windows API function SetWindowsHookEx, specifying the type of hook you want to set, and the address of a hook procedure for Windows to call when the hook is triggered.

The catch is, that if you are setting a global hook, or a single thread hook for a thread in a different process to your application, then the hook procedure supplied to SetWindowsHookEx must reside in a DLL, and a new instance of that DLL will be attached to each thread which triggers the hook.

That means that the DLL will be in a different address space from the application which set the hook.  Therefore there needs to be some form of cross-process communication in order for your application to receive information from hooks.

Akemi Spy Library accomplishes this by installing hook procedures which send messages to an invisible window which gets attached to your application.  The window procedure for this invisible window passes these messages to your application as COM events, much the same way that Visual Basic raises standard events in response to messages sent to standard Visual Basic forms. 

Limitations of Akemi Spy Library

At this time, there are certain types of Windows hooks which cannot be obtained using Akemi Spy Library.  In particular, the Journalling hooks which allow recording and playback of mouse and keyboard events.

These features may be added to a future version of the Spy Library if there is sufficient demand.  In the meantime, consider using one of the following techniques for manipulating applications.

(i)  The SendMessage API.  It is possible to invoke the menu commands of other applications by sending a WM_COMMAND message.  This may be preferable to sending keystrokes which will visually bring up the application's menu.

(ii)  SendKeys.  This is a built-in VB/VBA procedure which can be used to simulate keystrokes.

Also, Akemi Spy Library is currently limited to 10 simultaneous hooks.  I have not yet run into a situation where this is not sufficient.  If you do, then contact support@akemivb.com 

 

Home Copyright and Disclaimer