VB3 Creating a Simulated Custom Method in VBX Custom Control

ID: Q119735

3.00 WINDOWS

The information in this article applies to:

- Standard and Professional Editions of Microsoft Visual Basic for

  Windows, version 3.0

SUMMARY

The Visual Basic VBX custom control architecture does not provide a mechanism for creating custom methods. Custom properties and custom events are supported, but only a set of eight predefined methods can be used by VBX custom controls.

However, to simulate a custom method, a VBX developer can attribute any meaning to the standard methods. To override the meaning of a standard method, you may want to use one of the two techniques described below.

MORE INFORMATION

Technique One: Implement a Custom Action Property

The most common way to simulate a custom method is to implement a custom action property. For example, assume that the control needs a custom line method. You could set up an action property that draws a line when the property is set.

Below is a hypothetical code example:

    ' Draw line from (20,30)-(200,15)
    MyControl.StartX = 20
    MyControl.StartY = 30
    MyControl.EndX = 200
    MyControl.EndY = 150

    MyControl.Action = DRAW_LINE

When the custom control receives a message that the Action property is being set, it can use the information in the StartX, StartY, EndX, and EndY properties to draw a line.

This technique is very popular and is used in several of the custom controls that ship with the Professional Edition of Visual Basic version 3.0.

Technique Two: Use an Exported Function

As an alternative, you can use an exported function within the VBX itself. For example, add the following code to the Visual Basic program:

   Declare Function CustomMethod Lib control.vbx (X As Control, ...

Add the following to the VBX code:

   int FAR PASCAL _export CustomMethod( HCTL hctl, ...
   {
     //Perform the custom method on the given hctl.
   }

This technique is also used in some Professional Edition controls (for example, the MSComm control). This technique allows you to pass more than one parameter to your control, but it also requires slightly more code on the part of the Visual Basic programmer.

KBCategory: KBSubcategory: TlsCDK Additional reference words: 3.00

Keywords          : kbcode TlsCDK 
Version           : 3.00
Platform          : WINDOWS

Last Reviewed: May 22, 1998