The new vbAccelerator Site - more VB and .NET Code and Controls
Source Code
3 Code Libraries &nbsp
Simpler UserControl Tab Trapping.
Create controls which manage the Tab key with this DLL wrapper around IOLEInPlaceActiveObject
&nbsp

Download the vbalIPAO ActiveX DLL, code and demonstration project (15kb)

&nbsp Source Code Note &nbsp
&nbsp This DLL is a binary compatible component which works with all other samples. If you compile your own copy of this DLL yourself please make sure you change the name. See disclaimer and license for more details.

&nbsp
&nbsp Before you Begin &nbsp
&nbsp The source code project requires the IShellFolder Extended Type Library v1.2 (ISHF_Ex.TLB) when running in the IDE. Make sure you have downloaded and registered this before trying the project. &nbsp
&nbsp The source code project requires the Ole GUID and interface definitions Type Library (OLEGUIDS.tlb) when running in the IDE. Make sure you have downloaded and registered this before trying the project. &nbsp

Overview
Implementing the IOLEInPlaceActiveObject interface is the only way to solve two problems in VB:

  1. 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.
  2. To allow a window created using the API to appear as part of the VB tab order.
However, if you follow the full code required to achieve this, you will see that it is awkward and highly "un-basic" like.

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 control.

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:

Implements IPAO

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:
  • hWnd, iMsg, wParam, lParam
    The SendMessage parameters of the message.
  • iKeyCode
    The KeyCode of the Accelerator key.
  • iShiftState
    The current shift state.
  • x, y
    The mouse position relative to the screen at the time the message was generated, specified in pixels.
  • time
    A long value specifying the time the message was generated.

If you wish to process the key, return a value of 0, otherwise return a value of 1.

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 method.

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 TextBoxEx control.

Click here to view the vbalIPAO.DLL method and event documentation (3kb)



TopBack to top

Source Code - What We're About!Back to Source Code

&nbsp

AboutContributeSend FeedbackPrivacy

Copyright 1998-1999, Steve McMahon ( steve@vbaccelerator.com). All Rights Reserved.
Last updated: 25 August 1999