Go Premium for a chance to win a PS4. Enter to Win

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 485
  • Last Modified:

CFrameWnd saving background as bitmap

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
jasoncpp
Asked:
jasoncpp
  • 2
2 Solutions
 
jasoncppAuthor Commented:
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
 
Roshan DavisCommented:
one suggession... create a memory dc and draw all the stuffs in that DC, and copy that to screen DC on OnPaint
0
 
AndyAinscowCommented:
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
 
jasoncppAuthor Commented:
Thank you, I found both comments helpful.
0

Featured Post

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

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.

  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now