CFormView Class with Custom Background Color

CColorFormView is derived from CFormView with custom background color.

How to use CColorFormView class in your project?

1)Derive your form view class from CColorFormView class. For example:
class CMyFormView : public CColorFormView
2)Change form view background color: You can specify background color in your form view's OnInitialUpdate():

void CMyFormViewView::OnInitialUpdate() 
{
 SetWindowText(_T("This is my formview"));

 CColorFormView::OnInitialUpdate();

 // set color to your form view
 SetBackgroundColor(RGB(0, 128, 0));	

 // make the parent frame fit the form template
 GetParentFrame()->RecalcLayout();
 ResizeParentToFit();
}
I hope you enjoy this little class.

Download demo project - 31 KB

Download source - 2 KB



Comments

  • Maximize form

    Posted by Legacy on 07/16/2002 12:00am

    Originally posted by: alenbabu

    How can I maximize the size of a CFormView in order to it takes all the place of the parent frame.
    
    I have used

    CColorFormView::OnInitialUpdate();
    SetBackgroundColor(RGB(256, 0, 255));
    GetParentFrame()->RecalcLayout();
    ResizeParentToFit();

    But that didn't help

    Also I want to change the background color of my
    already existing application which is basically
    View class with two formViews on it.
    But I get error message

    error C2065: 'IDD_MANAGEMENT_FORM' : didn't
    declared
    error C2057: A constant expression expected
    error C2065: 'IDD_PROCESSCONTROL_FORM' : didn't
    declared
    error C2057: A constant expression expected
    What is wrong. I have added the header file of each form
    in the ColorFormView.cpp file

    Can you please help me

    Reply
  • How can I paint the bgcolor in WIN CE 3.0?

    Posted by Legacy on 01/18/2002 12:00am

    Originally posted by: kang ilkoo

    In win ce 3.0 MFC , there is no SetBackgroundColor method...

    Reply
  • Bestway to paint the background colo

    Posted by Legacy on 11/12/2001 12:00am

    Originally posted by: Pat Tharmarajah

    Do
    
    

    the following in your MFC CFormView class

    HBRUSH CFormView::OnCtlColor(CDC* pDC, CWnd* pWnd, UINT nCtlColor)
    {
    HBRUSH hbr = CFormView::OnCtlColor(pDC, pWnd, nCtlColor);
    // you can choose any color
    return(::CreateSolidBrush(RGB(77,0,77)));


    }

    • Danger code

      Posted by zjkg on 03/23/2014 02:14am

      The code, return(::CreateSolidBrush(RGB(77,0,77))); is critically dangerous. RESOURCE LEAK will be occured and your application will crash after many repaintings. ::DeleteObject() must be called but can't be called.

      Reply
    Reply
  • Bestway to paint the background colo

    Posted by Legacy on 11/12/2001 12:00am

    Originally posted by: Pat Tharmarajah

    Do

    the following in your MFC CFormView class

    HBRUSH CFormView::OnCtlColor(CDC* pDC, CWnd* pWnd, UINT nCtlColor)
    {
    HBRUSH hbr = CFormView::OnCtlColor(pDC, pWnd, nCtlColor);
    // you can choos any color
    return(::CreateSolidBrush(RGB(77,0,77)));

    // TODO: Return a different brush if the default is not desired
    return hbr;
    }

    Reply
  • Simple Formview BG Color

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

    Originally posted by: Mark Clouden

    How about....
    
    

    Works for me, no painting, no erasebackground, nothing else to it.

    HBRUSH
    xMyFormView::OnCtlColor(CDC* pDC, CWnd* pWnd, UINT nCtlColor)
    {

    pDC->SetTextColor(::GetSysColor(COLOR_WINDOWTEXT));
    return(::GetSysColorBrush(COLOR_WINDOW));
    }

    Reply
  • how to do the First step??I dun get it....

    Posted by Legacy on 03/25/2001 12:00am

    Originally posted by: stephen

    is that actually put "class CMyFormView : public CColorFormView" in the View header file or what..

    i dun know how to derive my form view class from CColorFormView class!!~~thank you

    Reply
  • Problem with EditView

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

    Originally posted by: Rajasekhar

    Hello!

    I am developing an application in eVC 3.0 using document/view architecture.My main view is CView.It's working fine.I have one more screen with base calss as CEditView.It's working fine to write something and to save.But when i tried to open a file, after selecting the file name, this view getting disappeared and the main view is coming up.How to keep the CEditView as the top view until i want.I am not implementing the Open Dialog functionality.

    I have a from with CFormView as the base class.I don't want the default scroll bars.How to remove them.

    When i implemented the Open Dialog functionality it's not showing the files available in a directory.What might be the problem?

    Please help me in this regard.

    Please send mail to chavasekhar@rediffmail.com

    Thanking you,

    Rajasekhar

    Reply
  • Screen Flashing?...Try this..

    Posted by Legacy on 05/11/2000 12:00am

    Originally posted by: Seung Wook, Hong

    Try this...
    
    Add 'WM_ERASEBKGND' Event Handler to your CView Class..
    and fill your color..
    At last, you must return TRUE(or 1)..

    BOOL CTestView::OnEraseBkgnd(CDC* pDC)
    {
    //CView::OnEraseBkgnd(pDC);
    CRect rect;
    GetClientRect(rect);
    pDC->FillRect(&rect, &m_wndbkBrush);
    return 1; // this...
    }

    Reply
  • Screen flashing

    Posted by Legacy on 05/11/2000 12:00am

    Originally posted by: Tong Chen

    I used your idea on CView, it worked. There is only one question: screen is always flashing when I resize the child windlow. Do you have any idea?

    Reply
  • CFormView Class with Custom Background Color

    Posted by Legacy on 05/06/2000 12:00am

    Originally posted by: Fabrice

    How can I maximize the size of a CFormView in order to it takes all the place of the mother frame.
    

    Reply
  • Loading, Please Wait ...

  • You must have javascript enabled in order to post comments.

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

Top White Papers and Webcasts

  • As all sorts of data becomes available for storage, analysis and retrieval - so called 'Big Data' - there are potentially huge benefits, but equally huge challenges...
  • The agile organization needs knowledge to act on, quickly and effectively. Though many organizations are clamouring for "Big Data", not nearly as many know what to do with it...
  • Cloud-based integration solutions can be confusing. Adding to the confusion are the multiple ways IT departments can deliver such integration...

Most Popular Programming Stories

More for Developers

RSS Feeds

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