How to Create a Simulated Custom Method in VBX Custom Control (140522)
The information in this article applies to:
- Microsoft Visual Basic Professional Edition, 16-bit, for Windows 4.0
- Microsoft Visual Basic Enterprise Edition, 16-bit, for Windows 4.0
This article was previously published under Q140522 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 INFORMATIONTechnique 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.
Modification Type: | Minor | Last Reviewed: | 1/8/2003 |
---|
Keywords: | KB140522 |
---|
|