Hide

SftMask/OCX 7.0 - ActiveX Masked Edit Control

Display
Print

Using SftMask/OCX with Visual Studio (Unmanaged C/C++)

Adding SftMask/OCX To The Toolbox
Adding SftMask/OCX To A Project
Special Considerations
- Font Properties
- Color Properties

This section describes how SftMask/OCX is typically used with unmanaged C/C++ and Visual Studio .NET. For information on how to use this product with Visual C++ 6.0, please see Using SftMask/OCX with Visual C++ 6.0.

All interfaces offered by SftMask/OCX, such as ISftMask, ISftMaskCaption, etc. are implemented as dual interfaces. Using vtable binding is significantly more efficient than using the IDispatch interface. The approach presented here relies on the #import preprocessor directive available in Visual C++.

Adding SftMask/OCX To The Toolbox

The controls are automatically added to the Visual Studio Toolbox in the toolbox group "Softel vdm, Inc.", except for Visual Studio .NET 2002 and all Visual Studio Express Editions. For these, the controls have to be added "manually" using the simple procedure outlined in "Adding Controls To The Visual Studio Toolbox".

If you are using Visual Studio .NET 2002 or any of the Visual Studio Express Editions, please take a moment to add the controls using the simple procedure outlined in "Adding Controls To The Visual Studio Toolbox" before continuing.

Adding SftMask/OCX To A Project

Typically, the control is used with an MFC based application (or ATL). For this example, a sample MFC based application is used, but any unmanaged C or C++ application developed using Visual C++ can use this approach. This sample is created using the MFC AppWizard. A dialog based application is generated. While it is possible to use SftMask/OCX in non-dialog windows, this is rarely the case.

In order to use any ActiveX controls in an MFC based project, OLE control support has to be added to the project. This is accomplished automatically when using the Application Wizard (as long as ActiveX control support is selected), or can be added later in the CWinApp::InitInstance member function, by using the AfxEnableControlContainer() function. For more information on ActiveX controls and Visual C++ please see the Visual C++ documentation.

Adding The Control

The SftMask/OCX control can be added to a form, by locating the control in the toolbox group "Softel vdm, Inc.". It can be added to a form by clicking on the SftMask/OCX button of the toolbox, then clicking on the form or by dragging the SftMask/OCX button of the toolbox to the form.

Resize the control to a suitable size.

Adding A Member Variable

Member variables for the control can be added using ClassWizard, or simply by adding the required definitions to your dialog implementation.

"Manually" Adding A Member Variable

Add a variable for the control to your dialog's header file. The control class is always CWnd:

public:
    CWnd m_Mask1; <<<<<<<

Add a DDX_Control entry to your dialog's DoDataExchange function. Make sure the ID used matches the ID used in the dialog resource (IDC_SFTMASK in this example).

void CYourDialog::DoDataExchange(CDataExchange* pDX)
{
    CDialog::DoDataExchange(pDX);
    DDX_Control(pDX, IDC_SFTMASK1, m_Mask1); <<<<<<<<
}

Adding A Member Variable Using ClassWizard

Click on the control, then invoke the Add Member Variable Wizard using the menu command Project, Add Variable....

Enter a variable name, and optional comment and click Finish.

This will add the C++ wrapper classes needed to access SftMask/OCX. A number of C++ classes are generated for each object class supported by SftMask/OCX. The only wrapper class that is needed is the class CSftMask (based on the control's IDispatch interface). It is only needed to define the options control. Any other C++ classes generated can be discarded and are not used.

Using #import

Because the generated wrapper classes are not used, #import statements have to be added to STDAFX.H. The #import directive makes all interfaces and the associated methods and properties available to the application.

#import <msdatsrc.tlb> no_namespace

#pragma warning(disable : 4192) // automatically excluding 'Ixxx' while importing type library 'stdole2.tlb'
// For information about the following construct, please see Microsoft's
// KnowledgeBase entry Q224610
#import <SftMask_IX86_U_70.ocx> rename_namespace("SftMaskNameSpace") rename("LoadImage", "LoadImageSftMask")
#if _MSC_VER >= 1400 // need at least Visual Studio 2005
# pragma comment(lib, "comsuppw.lib") // avoid link error in VS2005
#endif
#pragma warning(default : 4192)

using namespace SftMaskNameSpace;

SftMask/OCX controls are installed in the Windows System(32) directory.

The #import statement generates two files, SftMask_IX86_U_70.tlh and SftMask_IX86_U_70.tli, which are automatically included into the source at the position of the #import directive. It does so by analyzing the type library which is built into the SftMask/OCX control. These files contain the definition of the methods and properties as shown in the Syntax section of each method and property.

VARIANT_BOOL Boolean = object->Enabled

In addition, lower level function calls are also defined.

VARIANT_BOOL Boolean = object->GetEnabled();
void object->PutEnabled

The generated header files SftMask_IX86_U_70.tlh and SftMask_IX86_U_70.tli should be used as a reference when using the functions and C++ properties. This documentation generally includes the higher level property variables and functions only. Some low-level functions are not shown and can only be found in the generated header files.

Which style is used depends on your preference. Both styles are identical in functionality but some styles are easier to use. For example, the Enabled property can be set using any of the following styles:

ISftMaskPtr vEdit1 = m_Edit1.GetControlUnknown();
vEdit1->Enabled = VARIANT_FALSE;

or

ISftMaskPtr vEdit1 = m_Edit1.GetControlUnknown();
vEdit1->PutEnabled(VARIANT_FALSE);

For more information on smart pointers such as ISftMaskPtr used above, please see the Visual C++ product documentation.

All required steps have now been completed to use SftMask/OCX.

Adding IntelliSense Help

IntelliSense information is available for SftMask/OCX 7.0, but it is not automatically added to your projects. To "activate" IntelliSense help, add the generated header files SftMask_IX86_U_70.tlh and SftMask_IX86_U_70.tli to your project. IntelliSense is only available for files that are part of your project. Using the Project, Add to Project, Files... menu command, locate the above header files in your project's directory or subdirectories and add these to your project. These files exist only after the project has been compiled at least once.

All required steps have now been completed to use SftMask/OCX.

Sample Initialization

Add the following sample code to initialize the control in the OnInitDialog member function of the dialog:

ISftMaskPtr vEdit1 = m_Edit1.GetControlUnknown();
vEdit1->Mask = _T("$D $T");
vEdit1->EditStyle = editSftMaskCalendarDropDown;
vEdit1->Contents->DateTime = COleDateTime( 2014, 12, 31, 9, 0, 0);
vEdit1->TabAdvance = VARIANT_TRUE;
vEdit1->AutoAdvance = VARIANT_TRUE;

In this example, the control is initialized at run-time using code. Of course it is also possible (and much easier) to set up all properties using the property pages. You can access the property pages by right-clicking on the control and select the Properties... entry of the popup menu.

You can run the sample application and it displays an edit control allowing entry of a date and time value with a popup calendar.

This sample displays an edit control for numeric input with popup calculator:

ISftMaskPtr vEdit1 = m_Edit1.GetControlUnknown();
vEdit1->Mask = _T("!1$C,8.2!!");
vEdit1->Alignment = alignSftMaskRight;
vEdit1->Contents->Value[1] = 88.12;

After adding the control to the form, right click on the control and select the Properties... entry of the popup menu. This displays the Property Dialog for the control.

Please note that you can right-click on a property. This displays a popup menu which can be used to access help information for the property or Property Dialog. Or double-click on the description of a property to access its help information.

This control has many properties and methods which you can use. This is a very simple example and doesn't even begin to exploit the capabilities of this control. Please take a moment to familiarize yourself with the objects offered by the SftMask/OCX control. Each object represents a specific area of the control and can be fully customized. Also make sure to run the demo which is included with this product and take a look at the included samples.

Special Considerations

The #import statement generates two files, SftMask_IX86_U_70.tlh and SftMask_IX86_U_70.tli, which are automatically included into the source at the position of the #import directive. It does so by analyzing the type library which is built into the SftMask/OCX control. These files contain the definition of the methods and properties as shown in the Syntax section of each method and property.

Font Properties

Fonts are represented using the OLE Font object and the IFontDisp interface. OLE Font objects can be created using the Windows API function OleCreateFontIndirect.

The Caption.Font property (for example) can be used as follows:

m_pMask1 = m_Mask1.GetControlUnknown();
_ASSERT(m_pMask1 != NULL);

IFontDispPtr pFontDisp = m_pMask1->GetFont();
IFontPtr pFont = pFontDisp;
pFont->put_Name(L"Times New Roman");
pFont->put_Bold(TRUE);
CY size;
size.int64 = 12*10000L; //12 point font
pFont->put_Size(size);

pFontDisp = m_pMask1->Caption->GetFont();
pFont = pFontDisp;
pFont->put_Name(L"Times New Roman");
pFont->put_Bold(FALSE);
size.int64 = 12*10000L; //12 point font
pFont->put_Size(size);

The Syntax section of font properties typically shows Get, Put and PutRef forms. If both Put and PutRef are available, PutRef is the preferred form as it conserves resources and assigns a font object reference to the control. Any change to the font object is reflected in the control also. Put on the other hand causes the control to completely copy the font object.

Color Properties

The valid range for a color value is 0 to 16,777,215 (0xffffff). The high order byte of a number in this range equals 0; the lower 3 bytes, from least to most significant byte, determine the amount of red, green, and blue, respectively. The red, green, and blue components are each represented by a number between 0 and 255 (0xff). If the high byte is not 0, the system colors as defined in Control Panel's settings are used. The Windows API GetSysColor defines all valid constants. Please see your development environment's documentation for applicable color constants.

vMask1->BackColor = 0x80000000L | COLOR_HIGHLIGHT;
vMask1->BackColor = 0x000000ffL;

Last Updated 08/13/2020 - (email)
© 2024 Softel vdm, Inc.