Solved

CFrameWnd saving background as bitmap

Posted on 2004-03-23
4
453 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
  • 2
4 Comments
 

Author Comment

by:jasoncpp
Comment Utility
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
Comment Utility
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
Comment Utility
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
Comment Utility
Thank you, I found both comments helpful.
0

Featured Post

Highfive Gives IT Their Time Back

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

Introduction: Dynamic window placements and drawing on a form, simple usage of windows registry as a storage place for information. Continuing from the first article about sudoku.  There we have designed the application and put a lot of user int…
Introduction: Load and Save to file, Document-View interaction inside the SDI. Continuing from the second article about sudoku.   Open the project in visual studio. From the class view select CSudokuDoc and double click to open the header …
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…

728 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

Need Help in Real-Time?

Connect with top rated Experts

10 Experts available now in Live!

Get 1:1 Help Now