Grid derived from CWnd (2)

 Download Source Code and Example


This is MFC version of grid I originally wrote in OWL. All about grid is in PageWnd.h (cpp) file (which does not mean it is too long). CPageWnd provides public members for getting/setting cell text, color, alignment and font, column width, row height and similar. It is easy to derive CPageWnd and add additional functionality. This code is build with Visual C++ 5.0 (it should work with 4.x version). To integrate in existing project just insert PageWnd.cpp file in your project. How to use CPageWnd find is shown in TestPageView.cpp. If you are interested for OWL version of grid, e-mail me.

Last updated: 25 July 1998


  • Grid Control in C?

    Posted by Legacy on 09/24/2003 12:00am

    Originally posted by: Mark Richardson

    Is it possible to implement a grid control in plain C rather than C++ or MFC and if so how is it done?

  • Suggests and paint errors

    Posted by Legacy on 06/02/2001 12:00am

    Originally posted by: Leandro Gustavo Biss Becker


    You class is nice but if you create GDIs object to each cell and hold all of them created, if you have many and many
    cells the systems resources will go down because the GDI resources (pens, fonts, brushes, etc) are limited !
    You can hold to each cell only the infomation about the GDI objects like font typeface, size, color etc, brush color, etc and create them when you will paint the cell and after the cell paint process, free then. I know that this process is a little bit slower but this is the better solution to your case.

    The paint errors are not logical errors. The problem are when you use SelectObject CDC function, you must hold the returned object pointer and call SelectObject again with the held object before release the dc. If you don't do this, even if you destroy the objects before you program exits (I see that you are doing this!) the Windows will not free the object because it was selected in a dc but not deselected !!

    Best Regards

    Leandro Gustavo Biss Becker
    LIT - Laboratory of Information and Telecomunications
    CEFET-PR Brazil

  • FlexGrid or Grid Control

    Posted by Legacy on 01/08/2001 12:00am

    Originally posted by: Roberto A. Vidal

    Do you know how use FlexGrid or Grid Control step by step in a dialog box.

    or any book you suggest where I can find it.


  • Error & Fix

    Posted by Legacy on 03/12/2000 12:00am

    Originally posted by: Hassanov

    1. Mark cell A1 as the active cell
    2. Scroll to right (by mouse) to hide current active cell
    3. Click on any cell (let's say B2)
    4. Notice that the old col/row markers are not cleared (i.e., Still shown in BOLD).

    1. In function MarkActiveCell() do:
    MarkHeader(false); //This is new place of this call
    if(m_pScrollData->XPos < m_colEditEx && m_pScrollData >YPos < m_rowEditEx)
    CPen inactivePen(PS_SOLID, 2, GetCellColor(m_rowEditEx, m_colEditEx));
    CRect r(m_EditRect.left + 2, + 2, m_EditRect.right, m_EditRect.bottom);
    //MarkHeader(false); // This is old place of this call

    2. Retype function MarkHeader() as follows :
    void CPageWnd::MarkHeader(bool mark)
    CRect rowRect(0,, m_width[0], m_EditRect.bottom);
    CRect colRect(m_EditRect.left, 0, m_EditRect.right, m_height[0]);

    CClientDC dc(this);

    SetCellFont(m_rowEditEx, 0, *m_pDefFont);
    SetCellFont(0, m_colEditEx, *m_pDefFont);

    SetCellFont(m_rowEdit, 0, *m_pDefFontBold);
    SetCellFont(0, m_colEdit, *m_pDefFontBold);

    if(!mark) {
    if(m_rowEditEx > m_pScrollData->YPos && m_rowEditEx < m_pScrollData->YPos + m_pScrollData->YPage)
    dc.DrawEdge(rowRect, BDR_RAISEDINNER, BF_RECT | BF_MIDDLE);

    CellEntry(dc, m_rowEditEx, 0, rowRect);

    if(m_colEditEx > m_pScrollData->XPos && m_colEditEx < m_pScrollData->XPos + m_pScrollData->XPage)
    dc.DrawEdge(colRect, BDR_RAISEDINNER, BF_RECT | BF_MIDDLE);

    CellEntry(dc, 0, m_colEditEx, colRect);
    else {
    dc.DrawEdge(rowRect, EDGE_RAISED , BF_RECT | BF_MIDDLE); //BDR_RAISED
    CellEntry(dc, m_rowEdit, 0, rowRect);

    dc.DrawEdge(colRect, EDGE_RAISED, BF_RECT | BF_MIDDLE); //BDR_RAISED
    CellEntry(dc, 0, m_colEdit, colRect);

  • Save '\res\TestPage.rc2'...

    Posted by Legacy on 11/16/1999 12:00am

    Originally posted by: Sok Woo, Lim

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

    #error this file is not editable by Microsoft Visual C++

    // Add manually edited resources here...


  • Error when compile TestPage

    Posted by Legacy on 10/04/1998 12:00am

    Originally posted by: Vatiutov Victor

    When I compile TestPage appears this message:

    TestPage\TestPage.rc(354) : fatal error RC1015: cannot open include file 'res\\TestPage.rc2'.

Leave a Comment
  • Your email address will not be published. All fields are required.

Top White Papers and Webcasts

  • Live Event Date: February 25, 2015 @ 2:00 p.m. ET / 11:00 a.m. PT Secure Shell (SSH) keys provide unmitigated access for privileged users and applications. However, managing and securing these critical privileged credentials poses a real challenge for organizations, putting sensitive data at risk. In fact, more than 50% of organizations report experiencing an SSH Key related compromise. Check out this upcoming eSeminar and join Adam Bosnian, EVP of Global Business Development at CyberArk, as he discusses the …

  • In the words of epic book series Game of Thrones, "Winter is coming," and there's never been a better time to be on your guard. After all, we live in a world of vicious attacks, scary data breaches, unpredictable weather, and other factors that can threaten the very existence of both your applications and your precious data. Like any enterprise or organization, Westeros is endangered by a lack of continuity and poor disaster recovery plans. This white paper explores why disaster recovery should become a …

Most Popular Programming Stories

More for Developers

RSS Feeds

Thanks for your registration, follow us on our social networks to keep up-to-date