Most of our GUI components for building Microsoft Windows applications are class libraries built on top of MFC classes, and are intended to provide complete integration with MFC. But what about companies who use other frameworks, like Zugg Software's zApp, or need to maintain legacy Windows SDK code?
Here's an approach that lets non-MFC applications access MFC components using Stingray Objective Grid, a library of MFC extension classes for implementing grid controls. Instead of rewriting a whole project, you can subclass and customize Objective Grid classes with MFC and export an interface to your existing application. This approach works well even when using Objective Grid from .NET languges like C# or VB.NET. You can find more details in the Knowledge Base article "Stingray Studio MFC Projects Integration with .NET". To get to the Knowledge Base, go to kb.roguewave.com/kb/ and click on the Stingray link.
It is possible to convert into a regular DLL not just a dialog-based application, but also SDI or MDI applications with rich functionality. You can find an additional sample with an SDI application converted into a DLL in <stingray-installdir>\Samples\Grid\General\PrintPreview.
In this section, we create a regular DLL that registers a customized grid as a window class in the Microsoft Windows environment. This way you can incorporate Objective Grid into a dialog the same way as a regular Windows SDK control. You can then instantiate a grid window through a call to the Windows SDK CreateWindow() method, or embed the grid as a custom control into a dialog template with a resource editor. Here are the steps:
Create a DLL to export the grid window.
a. | First, create a regular DLL with Visual Studio by selecting File|New|Project, and select MFC DLL. Figure 129: New Project |
b. | Specify ogregdll as the Project name and click OK. |
c. | In the dialog that appears, select Regular DLL with MFC statically linked. Figure 130: MFC DLL Wizard |
d. | Click Finish to close the window. |
Add the initialization code for Objective Grid.
a. | To do this, open the file stdafx.h and insert:
at the end of the file. | ||||
b. | Bring up the resource tree by selecting Resource View from the View menu. | ||||
c. | Right-click on the root node (ogregdll.rc) and select Resource Includes from the context menu. | ||||
d. | In Resource Includes, add
to the Read-Only Symbol Directives, and
to the end of Compile-time Directives, and click OK. | ||||
e. | A warning dialog box saying, "Directive Text will be written into your resource script and may render it uncompilable." pops up. Discount the warning and click OK to save the resource file. | ||||
f. | Now, select Class View from the View menu. | ||||
g. | Right click on COgreddllApp and select Properties from the context menu. All the overridable functions will be shown at the bottom. | ||||
h. | Click on Overrides and override InitInstance and ExitInstance if they are not already overridden. Figure 131: ClassWizard | ||||
i. | Add a call to GXInit() in InitInstance(). Normally no termination code is necessary. However, if you are dynamically loading and unloading a DLL or an OCX that uses Objective Grid, you should add a call to GXForceTerminate() in the DLL's or OCX's ExitInstance(). | ||||
j. | In each case, select <Edit Code> in the drop down box to jump to the code. | ||||
k. | After editing, save and exit the code window. |
Add a customized class for Objective Grid.
a. | Open Class View again, right click on ogregdll and select Add Class from the Add menu. |
b. | Select Visual C++|MFC|MFC Class to add a MFC Class to the project. |
c. | In the New Class dialog box specify CWnd as the base class and name it CMyGridWnd. |
d. | Click Done in the dialog. |
e. | Now open MyGridWnd.cpp and MyGridWnd.h in the editor and replace all occurrences of CWnd with CGXGridWnd. |
f. | Add the Objective Grid macro GRID_DECLARE_REGISTER() to the class declaration in MyGridWnd.h and GRID_IMPLEMENT_REGISTER(CMyGridWnd, CS_DBLCLKS | CS_GLOBALCLASS, 0, 0, 0) to MyGridWnd.cpp. You can also use ClassWizard to add methods to this class, such as OnLButtonDblClk() to customize the standard grid behavior. |
Register and Compile.
a. | Add a call to CMyGridWnd::RegisterClass in InitInstance() and include CMyGridWnd to the stdafx.h file.
| |
b. | Compile as usual. |
Use.
a. | To use CMyGridWnd outside MFC, just call LoadLibrary("ogregdll.dll") from your application. You can instantiate a grid by calling:
with your usual parameters, or by using it in a dialog template. |
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.