Is it possible to integrate Objective Grid into applications written in plain C? That means the grid has to do all its initialization itself because we cannot call any C++ methods.
Yes, that's possible. You can implement a User Dll with and derive a class from CGXGridWnd and put the initialization code into the OnCreate message handler. By registering the grid window class through the DECLARE_REGISTER() / IMPLEMENT_REGISTER() macros, you can use it just like any other MS Windows control with the MS SDK CreateWindow method.
// Declaration for CSampleGridWnd class
class CSampleGridWnd : public CGXGridWnd
{
DECLARE_REGISTER()
public:
// Generated message map functions
//{{AFX_MSG(CSample4GridWnd)
afx_msg int OnCreate(LPCREATESTRUCT lpCreateStruct);
//}}AFX_MSG
DECLARE_MESSAGE_MAP()
};
////////////////////////////////////////////////////////////////////
// Implemenation of CSampleGridWnd class
IMPLEMENT_REGISTER(CSampleGridWnd, CS_DBLCLKS|CS_GLOBALCLASS, 0, 0, 0);
BEGIN_MESSAGE_MAP(CSampleGridWnd, CGXGridWnd)
//{{AFX_MSG_MAP(CSampleGridWnd)
ON_WM_CREATE()
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
int CSampleGridWnd::OnCreate(LPCREATESTRUCT lpCreateStruct)
{
if (CGXGridWnd::OnCreate(lpCreateStruct) == -1)
return -1;
Initialize();
SetRowCount(256);
SetColCount(52);
return 0;
}
// Now, you can create instances by embedding CSampleGridWnd
// as user control with the class name "CSampleGridWnd" in
// your dialog template or by creating it with SDK method
// CreateWindow.
// Example:
BOOL CMySampleDialog::OnInitDialog()
{
CDialog::OnInitDialog();
// IDC_GRIDWND is a static frame in the dialog template
CWnd* pGridFrame = GetDlgItem(IDC_GRIDWND);
if (pGridFrame)
{
// Retrive the size of the frame and convert the co-ordinated to
// use the Dialog co-ordinates (from screen co-ordinates).
CRect rect;
pGridFrame->GetWindowRect( &rect );
ScreenToClient(&rect);
DWORD dwFlags =
WS_TABSTOP | WS_BORDER | WS_VSCROLL | WS_HSCROLL | WS_VISIBLE;
#if _MFC_VER >= 0x0400 && _GX_VER >= 0x0110
// draw grid with sunken borders
dwFlags |= WS_EX_CLIENTEDGE;
#endif
// Create the window with SDK method
::CreateWindow(_T("CSample4GridWnd"),
NULL,
dwFlags | WS_CHILD,
rect.left,
rect.top,
rect.Width(),
rect.Height(),
GetSafeHwnd(),
NULL,
AfxGetInstanceHandle(),
NULL);
return FALSE;
}
return TRUE; // return TRUE unless you set the focus to a control
}