OnEraseBackground
CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 7 of 7

Thread: OnEraseBackground

  1. #1
    Join Date
    Jan 2004
    Location
    Italy
    Posts
    144

    OnEraseBackground

    Hi gurus.
    I have some problems overriding OnEraseBackground in my MFC dialog-based applications (the framework doesn't call my override).
    Can anyone suggest how to handle this matter?
    (before you ask: yes, I added the OnEraseBackground declaration in the message map... well, at leas I think I didi it properly )
    Thanks!

  2. #2
    Join Date
    Mar 2004
    Location
    pathankot,punjab, india
    Posts
    57
    can u plz come up with some amount of code??

  3. #3
    VictorN's Avatar
    VictorN is offline Super Moderator Power Poster
    Join Date
    Jan 2003
    Location
    Wallisellen (ZH), Switzerland
    Posts
    17,517
    The best way to "override OnEraseBackground" would be to let ClassWizard add Windows message handler WM_ERASEBKGND into your class.
    After doing this you'd have to get
    a) in your header:
    Code:
    	afx_msg BOOL OnEraseBkgnd(CDC* pDC);
    b) in your cpp:
    Code:
    BEGIN_MESSAGE_MAP(<your_class> ,<Base_class>)
    	//{{AFX_MSG_MAP(<your_class>)
    	ON_WM_ERASEBKGND()
    	.............
    	//}}AFX_MSG_MAP
    ............
    BOOL <your_class>::OnEraseBkgnd(CDC* pDC) 
    {
    	return <Base_class>::OnEraseBkgnd(pDC);
    }

  4. #4
    Join Date
    Jan 2004
    Location
    Punjab, India
    Posts
    113
    Hey,

    Once i also had the same problem. But it figured out that i was returning from the function before actual code.

    some thing like

    BOOL <your_class>::OnEraseBkgnd(CDC* pDC)
    {
    return <Base_class>::OnEraseBkgnd(pDC);

    //your own code

    }

    In case this is the problem.

    Amit

  5. #5
    Join Date
    Jan 2004
    Location
    Italy
    Posts
    144
    Ok... VictorN helped me understand... I forgot to put "ON_WM_ERASEBKGND()" in the message map...
    Sorry for the silly question... crunch time is almost killing me!

    P.S. VictorN, you wrote
    BOOL <your_class>::OnEraseBkgnd(CDC* pDC)
    {
    return <Base_class>::OnEraseBkgnd(pDC);
    }

    ...I think the function should return TRUE if it handles the background erasing task, right?

  6. #6
    VictorN's Avatar
    VictorN is offline Super Moderator Power Poster
    Join Date
    Jan 2003
    Location
    Wallisellen (ZH), Switzerland
    Posts
    17,517
    ...I think the function should return TRUE if it handles the background erasing task, right?
    Yes!
    Sorry, i forgot to paste the rest of my code in OnEraseBkgnd() body.
    Code:
    BOOL <myClass>::OnEraseBkgnd(CDC* pDC) 
    {
    	if(<I do smth. myself>)
    	{	
    		//  do it	
    		return TRUE;
    	}
    	else
    		return <aseClass>::OnEraseBkgnd(pDC);
    }

  7. #7
    Join Date
    Aug 2000
    Location
    New York, NY, USA
    Posts
    5,545
    Originally posted by Amit Sebiz
    Once i also had the same problem. But it figured out that i was returning from the function before actual code.

    some thing like

    BOOL <your_class>::OnEraseBkgnd(CDC* pDC)
    {
    return <Base_class>::OnEraseBkgnd(pDC);

    //your own code

    }
    The compiler would produce a warning (level 4) about unreachable code in such case.
    You should really read your compiler output. Oh, and set your Warning Level to 4 (if it isn't yet).
    Vlad - MS MVP [2007 - 2012] - www.FeinSoftware.com
    Convenience and productivity tools for Microsoft Visual Studio:
    FeinViewer - an integrated GDI objects viewer for Visual C++ Debugger, and more...

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  


Windows Mobile Development Center


Click Here to Expand Forum to Full Width

This is a CodeGuru survey question.


Featured


HTML5 Development Center