<< Return to Main Index

< Return to Class Index

CGXGridParam::CreateFromResource

static CGXGridParam* CreateFromResource(LPCTSTR lpszResourceName);

static CGXGridParam* CreateFromResource(UINT nId);

lpszResourceName

Points to the null-terminated string that contains the name of the binary resource.

nId

Specifies the resource id number of the binary resource.

Return Value

A pointer to the allocated object; NULL if an object of the given runtime class could not be found in the file.

Remarks

The CGXGridParam::CreateFromFile and CGXGridParam::CreateFromResource allow you load the layout into the grid either from a file or from a binary resource.

Loading the grid layout from binary resource has the benefit that you don’t have to ship external files with your application. You can link the layout into your .EXE file and not worry about correct installation of files. Another advantage is that the end user cannot accidentally modify or destroy the layout file.

Here are the steps to enable your application to load the grid layout from a binary resource.

1) Loading the layout into your grid view or window

First, you have to create a layout file. This can be done with Objective Grid Designer or programmatically by calling CGXGridParam::WriteToFile in your application.

The layout file should be copied into the RES directory in your project’s directory. Next, you have to manually edit the .RC2 file in your application and insert a reference to your layout file.

Example:

//
// 1STGRID.RC2 - resources Microsoft Visual C++ does not edit directly
//

#ifdef APSTUDIO_INVOKED
   #error this file is not editable by Microsoft Visual C++
#endif //APSTUDIO_INVOKED


///////////////////////////////////////////////////////////////////
// Add manually edited resources here...

LAYOUT1                 GXLAYOUT DISCARDABLE    "RES\\Layout1.OGL"

Note: Binary resources must have the resource type “GXLAYOUT”. Otherwise, CreateFromResource will not find the resource in your resource file.

The OGLGrid project demonstrates the various ways to initialize the grid from the layout file.

Example:

void C1stGridView::OnInitialUpdate()
{
   BOOL bFirstView = FALSE;

   if (GetDocument()->m_pParam == NULL)
   {
      bFirstView = TRUE;      
         // bFirstView = TRUE indicates that this is
         // the first view connected to the document
         // and therefore the data need to be initialized.

      // construct parameter object
      // CGXGridParam* pParam = CGXGridParam::CreateFromFile(_T("RES\\LAYOUT1.OGL"));
      // CGXGridParam* pParam = CGXGridParam::CreateFromResource(_T("LAYOUT1"));
      CGXGridParam* pParam = CGXGridParam::CreateFromResource(IDR_GXLAYOUT1);

      // if load failed, create empty object
      if (pParam == NULL)
         pParam = new CGXGridParam;

      GetDocument()->m_pParam = pParam;
   }
   // else
      // bFirstView = FALSE indicates that this is
      // only another view connected to the document
      // No data need to be initialized. They are all
      // available in the document already.


   // pass the pointer to the grid view
   SetParam(GetDocument()->m_pParam, FALSE);
                              //     ^-- indicates that document is
                              // responsible for deleting the object.

   // standard initialization, will create other objects
   // such as data object, stylesmap object, ...

   CGXGridView::OnInitialUpdate();

   // Just to be sure that everything is redrawn
   Invalidate();

   // Enable Objective Grid internal update-hint mechanism

   // You should put this line as last command into OnInitialUpdate,
   // because as long as EnableHints is not called, the modified flag
   // of the document will not be changed.

   EnableHints();
}

2) Loading the layout into grid windows embedded in a dialog

If you want to embed grid windows into your dialogs without writing a line of code, take a look at the implementation of the CMyGridWnd class in the file mywnd.cpp of the OGLGRID sample project.

With CMyGridWnd, all you have to do is place a custom control in your dialog, specify CMyGridWnd as class name and enter the name of the binary resource (e.g., LAYOUT1) as caption text. CMyGridWnd will then automatically initialize itself from the binary resource.

See Also

CGXGridParam::CreateFromFile CGXGridCore::SetParam CGXGridParam::WriteToFile

CGXGridParam

Class Overview | Class Members