المساعد الشخصي الرقمي

مشاهدة النسخة كاملة : How to handle drawing into bitmaps and PAINT issues



C++ Programming
07-14-2009, 07:12 AM
I've created an application that loads a bitmap, and draws on it using various graphics functions (text, bitmap, etc) depending on various things that the user does (pressing keys, clicking buttons, etc). I was able to implement most everything I wanted to do, but there are problems related to not having used OnPaint, so when other windows cover my window, as expected the graphics I drew disappear. I understand the reason this happens, but I'm not quite sure what the simple work around is.

I can't do all my drawing in OnPaint, because well that would be weird. http://www.barakasoft.com/script/Forums/Images/smiley_smile.gif

I've started with a standard MFC Dialog App with a CStatic control. Here's fake code basics of what I have in OnInit():

CBitmap bmpIntro;
bmpIntro.LoadBitmap(IDB_Intro);

CStatic c_Image;
c_Image.SetBitmap(bmpIntro);

Now, problem #1 is that I want to put some intro text on this bitmap to appear when the window first opens. Putting it in OnInit() or OnPaint() doesn't seem to work.

The other problem is that as things progress, I'm using c_Image.GetDC() to draw all kinds of stuff into the CStatic control, and at any given moment, anything could be displayed depending on what the user initiated. Too much for OnPaint() to know what to recreate.

Since the CStatic already knows how to OnPaint() the original bitmap back into the dialog, is there a way I can draw into the original bitmap, so I don't have to worry about OnPaint() myself? And then somehow tell the CStatic to update itself? Or possibly I draw everything twice, once into the CStatic, and once into the original bitmap it is using.

Again, this seems kludgy, surely there's a more sensible way? And then how also to resolve problem #1?

modified on Monday, July 13, 2009 10:43 PM