Home Search Contact us About us
Title How to create a Persistent Property in an ActiveX control.
Summary This article discusses creating a Persistent property in an ActiveX control that can be modified in IDE such as VB, Delphi and Visual Studio.NET.
Contributor John McTainsh
Published 20-Feb-2001
Last updated 20-Feb-2001
Page rating   Be the first to rate this page! Useless Brilliant

Description.

Using ActiveX control properties is like loading or storing a controls data to/from a persistent storage. This is the case when a developer uses your ActiveX control and wants certain setting to be set when it first starts up. These settings are modified in the IDE.

How to save and recover Persistent settings.

This is much easier than you might expect. The following guides you through creating a property and then persisting the property.

  • Creating a property. - First create the control property.
    • Open the MFC Wizard.
    • Select the Automation tab.
    • Choose "Add Property".
    • Set the external name which the caller will use
    • Set the internal name use by the control usually m_XXXX.
    • Set the data type.
  • Make the variable persistent.
    • Locate the DoPropExchange function.
    • To the end of this function add
          PX_Double( pPX, _T("RangeMin"), m_dRangeMin,    0.0 );
      
    • Here the the double value is persisted to RangeMin.
    • There is a PX_ available for most data types.
  • Add the Property page (Use can use the control without addind a property page if necessary).
    • Open the dialog resource named IDD_PROPPAGE_???.
    • Add your property items to this dialog. Be careful not to change the dialog size. The dialog MUST be either 250x110 or 250x63.
    • Right click on the edit box for the property item and Select "Class wizard".
    • You should be in the Member Variable Tab.
    • Highlight the control ID and choose select "Add Variable".
    • Fill out the property sheet as normal. However, the "Optional property name" MUST be the same as the name used in the PX_ field of DoPropExchange.

Closing note.

When building an AcctiveX control, it is important to test it under as many different development environments as possible. Often vendors perform differently in the IDE. For this reason I test against VC, VB and Delphi.

Also note that the control behaves differently when in the IDE to when it is running. One way to make your control appear differently in the IDE is to use AmbientUserMode().

For each property you add a CXXXXCtrl::OnYYYYChanged() will be added. Here you will be tempted to use CDC or CWnd to update the display DON'T. Call Refresh() to cause the OnDraw to be called for the control.

Comments Date
Home Search Contact us About us