Objective Grid : PART II Programmer’s Guide : Chapter 15 Advanced Concepts : Using This Product Outside MFC
Using This Product Outside MFC
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:
1. 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.
2. Add the initialization code for Objective Grid.
a. To do this, open the file stdafx.h and insert:
 
#include <grid\gxall.h>
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
 
#include "grid\gxresrc.h"
to the Read-Only Symbol Directives, and
 
#include "grid\gxres.rc"
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.
3. 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.
4. Register and Compile.
a. Add a call to CMyGridWnd::RegisterClass in InitInstance() and include CMyGridWnd to the stdafx.h file.
 
BOOL CogregdllApp::InitInstance()
{
GXInit();
CMyGridWnd::RegisterClass();
CWinApp::InitInstance();
 
return TRUE;
}
b. Compile as usual.
5. Use.
a. To use CMyGridWnd outside MFC, just call LoadLibrary("ogregdll.dll") from your application.
You can instantiate a grid by calling:
 
CreateWindow("CMyGridWnd", ...)
with your usual parameters, or by using it in a dialog template.