Download the vbalIPAO ActiveX DLL, code and demonstration project (15kb)
Implementing the IOLEInPlaceActiveObject interface is the only way to solve two
problems in VB:
However, if you follow the full code required to achieve this,
you will see that it is awkward and highly "un-basic" like.
- To allow your control to modify how it responds to the user pressing Tab or Shift-Tab
without requiring the user to set all TabStop properties to False and write their
own tabbing code.
- To allow a window created using the API to appear as part of the VB tab order.
This library provides a simple interface to the IOLEInPlaceActiveObject in a small ActiveX DLL
(17kb), isolating the code from your project, and also is designed so you only need to
move one class and one module to your UserControl to compile the support directly into your
Tab Trapping with vbalIPAO.Dll
The vbalIPAO library has three methods and one interface which you must implement to use the
methods. To use it, you first implement the IPAO interface. Add the line:
Once you have done this, you will have to fill in the IPAO_TranslateAccelerator method
with the code you want for the keys . This
method is fired when an Accelerator is pressed and your control is active. Accelerator keys in
UserControls are defined as the arrow keys (up, down, left, right), the Tab key and the Enter key.
The TranslateAccelerator parameters are:
If you wish to process the key, return a value of 0, otherwise return a value of 1.
- hWnd, iMsg, wParam, lParam
The SendMessage parameters of the message.
The KeyCode of the Accelerator key.
The current shift state.
- x, y
The mouse position relative to the screen at the time the message was generated, specified in
A long value specifying the time the message was generated.
Once you have an IPAO implementation, you can then use the library. Here are the methods:
Sub AttachIPAO(ByVal ctlRef As IPAO, ByVal hWnd As Long)
Connects the IOLEInPlaceActiveObject interface to a UserControl. Since the library uses a hWnd
property to keep track of which control(s) it is attached to, you need to wait until your UserControl's
hWnd property is valid. This occurs once either the
UserControl_InitProperties (if it is the first time you are using the control and there are no
stored properties) or the UserControl_ReadProperties event fires.
Sub DetachIPAO(ByVal hWnd As Long)
Detach the IOLEInPlaceActiveObject interface from a UserControl. Call this object when your control
terminates during the UserControl_Terminate event, otherwise a (very small)
memory and resource leak will occur.
Sub IPAOInPlaceActivate(ByVal ctlRef As IPAO, ByVal hWnd As Long)
Set an alternative TranslateAccelerator Handler. Call this method in response to a your main
control getting focus.
If you are creating an all VB control, you call this method whenever the UserControl's SetFocus
event occurs. Use exactly the same values in the parameters as you passed to the AttachIPAO
If you are creating a VB control which hosts an API created control, you need to
Subclass the UserControl for the WM_SETFOCUS
and WM_MOUSEACTIVATE messages. If either fires, call SetFocusAPI on the API
created control. Then subclass the API control for the WM_SETFOCUS message. When it occurs,
call this method.
To see an example of the library code in use in an API control, check out Mike Gainer's
Click here to view the vbalIPAO.DLL method and event documentation (3kb)
Back to top
Back to Source Code