Rogue Wave Knowledge Base
Search:    
Browse by category:
Knowledgebase | Glossary | Ask a Question |

Objective Grid: CGXWndWrapper and printing

Article ID: 81
Last updated: 22 Jun, 2018
Revision: 3
print  Print
share  Share
Views: 3939
Posted: 12 Jan, 2001
by Meltreger B.
Updated: 22 Jun, 2018
by Meltreger B.

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
if (pMsg->message == WM_VSCROLL || pMsg->message == WM_HSCROLL)
{

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)));
// ASSERTION-> Invalid Device Context ->END

ASSERT(nRow <= Grid()->GetRowCount() && nCol <= Grid()->GetColCount());
// ASSERTION-> Cell coordinates out of range ->END

ASSERT_VALID(pDC);

CMyGrid* pGrid = (CMyGrid*) m_pWnd;

// Erase Frame around the cell
DrawFrame(pDC, rect, style);
rect = GetCellRect(nRow, nCol, &rect, &style);
CRect rectDisplay = CRect(0, 0, rect.Width(), rect.Height());

// The grid below only prints to CRect(0,0,x,y) -
// Therefore I have to change the mapping mode so that
// rectDisplay maps to (0,0,x,y)
pDC->SaveDC();
CPoint pt = pDC->OffsetWindowOrg(-rect.left, -rect.top);
pDC->IntersectClipRect(rectDisplay);
pGrid->SetGridRect(TRUE, rectDisplay);
pGrid->DrawDirectToDC(pDC);
pGrid->SetGridRect(FALSE, rectDisplay);

// Reset device context
pDC->RestoreDC(-1);

// child Controls: spin-buttons, hotspot, combobox btn, ...
// CGXControl::Draw(pDC, rect, nRow, nCol, style, pStandardStyle);

}

// Unreferenced:
pStandardStyle;

}

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();
pGridWnd->SetRowCount(32);
pGridWnd->SetColCount(16);

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))
);


 

This article was:   Helpful | Not helpful Report an issue


Prev     Next
Objective Grid: Changing the data of a grid without a view       Objective Grid: Dragging items from a listbox to the grid

Others in this category
b How to avoid cursor blinking on a grid view
b GX_IDS_CTRL_TEXTFIT ComboBox wrong item selection if Formula Engine enabled
b Hide first column in CGXMRTGrid
b Scroll with frozen columns
b Objective Grid: The current DateTime control only displays the Date
b How to implement Cut method with a Virtual Grid
b Max and Min Date for Datetime Control in Grid for .Net
b Numeric Format in Grid for .Net
b Tab to Grid for .Net Control on a Form
b Loading Performance in Grid for .Net
b Objective Grid: Synchronizing cells in different views
b Objective Grid: Transferring data between a grid and a document
b Objective Grid: Floating, merge, and covered cells
b Objective Grid: Restricting printing to one page
b Objective Grid: Enabling listbox mode
b Objective Grid: Forcing [Tab] and [Return] keys to move to the next valid cell
b Objective Grid: Sorting columns and rows
b Objective Grid: Using covered cells as a recurring pattern
b Objective Grid: Limiting the drawing area of the grid
b Objective Grid: What is the best way to remove all rows for the entire grid?
b Objective Grid: Support for far-eastern languages
b Objective Grid: Preventing current cell deactivation during user selections
b Objective Grid: Cell edit notification
b Objective Grid: Drawing a bitmap and text into a grid cell with an edit control
b Objective Grid: Setting cells to be read-only.
b Objective Grid: Quicken-like grid
b Objective Grid: How to change the face color of a push button.
b Objective Grid: Excel compatibility
b Objective Grid: Optimally resizing columns when clicked
b Objective Grid: How can I specify the number of rows and columns in the grid?
b Objective Grid: Modifying status bar text during lengthy grid operations
b Objective Grid: Discarding the selection when the user changes the current cell
b Objective Grid: Assertion in COleDropTarget::Register()
b Locale settings in Objective Grid
b Objective Grid: Enabling row dragging
b Cell Attributes: Determining the attributes of a cell
b Objective Grid: Printing without grid lines
b Objective Grid: Printing a range of rows
b I have a grid with a CString
b Objective Grid: Restricting hint information when a view attached to a document is updated
b Objective Grid: Using a CGXTabWnd in a static splitter window
b Objective Grid: User Attributes
b Objective Grid: Determining the database field displayed in a column
b Objective Grid: Changing the default printer settings
b Objective Grid: Row height/column width not stored correctly after changing the standard font
b Objective Grid: Numeric entry in an edit cell
b Objective Grid: Displaying bitmaps
b Objective Grid: Disabling column resizing
b Objective Grid: How can I get the value for a given cell.
b Objective Grid: Disabling scrolling for the grid
b Objective Grid: Navigation notification
b Objective Grid: Changing cell styles when using a browser grid
b Objective Grid: Decreasing update flicker
b Objective Grid: Determining scroll bar visibility
b Objective Grid: What is the fastest way to clear cell contents out of the grid?
b Objective Grid: Increasing the thickness of the line separating columns
b Objective Grid: Disabling cell-range selection
b Objective Grid: Clearing the selection when the user moves the active cell
b Objective Grid: Removing borders from cells
b Objective Grid: Applying borders to cells
b Objective Grid: Dotted grid lines
b Objective Grid: Value-dependent cell outlining
b Objective Grid: Displaying double precision values in ODBC and ADO grids
b Objective Grid: Turning off header numbers and letters
b Objective Grid: Formatting a column of cells
b Objective Grid: Problem underlining blanks when printing
b Objective Grid: Sorting a combobox cell
b Objective Grid: Making a covered cell span an entire row
b Objective Grid: Resizing columns and rows without visible headers
b Objective Grid: Subclassing CGXTabBeam when the associated CGXTabWnd is embedded in a dialog
b Objective Grid: Having more than 32 items in CGXCheckListComboBox
b Objective Grid: Copying/Pasting cell formatting to/from Excel
b Objective Grid: Disabling message processing and user cancel operations
b Objective Grid: Always drawing the pushbutton in a combobox
b Objective Grid: Conditionally filling a combobox based on the contents of another cell
b Objective Grid: How do I display a grid with a Record Beam in a Form View?
b Objective Grid: Cell delete notification
b Objective Grid: Sending notifications to the parent dialog
b Objective Grid: Determining if the grid has focus
b Objective Grid: Embedding a grid in a CFormView
b Objective Grid: Drawing text in a combobox cell
b Objective Grid: Using the grid as a registered dialog control
b Objective Grid: Floating cells do not grow over the last frozen column
b Objective Grid: CGXComboBoxWnd draws over adjacent cells
b Objective Grid: Enabling listbox mode
b Objective Grid: OnEndEdit() called even when no editing has occurred
b Objective Grid: Creating a CGXMaskControl-derived control
b Objective Grid: Displaying international dates
b Objective Grid: Making changes to read-only cells
b Objective Grid: Determining the new row or column ID after a user drag
b Objective Grid: Implementing a virtual grid
b Objective Grid: Modifying the behavior of the tab key for a grid in a dialog
b Objective Grid: Adding a toolbar to a MDI child window with a CGXGridView
b Cell Attributes: Changing a read-only cell to be writable
b Objective Grid: Toggling a checkbox
b Objective Grid: Changing the font of header cells
b Objective Grid: Preventing user cancellation for CGXLongOperation
b Objective Grid: How can I insert and remove rows and columns at runtime?
b Objective Grid: Adding empty rows after the last record
b Objective Grid: Radio button/combobox click notification
b Objective Grid: Disabling colors for printing
b Objective Grid: Changing the mouse cursor when moving over cells
b Objective Grid: Resizing the client area of a grid to fit the width and height of the grid
b Objective Grid: International date style settings ignored
b Objective Grid: Bug in CGXUserAtttribute::IsEqual()
b Objective Grid: Writing a grid to a text file
b Objective Grid: Can I change the query for a grid at runtime?
b Objective Grid: Record set loading
b Objective Grid: Grid on a tab control vanishes
b Objective Grid: How can I turn off the message Automatic linking with .... at compilation time?
b Objective Grid: Determining the original row (or column) after a drag
b Objective Grid: Changing the appearance of a cell
b Objective Grid: Rows not resizing correctly
b Objective Grid: How can I create a 32-Bit extension DLL that uses Objective Grid?
b Objective Grid: How to fill a grid for best performance
b Objective Grid: Base styles
b Objective Grid: Setting colors for individual cells using palettes
b Objective Grid: Displaying default values in the last row
b Can I spread a title across two columns?
b Objective Grid: Converting an OLE move to a copy
b Objective Grid: Adding application-specific data
b Objective Grid: Copying parameter objects
b Objective Grid: Implementing a spin-list control
b Objective Grid: Placing images in a column header
b Objective Grid: Adding What's this? context-sensitive help to grid elements
b Objective Grid: Initializing an extension DLL
b How can I validate cell contents before they are stored in the grid?
b Objective Grid: Custom cell types
b Objective Grid: Displaying icons in cells
b Objective Grid: Printing with a zoom level
b Objective Grid: Frequent Automatic Linking with gx###.lib messages
b Objective Grid: How to keep the grid in synch with its recordset?
b Objective Grid: Tabbed combobox speed
b Objective Grid: Creating a CGXFont from a CFont
b Objective Grid: Problem with constructors being called before GXInit()
b Objective Grid: MFC integration
b Objective Grid: Handling OnKillFocus()
b Objective Grid: Retrieving the current text from a combobox
b Objective Grid: Pasting RichText into a grid
b Objective Grid: Pasting text without changing format
b Objective Grid: Outlining the current row with a border
b Objective Grid: Problems with the expression GetUserAttribute(IDS_MYATTRIBUTE)
b Objective Grid: Disable row and column moving
b Objective Grid: Setting the default size for a row or column
b Objective Grid: Grid types
b How to make the grid have no current cell
b Objective Grid: Using a grid in applications written in plain C
b Objective Grid: Text alignment changes during cell editing
b Objective Grid: Problems using the grid layout file created by Designer
b Objective Grid: Drawing rotated text in cells
b Objective Grid: Style change notifications
b Objective Grid: Determining the last filled row in a column
b Objective Grid: Deriving a grid class
b Objective Grid: Changing grid margins
b Objective Grid: Deactivating the current cell
b Objective Grid: Changing the outline frame for the current cell
b Objective Grid: Hiding headers
b Objective Grid: Setting the active cell characteristics
b Objective Grid: Preventing cell selection with the mouse
b Objective Grid: Hiding vertical header lines
b Cell Attributes: Determining the attributes of a cell
b Objective Grid: Using CGXPrintDevice with scroll views
b Objective Grid: Positioning the current cell
b Objective Grid: Preventing text display at the bottom of the screen
b Objective Grid: Handling combobox notifications
b Objective Grid: Disabling cells
b Objective Grid: How do I display a grid with a Record Beam in a dialog?
b Objective Grid: Using a tab control in a dialog
b Objective Grid: Moving the current cell to the first editable column in the selected row
b Objective Grid: Handling combobox notifications
b Objective Grid: Preventing the print setup dialog from appearing
b Objective Grid: Header cells not inverted when selected
b Objective Grid: Transactions with ODBC grids
b Objective Grid: Filling a combobox
b Objective Grid: Deferred binding to a recordset
b Objective Grid: Requerying the recordset does not reflect changes in the row count
b Objective Grid: Duplicate control IDs
b Objective Grid: How can I change the query for a grid at runtime?
b Objective Grid: Title bar flashing
b Objective Grid: Incremental column scrolling
b Objective Grid: Initiating a message box when a change occurs
b Missing combobox buttons or other resources
b Objective Grid: Intercepting data to and from a database
b Objective Grid: Specifying cell formats
b Objective Grid: Reserved ranges for resource IDs
b Objective Grid: Displaying a message box when closing a grid dialog
b Objective Grid: An exception-safe way to change read-only cells
b Objective Grid: Validating a grid embedded in a dialog
b Objective Grid: Implementing an owner-draw combobox
b Objective Grid: Determining combobox dropdown list items at runtime
b Objective Grid: Combobox type-to functionality
b Objective Grid: Rich edit cells do not change font with format style changes
b Objective Grid: Preventing headers from being hidden by splitter panes
b Objective Grid: Changing the label of column headers
b Objective Grid: Converting date formats
b Objective Grid: Persisting custom base styles
b Objective Grid Pro/Excel Read-Write: Size of Excel file changes
b Objective Grid: The current cell is not refreshed when navigating the grid
b Objective Grid: Turning off grid lines for specific columns
b Objective Grid: Caching a virtual grid
b Objective Grid: Accessing style objects
b Objective Grid: How should I fill the grid with values?
b Objective Grid: Add floating cell capability to cell types other than edit cells
b Objective Grid: Inserting and removing worksheets at runtime
b Objective Grid: ODBCGrid fails to display SQL Server dynamic cursors.
b Objective Grid: Displaying a choice in a combobox and storing the index in the cell
b Using Objective Grid with C++/CLI
b Highlight the background of the current cell
b Objective Grid: Specifying custom page breaks
b Objective Grid: Tooltip text not updated
b Objective Grid: How can I change cell settings (e.g. colors) for individual cells?
b Objective Grid: Removing borders and grid lines from cells
b Objective Grid: Large number of hidden rows
b Objective Grid: Turning off row headers
b Objective Grid: Modifying the horizontal space between the grid line and the cell text
b Objective Grid: Can CGXRecordInfoWnd and CGXRecordInfoSplitterWnd be used with other grids besides the browser grids?
b Objective Grid and multiple threads
b Objective Grid: Excel compatibility
b Objective Grid: List box mode
b Objective Grid: Positioning the grid when printing
b Objective Grid: Enabling scrollbars
b Objective Grid: Cell modify notifications
b Objective Grid: Resizing all rows to the same height
b Objective Grid: Outlining the current rows or columns with special formatting
b Objective Grid: Printing a grid embedded in a dialog or form view
b Objective Grid: Inserting unbound columns
b Objective Grid: Appending a record to the data source
b Objective Grid: Modifying the value of a cell in a formula
b Objective Grid: Adding custom worksheet functions
b Objective Grid: Pasting into static cells
b Objective Grid: Non-OLE drag and drop
b Objective Grid: Column header text too large when zoomed.
b Objective Grid: IME window flicker
b Objective Grid: Filling a large grid with a formula
b Objective Grid: Updating formula cells that reference cells changed programmatically
b Objective Grid: Changing header labels
b Objective Grid: Storing text as a string in cells with formula support
b Objective Grid: How can I change the default settings for all cells
b Objective Grid: Changing color properties of a cell
b Objective Grid: Hiding or showing tabs
b Objective Grid: Metafiles generated by Objective Grid cannot be read by other applications
b Objective Grid: Adding user properties
b Objective Grid: Editing the record in the data source
b Cannot unload DLLs or ActiveXs using OG
b Objective Grid: Linking statically Objective Grid to an extension library
b Objective Grid: Floating cells with rotated text do not grow vertically
b Objective Grid: Printing worksheets from CGXTabWnd
b Objective Grid: First character entered in a cell is not visible
b Objective Grid: Decreasing flicker for a grid in a CView
b Objective Grid: Windows Explorer-like headers
b Objective Grid: Changing the calendar months and days to a specific language
b Objective Grid: Preventing database record writing when a row is updated
b Objective Grid: Determining the columns and rows of a selection
b Sorting problem with CGXCurrencyEdit and decimal separators
b Objective Grid: Modifying the horizontal space between the grid line and the cell text
b Objective Grid: Enabling right mouse button dragging
b Objective Grid: Changing cell types
b Objective Grid: Default date for custom date formats
b Objective Grid: Sorting a CGXBrowserGrid, CGXADOGrid or CGXODBCGrid
b Objective Grid: Cells do not resize properly with SetValueRange()
b Objective Grid: Date stored in grid does not match CGXDateTime custom format
b Objective Grid Pro/Excel Read-Write: ExDlgMulti sample
b Objective Grid: Static edit cells
b Objective Grid: Problems with calling SetCurrentCell() from OnAddedNewRecord().
b Grid colors display as black when loaded into Excel
b Customizing a record view to put the Append Row on top
b Objective Grid: Get current value of a cell
b Customizing numeric format
b Objective Grid: Merging rows with hidden rows in between
b Objective Grid: Dynamically adding or deleting views
b Objective Grid: Dragging only the selection portion of a cell to another
b Objective Grid: Validating data pasted from the clipboard
b Objective Grid: Preventing validation when the hits cancel
b Objective Grid: Preventing headers from being drawn depressed
b Can I use formulas in a browser grid?
b Objective Grid: Using the translated resource files
b Objective Grid: Displaying rows with optimal height
b Objective Grid: Setting the caret position in an edit cell
b Objective Grid: Scrollbars in tab windows
b Objective Grid: Accelerators not working in conjunction with Objective Edit
b Objective Grid: Preventing zeros from being stripped from numeric entries
b Objective Grid: Changing the record string
b Objective Grid: Programmatically selecting a single range of cells
b Objective Grid: Unselecting rows with the mouse
b Objective Grid: Displaying selected cells with a user-defined text and background color
b Objective Grid: Preventing the user from selecting multiple rows
b Objective Grid: Programmatically selecting a row after a selection
b Objective Grid: Disabling the extension of selection when using SetSpecialMode()
b Objective Grid: Displaying a dialog or popup-menu when the user clicks the right mouse button
b Objective Grid: Clipboard formats
b Objective Grid: Giving the right mouse button the same functionality as the left mouse button
b Objective Grid: Disabling cell-range selection
b Objective Grid: Using a drop down list as a header
b Objective Grid: Turning off automatic linking
b Objective Grid: Determining the rows and columns of a selection
b Objective Grid: Setting column widths based on string size
b Objective Grid: Preventing hidden columns from becoming visible through double-clicks
b Objective Grid: Printing a grid with a page header
b Objective Grid: Forcing the last column to fill remainder of the grid window
b Objective Grid: How do I place a record-info beam in the lower pane of a static splitter window?
b Objective Grid: Support for Number Formats in ODBC grids
b Objective Grid: SetStyleRange() and CGXRecordWnd
b Objective Grid: Batching screen updates
b Objective Grid: Maintaining the cursor position as a cell loses and regains focus
b Objective Grid: Using a grid in a dialog
b How can I read data from a text file in tab-delimited format?
b Objective Grid: Grid lines not visible during print preview
b Objective Grid: WYSIWYG mode
b Objective Grid: Changing the date format when printing headers and footers
b Objective Grid: Changing the data of a grid without a view
b Objective Grid: Dragging items from a listbox to the grid
b Objective Grid: International character fonts
b Objective Grid: Two digit years
b Objective Grid: Customizing headers and footers for printing
b Objective Grid: How can I programmatically change the record number that is displayed in the record field of the CGXRecordInfoWnd?
b Objective Grid: Printing a grid embedded in a CFormView
b Objective Grid: Controlling cell focus
b Objective Grid: Displaying a messagebox during validation
b Objective Grid: Making column widths relative to the size of the grid
b Objective Grid: Handling the [Enter] key in a grid embedded in a dialog
b Objective Grid: Displaying the append row at the top of a browser grid instead of the bottom