| | | | Browse by category |
Problem
CGXWndWrapper and printing
Cause
By default the CGXWndWrapper class does not support printing. This is because CGXWndWrapper only knows the CWnd interface and there is no generic way to force a window to render its contents to a device context.
Action
However, it is possible to add support for printing a window if this window provides a method for rendering its content to a device context. The following example shows how to subclass CGXWndWrapper and add support for printing CGXGridWnd cells.
Example:
class CMyGridWndWrapper: public CGXWndWrapper { public: |
|||
CMyGridWndWrapper(CGXGridCore* pGrid, CWnd* pWnd, BOOL bNeedDestroy, BOOL bCanActivate, BOOL bInvertBorders);
CMyGridWndWrapper(CGXGridCore* pGrid); virtual void Draw(CDC* pDC, CRect rect, ROWCOL nRow, ROWCOL nCol, const CGXStyle& style, const CGXStyle* pStandardStyle); virtual void OnNotifyMsg(MSG* pMsg); |
|||
};
class CmyGrid: public CGXGridWnd |
|||
friend class CMyGridWndWrapper; | |||
};
CmyGridWndWrapper::CMyGridWndWrapper(CGXGridCore* pGrid, CWnd* pWnd, BOOL bNeedDestroy, BOOL bCanActivate, BOOL bInvertBorders) |
|||
: CGXWndWrapper(pGrid, pWnd, bNeedDestroy, bCanActivate, bInvertBorders) | |||
{ } CMyGridWndWrapper::CMyGridWndWrapper(CGXGridCore* pGrid) |
|||
: CGXWndWrapper(pGrid) | |||
{ } void CMyGridWndWrapper::OnNotifyMsg(MSG* pMsg) |
|||
// Called from CGXGridCore::OnVScroll, OnHScroll pMsg; // deactivate the current cell when the user scrolls |
|||
SetActive(FALSE); Refresh(); |
|||
} | |||
}
void CMyGridWndWrapper::Draw(CDC* pDC, CRect rect, ROWCOL nRow, ROWCOL nCol, const CGXStyle& style, const CGXStyle* pStandardStyle) |
|||
// Only let the base class draw the active current cell if (m_pWnd == NULL || !m_pWnd->IsKindOf(RUNTIME_CLASS(CGXGridWnd)) || !Grid()->IsPrinting() && nRow == m_nRow && nCol == m_nCol && m_bIsActive) { |
|||
CGXWndWrapper::Draw(pDC, rect, nRow, nCol, style, pStandardStyle); | |||
} else // render a CGXGridWnd object to the device context { |
|||
ASSERT(::IsWindow(m_pWnd->m_hWnd)); // ASSERTION-> Did you forget to call Create? ->END ASSERT(pDC != NULL && pDC->IsKindOf(RUNTIME_CLASS(CDC))); ASSERT(nRow <= Grid()->GetRowCount() && nCol <= Grid()->GetColCount()); ASSERT_VALID(pDC); CMyGrid* pGrid = (CMyGrid*) m_pWnd; // Erase Frame around the cell // The grid below only prints to CRect(0,0,x,y) - // Reset device context // child Controls: spin-buttons, hotspot, combobox btn, ... |
|||
}
// Unreferenced: |
|||
} |
In OnInitialUpdate(), add:
CGXGridWnd* pGridWnd = new CGXGridWnd();
VERIFY(pGridWnd->Create(WS_BORDER | WS_VSCROLL | WS_HSCROLL | WS_VISIBLE, CRect(0,0,1,1), this, IDS_CTRL_GRIDCHILD)); pGridWnd->Initialize(); RegisterControl(IDS_CTRL_GRIDCHILD, |
|||
new CMyGridWndWrapper(this, | |||
pGridWnd, TRUE, // must delete TRUE, // can activate FALSE // no invert borders |
|||
)); | |||
SetCoveredCellsRowCol(5, 1, 10, 5); SetStyleRange(CGXRange(5,1), |
|||
CGXStyle() | |||
.SetControl(IDS_CTRL_GRIDCHILD) .SetDraw3dFrame(gxFrameInset) //.SetBorders(gxBorderAll, CGXPen().SetWidth(2)) |
|||
); |