Solved

CFrameWnd saving background as bitmap

Posted on 2004-03-23
4
472 Views
Last Modified: 2013-12-03
Hi,

I have subclassed a CFrameWnd, overridden OnPaint and in there I BitBlt some stuff to the window. I then save what i have done through a bitmap to a CDC object.  I then continuing painting as i do not want to include this extra stuff in the DC.  I only do this once ie

OnPaint event{
  draw();
  if(!done) {
    savebackground();
    done = true;
  }  
  drawOtherStuff();
}

This appears to work most of the time, but occasionally it is as if the wrong thing gets saved to the DC or I am saving before the frame is painted and i get a blank, white background with no images on it.

I am guessing what I am doing is not guaranteed to save the background, so how do I ensure what I am saving is what I want?

thanks for any help clarifying the situation.
0
Comment
Question by:jasoncpp
[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
  • 2
4 Comments
 

Author Comment

by:jasoncpp
ID: 10664161
Just to add, it is saving the blank background, not the stuff after any blitting, but the regular form's surface.   I noticed that when the frame loads slowly this is what it captures, as if the first draw instructions are not written to the frame in time for the save instructions so it gets a blank form.
0
 
LVL 23

Accepted Solution

by:
Roshan Davis earned 250 total points
ID: 10664342
one suggession... create a memory dc and draw all the stuffs in that DC, and copy that to screen DC on OnPaint
0
 
LVL 44

Assisted Solution

by:AndyAinscow
AndyAinscow earned 250 total points
ID: 10664984
You also need to cope with window being resized.

Have a member variable in class of type bitmap.
When background not prepared create a memory dc, put bitmap into that, draw the bitmap.  Now bitmap prepared.
In paint dc just BitBlt this bitmap to your background.

A tip.  Provide handler for WM_ERASEBACKGROUND and in the function DO NOTHING AND RETURN TRUE.  This will stop a lot of flicker
0
 

Author Comment

by:jasoncpp
ID: 10668974
Thank you, I found both comments helpful.
0

Featured Post

Get proactive database performance tuning online

At Percona’s web store you can order full Percona Database Performance Audit in minutes. Find out the health of your database, and how to improve it. Pay online with a credit card. Improve your database performance now!

Question has a verified solution.

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

Introduction: The undo support, implementing a stack. Continuing from the eigth article about sudoku.   We need a mechanism to keep track of the digits entered so as to implement an undo mechanism.  This should be a ‘Last In First Out’ collec…
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.
Excel styles will make formatting consistent and let you apply and change formatting faster. In this tutorial, you'll learn how to use Excel's built-in styles, how to modify styles, and how to create your own. You'll also learn how to use your custo…

615 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