Microsoft KB Archive/140522

= How to Create a Simulated Custom Method in VBX Custom Control =

Article ID: 140522

Article Last Modified on 1/8/2003

-

APPLIES TO


 * Microsoft Visual Basic 4.0 Professional Edition
 * Microsoft Visual Basic 4.0 16-bit Enterprise Edition

-



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.



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 query words: 3.00 4.00 vb416 vb4win

Keywords: KB140522

-

[mailto:TECHNET@MICROSOFT.COM Send feedback to Microsoft]

© Microsoft Corporation. All rights reserved.