tutorials | com programming embedding...

5
1/5 [email protected] WWW.VISUALCOMPONENTS.COM The Visual Components logo 3DCreate, 3DRealize and 3DVideo are registered trademarks of Visual Components Oy, Inc., registered in the USA, Europe and/or other countries. All other brand names, product names, or trademarks belong to their respective holders. INTRODUCTION THIS TUTORIAL EXPLAINS HOW TO EMBED 3DCREATE INTO AN APPLICATION CREATED WITH MICROSOFT VISUALSTUDIO C++. OBJECTIVES THE OBJECTIVE OF THIS TUTORIAL IS TO CREATE A MFC DIALOG APPLICATION AND EMBED THE 3DCREATE 3D WINDOW IN IT. STEPS 1. Start Visual C++ and create a new MFC application 1.1 Start Visual C++ and select ‘File > New’ from the menu. 1.2 Enter ComTutorial4 as the name of the project. Select MFC AppWizard(exe) and click OK to start the wizard. 1.3 Select Dialog based from the alternatives, then click Next. RELATED FILES VCApplication.zip Description Files related to this tutorial TUTORIALS | COM PROGRAMMING EMBEDDING 3DCREATE INTO A VISUAL C++

Upload: builiem

Post on 06-May-2018

255 views

Category:

Documents


2 download

TRANSCRIPT

Page 1: TUTORIALS | COM PROGRAMMING EMBEDDING …download.visualcomponents.net/elib/3.1/eCat/EquipmentLibrary/6... · tutorials | com programming embedding 3dcreate into a visual c++. support@visualcomponents.com

1/5

[email protected]

WWW.VISUALCOMPONENTS.COM

The Visual Components logo 3DCreate, 3DRealize and 3DVideo are registered trademarks of Visual Components Oy, Inc., registered in the USA, Europe and/or other countries. All other brand names, product names, or trademarks belong to their respective holders.

INTRODUCTIONTHIS TUTORIAL EXPLAINS HOW TO EMBED 3DCREATE INTO AN APPLICATION

CREATED WITH MICROSOFT VISUALSTUDIO C++.

OBJECTIVESTHE OBJECTIVE OF THIS TUTORIAL IS TO CREATE A MFC DIALOG APPLICATION

AND EMBED THE 3DCREATE 3D WINDOW IN IT.

STEPS

1. Start Visual C++ and create a new MFC application

1.1 Start Visual C++ and select ‘File > New’ from the menu.

1.2 Enter ComTutorial4 as the name of the project. Select MFC AppWizard(exe) and click OK to start the wizard.

1.3 Select Dialog based from the alternatives, then click Next.

RELATED FILESVCApplication.zip

Description Files related to this tutorial

TUTORIALS | COM PROGRAMMING

EMBEDDING 3DCREATE INTO A VISUAL C++

Page 2: TUTORIALS | COM PROGRAMMING EMBEDDING …download.visualcomponents.net/elib/3.1/eCat/EquipmentLibrary/6... · tutorials | com programming embedding 3dcreate into a visual c++. support@visualcomponents.com

[email protected]

WWW.VISUALCOMPONENTS.COM

The Visual Components logo 3DCreate, 3DRealize and 3DVideo are registered trademarks of Visual Components Oy, Inc., registered in the USA, Europe and/or other countries. All other brand names, product names, or trademarks belong to their respective holders.

TUTORIALS | COM PROGRAMMING | EMBEDDING 3DCREATE INTO A VISUAL C++ 2/5

1.4 Make sure ActiveX Controls is checked, then click Next.

1.5 Click Next, then Finish to fi nish the wizard.

2. Import vcApplicationWindowX into the application

2.1 Select ‘Project > Add To Project > Components And Controls...’ from the menu.

Page 3: TUTORIALS | COM PROGRAMMING EMBEDDING …download.visualcomponents.net/elib/3.1/eCat/EquipmentLibrary/6... · tutorials | com programming embedding 3dcreate into a visual c++. support@visualcomponents.com

[email protected]

WWW.VISUALCOMPONENTS.COM

The Visual Components logo 3DCreate, 3DRealize and 3DVideo are registered trademarks of Visual Components Oy, Inc., registered in the USA, Europe and/or other countries. All other brand names, product names, or trademarks belong to their respective holders.

TUTORIALS | COM PROGRAMMING | EMBEDDING 3DCREATE INTO A VISUAL C++ 3/5

2.2 In the component browser dialog, select Registered ActiveX Controls, then ‘Visual Components Application Window Control.

In the class selection dialog, make sure you check at least the following classes: • CvcApplicationWindowX • CvcApplication

The other classes are not necessary for this tutorial, so they can be unchecked to minimize the amount of code generated. This is because this tutorial uses the ATL wrappers to do the actual work, whereas the MFC classes are only needed to encapsulate the Visual Components Application Window control.

2.3 Open IDD_COMTUTORIAL4_DIALOG from the resource browser. Select the Visual Components Application Window control from the control palette and add the component to the main dialog.

Page 4: TUTORIALS | COM PROGRAMMING EMBEDDING …download.visualcomponents.net/elib/3.1/eCat/EquipmentLibrary/6... · tutorials | com programming embedding 3dcreate into a visual c++. support@visualcomponents.com

[email protected]

WWW.VISUALCOMPONENTS.COM

The Visual Components logo 3DCreate, 3DRealize and 3DVideo are registered trademarks of Visual Components Oy, Inc., registered in the USA, Europe and/or other countries. All other brand names, product names, or trademarks belong to their respective holders.

TUTORIALS | COM PROGRAMMING | EMBEDDING 3DCREATE INTO A VISUAL C++ 4/5

2.4 Delete the Cancel button and add a command button.

2.5 Open the event dialog and add handlers for the following events:

Add the following handlers to CComTutorial4Dlg:

• WM_CLOSE • WM_INITDIALOG: This one is probably added already Add a WM_CLICK handler to IDOK button and the newly created

command button (IDC_BUTTON1).

3. Import the vcCOM type library and create member variables

3.1 Import the vcCOM type library by adding the following line after the #includes in ComTutorial4Dlg.h:

#import \ “c:\Program Files\Visual Components\3DCreate 3.0\Bin\vccom.tlb”

If 3DCreate is installed in a different location on your machine, modify the path accordingly.

3.2 Add the following line in the protected section of CComTutorial4Dlg:

vcCOM::IvcApplicationPtr m_vcapp;

3.3 Create a member variable for the Visual Components Application Window control by opening the ClassWizard through the popup menu.

3.4 Select the Member Variables tab, then select the Visual Component Application Window control (IDC_VCAPPLICATIONWINDOWX1). Then click Add Variable...

Page 5: TUTORIALS | COM PROGRAMMING EMBEDDING …download.visualcomponents.net/elib/3.1/eCat/EquipmentLibrary/6... · tutorials | com programming embedding 3dcreate into a visual c++. support@visualcomponents.com

[email protected]

WWW.VISUALCOMPONENTS.COM

The Visual Components logo 3DCreate, 3DRealize and 3DVideo are registered trademarks of Visual Components Oy, Inc., registered in the USA, Europe and/or other countries. All other brand names, product names, or trademarks belong to their respective holders.

TUTORIALS | COM PROGRAMMING | EMBEDDING 3DCREATE INTO A VISUAL C++ 5/5

3.5 Enter m_vcwindow as the name of the variable. Click OK.

4. Add code to the event handlers

4.1 Open ComTutorial4Dlg.cpp. Add the following line after the other #include lines.

#include “vcapplication.h”

4.2 Add the following line before the return statement in CComTutorial4Dlg::OnInitDialog():

m_vcapp = m_vcwindow.Start(“3DCreate”).m_lpDispatch;

This will ensure that 3DCreate is started when the dialog is initialized.

4.3 Add the following lines to CComTutorial4Dlg::OnClose() and CComTutorial4Dlg::OnOK() before calling the corresponding CDialog methods:

m_vcapp = NULL;m_vcwindow.Stop();

4.4 Add the following lines to CComTutorial4Dlg::OnButton1:

vcCOM::IvcComponentPtr cmp = m_vcapp->createComponent(“Test”);vcCOM::IvcFeaturePtr feature = cmp->RootNode->RootFeature->createFeature(“Block”);feature->setProperty(“Width”,1000L);feature->setProperty(“Height”,1000L);feature->setProperty(“Length”,1000L);cmp->rebuild();m_vcapp->render();

This will create a new component with a 1000x1000x1000 block in it.

5. Compile and run the application

NOTE! m_vcwindow.Stop() must be called before closing the window the control is in.