| | | | Browse by category |
Problem
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.
Cause
Action
Yes, that's possible. You can implement a User DLL 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) DECLARE_MESSAGE_MAP() |
|||
};
//////////////////////////////////////////////////////////////////// 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); return 0; |
|||
}
// Now, you can create instances by embedding CsampleGridWnd // Example: |
|||
CDialog::OnInitDialog();
// IDC_GRIDWND is a static frame in the dialog template if (pGridFrame) |
|||
// Retrieve the size of the frame // and convert the coordinates to // use the dialog coordinates (from // screen coordinates). 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; |
|||
} |