Solved

How to draw a picture in the background without flickering on scrolling?

Posted on 2001-06-24
4
293 Views
Last Modified: 2013-11-20
I am trying to draw a picture in the background of my control, the picture is determined in a property called Picture from the type CPictureHolder. I need to draw this picture in a way to get rid of flickering while scrolling or resizing. I have tried several methods but seems that I am missing something! Is it possible to have this functionality??
0
Comment
Question by:Daed
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
4 Comments
 
LVL 1

Accepted Solution

by:
iProgram earned 100 total points
ID: 6222547
You can draw it in OnPaint.
To get rid of flicking, you can use CMemDC to instead of CDC object in OnPaint().
See the example here:
http://codeguru.earthweb.com/bitmap/formview_background.shtml
And the following is CMemDC:
//Include it in your CPP file
//MemDc.h
#ifndef _MEMDC_H_
#define _MEMDC_H_


class CMemDC : public CDC
{
private:
     CBitmap m_bitmap; // Offscreen bitmap
     CBitmap* m_oldBitmap; // bitmap originally found in CMemDC
     CDC* m_pDC; // Saves CDC passed in constructor
     CRect m_rect; // Rectangle of drawing area.
     BOOL m_bMemDC; // TRUE if CDC really is a Memory DC.

public:
     CMemDC(CDC* pDC, CRect rect = CRect(0,0,0,0)) : CDC(), m_oldBitmap(NULL), m_pDC(pDC)
     {
          ASSERT(m_pDC != NULL); // If you asserted here, you passed in a NULL CDC.
         
          m_bMemDC = !pDC->IsPrinting();
         
          if (m_bMemDC){
               // Create a Memory DC
               CreateCompatibleDC(pDC);
               if ( rect == CRect(0,0,0,0) )
                    pDC->GetClipBox(&m_rect);
               else
                    m_rect = rect;

               m_bitmap.CreateCompatibleBitmap(pDC, m_rect.Width(), m_rect.Height());
               m_oldBitmap = SelectObject(&m_bitmap);
               SetWindowOrg(m_rect.left, m_rect.top);
          } else {
               // Make a copy of the relevent parts of the current DC for printing
               m_bPrinting = pDC->m_bPrinting;
               m_hDC = pDC->m_hDC;
               m_hAttribDC = pDC->m_hAttribDC;
          }
     }
     
     ~CMemDC()
     {
          if(m_bMemDC)
          {
               // Copy the offscreen bitmap onto the screen.
               m_pDC->BitBlt(m_rect.left, m_rect.top, m_rect.Width(), m_rect.Height(),
                    this, m_rect.left, m_rect.top, SRCCOPY);
               //Swap back the original bitmap.
               SelectObject(m_oldBitmap);
          }
          else
          {
               // All we need to do is replace the DC with an illegal value,
               // this keeps us from accidently deleting the handles associated with
               // the CDC that was passed to the constructor.
               m_hDC = m_hAttribDC = NULL;
          }
     }
     
     // Allow usage as a pointer
     CMemDC* operator->() { return this; }
     
     // Allow usage as a pointer
     operator CMemDC*() { return this; }
};

#endif
0
 
LVL 49

Expert Comment

by:DanRollins
ID: 6222557
You should override Render() in your CPictureHolder-derived class.  Then draw it only when necessary.  Use ValidateRect() and/or ValidateRgn()to mask parts of the picture that are not being changed by the user-activity.

As IProgram said, using a memory DC might help.

-- Dan
0
 

Author Comment

by:Daed
ID: 6227549
I tried using the CMemDC in OnPaint(), but my problem is that i need to write over the background picture, and this happens on DrawItem of another class, so when using the CMemDC there also, the new writtings are drawn over the picture (on a white rect) and hide it. How can i write over the background picture without any mixing in the colors and no flickering as well!
0
 
LVL 23

Expert Comment

by:Roshan Davis
ID: 9490124
No comment has been added lately, so it's time to clean up this TA.
I will leave a recommendation in the Cleanup topic area that this question is:

Answered by : iProgram  

Please leave any comments here within the next seven days.

PLEASE DO NOT ACCEPT THIS COMMENT AS AN ANSWER!

Roshan Davis
EE Cleanup Volunteer
0

Featured Post

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
viewing source code from eclipse 13 111
Detect file exist or not 3 215
Bartender label printing - switch on and off graphics 3 94
moto 4g phone enable finger print 4 73
Exception Handling is in the core of any application that is able to dignify its name. In this article, I'll guide you through the process of writing a DRY (Don't Repeat Yourself) Exception Handling mechanism, using Aspect Oriented Programming.
In this post we will learn different types of Android Layout and some basics of an Android App.
This video will show you how to get GIT to work in Eclipse.   It will walk you through how to install the EGit plugin in eclipse and how to checkout an existing repository.

751 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question