How to Create a Simulated Custom Method in VBX Custom Control

Last reviewed: December 4, 1995
Article ID: Q140522
The information in this article applies to:
  • Professional and Enterprise Editions of Microsoft Visual Basic, 16-bit only, for Windows, version 4.0

SUMMARY

The Microsoft 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:

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


Additional reference words: 3.00 4.00 vb416 vb4win
KBCategory: kbprg kbcode kbhowto
KBSubcategory: TlsCDK


THE INFORMATION PROVIDED IN THE MICROSOFT KNOWLEDGE BASE IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND. MICROSOFT DISCLAIMS ALL WARRANTIES, EITHER EXPRESS OR IMPLIED, INCLUDING THE WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. IN NO EVENT SHALL MICROSOFT CORPORATION OR ITS SUPPLIERS BE LIABLE FOR ANY DAMAGES WHATSOEVER INCLUDING DIRECT, INDIRECT, INCIDENTAL, CONSEQUENTIAL, LOSS OF BUSINESS PROFITS OR SPECIAL DAMAGES, EVEN IF MICROSOFT CORPORATION OR ITS SUPPLIERS HAVE BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. SOME STATES DO NOT ALLOW THE EXCLUSION OR LIMITATION OF LIABILITY FOR CONSEQUENTIAL OR INCIDENTAL DAMAGES SO THE FOREGOING LIMITATION MAY NOT APPLY.

Last reviewed: December 4, 1995
© 1998 Microsoft Corporation. All rights reserved. Terms of Use.