Using Objective Grid in a Dialog Box
This section discusses integrating Objective Grid into a dialog box.
Objective Grid vs. ActiveX Controls
Objective Grid is a custom grid component that is MFC based and does not implement ActiveX control interfaces. This does not allow the grid to be directly displayed in the dialog editor as ActiveX controls can be. (With ActiveX controls you will choose Insert Component and point to the control and Microsoft Visual Studio would generate the wrapper files as well as ensure that the ActiveX appeared in the dialog editor.)
The grid object is typically created and displayed using the custom control placeholder in the dialog editor. You can create a window on any dialog.
The next section discusses the steps that are required to accomplish this.
Using Objective Grid in a Dialog Template
The following steps are necessary to embed a grid in a dialog.
1. Create a new class with the View | Add Class menu. Use “CWnd” as the class type.
2. Next, using a text editor, change the derivation in your window class, in both the .h and .cpp files. All references to CWnd should be replaced with CGXGridWnd. A simple find and replace operation will work here.
3. Create or open your dialog template. Choose the user control icon, drag it into the dialog and open its property page. Enter GXWND as class name into the class box. Please note that this is a registered WNDCLASS and not the C++ class name. CGXGridWnd will not work here.
4. Specify the style bits for the grid:
*0x50b10000 to display both scrollbars and a border
*0x50810000 to display no scrollbars but a border
For other style bits see the definitions for Windows style bits in your windows.h header file.
5. If you created a new dialog, you should now create your dialog class with ClassWizard.
6. Embed an object of your derived grid class in the dialog.
// dergrdlg.h : header file
// CDerGridDialog dialog
#include “dergrid.h”
class CDerGridDialog : public CDialog
// Construction
CDerGridDialog(CWnd* pParent = NULL);// standard constructor
// Dialog Data
// NOTE: the ClassWizard will add data members here
// You do not have to derive from CGXGridWnd unless you want
// to handle some events, etc. You can also declare m_wndGrid
// to be an instance of CGXGridWnd if you do not wish to
// handle any of the grid virtuals.
CDerivedGridWnd m_wndGrid;
7. Add the OnInitDialog member to the dialog class. In OnInitDialog, you can initialize the grid:
// CDerGridDialog message handlers
BOOL CDerGridDialog::OnInitDialog()
// Please refer to the MFC documentation on
// SubclassDlgItem for information on this call. This
// makes sure that our C++ grid
// window class subclasses the window that is created
// with the User Control.
m_wndGrid.SubclassDlgItem(IDC_GRIDSAMPLE, this);
// Initialize the grid. For CWnd based grids this call is
// essential. For view based grids this initialization is
// done in OnInitialUpdate.
return TRUE; // return TRUE unless you set the
// focus to a control
// EXCEPTION: OCX Property Pages should return FALSE
NOTE >> If you want to use the grid in a formview, you should override OnInitialUpdate instead of OnInitDialog. Otherwise, the steps are identical.
8. Now, you can compile the class. The grid should display when you bring up the dialog. If the grid does not show up as expected, please refer to the next section before contacting Perforce Support Services.
If the grid does not show up when you compile the application:
1. Check whether you have called GXInit() in your application’s InitInstance. GXInit() is required in all applications that make use of the grid library.
2. Check whether you have included the grid resources if you are linking statically with the grid. For more information on this, see “Using the Objective Grid Static Libraries”.
3. If you have OLE controls on your dialog, check whether you have called AfxEnableControlContainer().
4. Verify that the class name in the user control properties box is GXWND. This refers to the registered WNDCLASS name and not to the C++ class name.