viksoe.dk

atlvbevents.h


This article was submitted .


Two plug-in ATL classes for your ActiveX controls.

The classes consist of custom message map handlers. They implement the standard Visual Basic 6 mouse and keyboard events:

MouseMove
MouseUp
MouseDown
Click
DblClick
KeyUp
KeyDown
KeyPress
All you need to do is to copy'n'paste the IDL code from the file, let the wizard generate the Connection Point code and chain the classes in your message map.

The classes will not eat your Windows messages, so you can still overload the behaviour of all the events.

How to use it

Copy the IDL code from the class file into the control's IDL file
 [id(DISPID_KEYDOWN)] void KeyDown(short KeyCode, short Shift);
 [id(DISPID_KEYUP)] void KeyUp(short KeyCode, short Shift);
 [id(DISPID_KEYPRESS)] void KeyPress(short *KeyAscii);
Compile the modified IDL file.
Let the ATL wizard generate a new Connection Point class (right-click in the class-browser and choose the "Implement Connection point" menu item).
Then add the event class to the class list...
class ATL_NO_VTABLE CMyControl : 
   public CComControl<CMyControl>,
   public CVbKeyEvents<CMyControl>,
   public CProxy_IMyControlEvents<CMyControl>
Chain the event class to the message map...
BEGIN_MSG_MAP(CMyControl)
   CHAIN_MSG_MAP(CComControl<CMyControl>)
   MESSAGE_HANDLER(WM_CREATE, OnCreate)
   CHAIN_MSG_MAP(CVbKeyEvents<CMyControl>)
END_MSG_MAP()
And there you have your keyboard events. Now do the same for the mouse class.

Source Code Dependencies

Microsoft ATL Library

See Also

Sample ActiveX control where the Keyboard class is used

Download Files

DownloadSource Code (3 Kb)

To the top