Rogue Wave banner
Previous fileTop of DocumentContentsIndex pageNext file
Objective Views User's Guide
Rogue Wave web site:  Home Page  |  Main Documentation Page

3.6 Integrate Objective Views into an Existing Project

To add Objective Views functionality to an existing program, you need to complete the steps that Objective Views AppWizard automatically implements when it creates a skeleton application. In the following tutorial, you add code to a typical MDI application so you can use the Objective Views Library. If you have a different configuration, some of these steps may differ.

3.6.1 Including Objective Views Files

  1. Let's include the Objective Views header files. Open the file stdafx.h and add the following line near the end of the file:

  2. Now, add the Objective Views resources from the View menu and select Resource Includes.

  3. In the Read-only symbol directives box, type the following code on the last line:

  4. In the Compile-time directives box, type the following line:

  5. Click the OK button. A warning dialog appears. Click the OK button again.

  6. Include header files that are common for all Stingray Studio products:

3.6.2 Adding MVC Architecture and OLE Support

If you have configured your application to include MVC architecture and OLE support, use the following steps to add them.

3.6.2.1 Add the Property Cache

  1. Let's add the global Property Cache. Open the source file that holds the implementation of your main application object. If you were working with a project named Foobar, this would be called Foobar.cpp.

  2. After the declaration of the application object (theApp), add the declaration of the global property cache object:

3.6.2.2 Add the Model and Support for OLE Drag-and-Drop

  1. Now, add a Model to your document object. Open your document's header file (for example, FoobarDoc.h).

  2. Add your model or the default model CODModel as a member variable:

  3. Now, add an accessor method for your model:

  4. Open your document's source file (for example, FoobarDoc.cpp).

  5. Add the model to the Serialize() method.

  6. Now, add support for OLE drag-and-drop. If you would like to use the OLE drag-and-drop features in addition to Objective Views drag-and-drop, you need to initialize the OLE libraries. Ensure that the following code is at the beginning of your application object's InitInstance() method.

  7. Ensure that your string table contains a string resource for IDR_OLE_INIT_FAILED. If it does not, add one.

3.6.2.3 Add the Viewport

  1. Let's add a viewport to your view object. Open your view's header file (for example, FoobarView.h).

  2. Add your viewport or one of the standard viewports supplied with Objective Views as a member variable. The CODScrollViewport has scrollbars and the CODViewport does not.

  3. Now, you need to add the viewport to the CView::OnDraw() method: In your view's source file, add a call to the Refresh() method in the viewport's OnDraw() method:

  4. Add the OnCreate() method to your view object. Use the Class Wizard to add a handler to your view for the WM_CREATE message.

  5. In the resulting OnCreate() method, add code to attach the model to the viewport.

  6. Now, add the OnInitialUpdate() method to your view object. Use the Class Wizard to add an override method for OnInitialUpdate().

  7. In the OnInitialUpdate() method, call the OnInitialUpdate() method of the viewport.

  8. Let's add the OnSize() method to your view object. Use the Class Wizard to add a handler for the WM_SIZE message.

  9. On the OnSize() method, call the SetSize() method for the viewport.

  10. Override OnCmdMsg() in your view object. In the view's header file, add a public declaration for OnCmdMsg():

  11. In the view's source file, add an implementation of OnCmdMsg() that gives the viewport access to the messages:

  12. Let's override OnWndMsg() in your view object. In the view's header file, add a public declaration for OnWndMsg():

  13. In the view's source file, add an implementation of OnWndMsg() that gives the viewport access to the messages:

At this point, you can build and run the application to verify that you did everything correctly so far. Make sure that you have built the OV libraries (they should be in the <stingray-installdir>\Lib directory). A view with a canvas should appear on the screen. There are no commands in place to do anything with it. If a grid of dots is visible, the application is working correctly.

3.6.3 Adding Menu Items and Accelerators

  1. Now, add Objective Views menu items. If you want menu items that interact with the view, you can copy them from the Objective Views resources into your own. Make sure you do not move them from the Objective Views resources. Open your application's resource file and then open Objective Views's resource file, which is stored in the Objective Views Include directory.

  2. Highlight the menu items you want to include in your application from Objective Views's View menu and then copy them.

  3. Select the empty space in your application's View menu and paste in the items. Then, delete the string resources for these menu items from your string table. Each resource ID for the menu items will be prefixed by ID_OD_.

  4. Now let's add Objective Views accelerators. The OdRes.rc file contains a set of common accelerators used with Objective Views.

  5. Select the accelerators you want to use in your application and then copy them.

  6. Select the empty slot in your application's accelerator table and then paste the accelerators.

3.6.4 Adding Objective Views Toolbars

Now, add Objective Views toolbars. The Objective Views resources include several defined toolbars that fire commands recognized by the CODController. They are divided by function:

Drawing Toolbar IDR_OD_DRAWING
Rotation Toolbar IDR_OD_ROTATE
Structure Toolbar IDR_OD_STRUCTURE
Nudge Toolbar IDR_OD_NUDGE
Alignment Toolbar IDR_OD_ALIGN
Zoom/Pan Toolbar IDR_OD_ZOOM_PAN
Link Toolbar IDR_OD_LINK
Layout Toolbar IDR_OD_LAYOUT
Canvas Toolbar IDR_OD_CANVAS

You can include any combination of these toolbars. You can also choose individual buttons to create toolbars with specific functionality.


If you want to use the standard Objective Views toolbars, you do not need to copy them into your application's resources because the toolbars are imported from OdRes.rc at compile time. If you want to make your own custom toolbars, you need to create new ones in your project and copy the buttons from OdRes.rc.


The following procedure is applicable if the MFC feature pack is not used. Otherwise, see the document Stingray Feature Pack Migration and the ShowcaseEx sample.

  1. You add an OV toolbar to your frame window just like you would any other toolbar. In your main frame's header file (for example, MainFrm.h), add a member variable for the toolbar:

  2. In your main frame's source file (for example, MainFrm.cpp), add code to create the toolbar in the OnCreate() method:

  3. To make the toolbar dockable, type the following line to enable docking.

  4. Set the name of the toolbar, which appears in the caption when it is floating.

  5. If you want to dock toolbars to the frame window, add the following line to the OnCreate() method.

  6. Now, you can dock all the toolbars you created with calls like the following.

  7. Objective Views's CODGlobal class has a static utility method for docking one toolbar to the left of another. To use it, make a call like the following.

Now you can use your MDI application with Objective Views. With Objective Views, you can define your own symbols, add them to the toolbar, and then let Objective Views integrate them into the application.

To add symbols, you need to handle more messages than the default CODController contains. To add functionality to the controller, derive your own controller from it and add whatever behavior you need. When you derive the controller, you also need to derive a new class from CODViewport to create the new controller.



Previous fileTop of DocumentContentsNo linkNext file

Copyright © Rogue Wave Software, Inc. All Rights Reserved.

The Rogue Wave name and logo, and Stingray, are registered trademarks of Rogue Wave Software. All other trademarks are the property of their respective owners.
Provide feedback to Rogue Wave about its documentation.