Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
See more: VC6 MFC GDI+
How can I use graphics class to draw images over a bitmap? Which then can be restored to the screen so whatever i draw does not get erased when I call invalidate().please provide me the solution.
Posted 1-Dec-10 20:49pm
Edited 2-Dec-10 5:02am
v3
Comments
Emilio Garavaglia at 2-Dec-10 8:23am
   
By saying "as soon as possible", you'll make no-one responding.
shivam13 at 2-Dec-10 10:02am
   
Is it OK now.i hope i will get some response to my question now
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 2

"Provide me the solution" seems implying there must be one and only. But the question is strange, since it mixed up two distinct aspects.
 
Drawing on a bitmap is something that happens in memory, and has no relation with the action of invalidate(), whose purpose is to force the window manager to ask your program to redraw the window contents.
 
If you don't want the window contents to "vanish", you have to override OnPaint, repainting the window.
You can do that by copying an image in it (Create a CPaintDC, initialise a gdp::Graphics with it, ad use it to draw your already existent and drawn bitmap into it).
 
To draw your bitmap, you have first to create a gdp::Bitmap somewhere, initiaklize a gdp::Graphics on it, ad use it to draw.
 
But ... are these two distinct step necessary? Can't you just draw the into the window when required?
  Permalink  
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 3

The window does not have a persistent canvas/bitmap associated with its surface. The system can overwrite a protion of your window on the screen any time, and it can call you any time with a WM_PAINT to ask you to redraw the 'destroyed' part of the window image on the screen.
The drawing consists of 2 steps:
  1. The system sends WM_ERASEBKGND to your window/control.
  2. WM_PAINT, where you have to draw your control
If you want to keep the image of your window/control then you have to draw the actual appearance of the control to an in-memory bitmap, and in the WM_PAINT message you just draw the bitmap to the control. This is called double buffering. If the control is not too complex then it does not worth keeping an in memory bitmap for this purpose. Doublebuffering is usually used only if the drawing of the control is complex and performance critical, or if you can avoid a lot of annoying flickering. Another two flicker avoidance methods:
  1. Returning 1 from WM_ERASEBKGND without clearing the beckground before painting.
  2. Moving your drawing to WM_ERASEBKGND entirely from your WM_PAINT, and doing nothing in WM_PAINT but validating the clipping region (for example by just calling BeginPaint() and EndPaint() without actual drawing).
  Permalink  
Comments
shivam13 at 5-Dec-10 10:56am
   
Thanks,but I have to draw some line,or rectangle,or ellipse according to the selection of the button.how can i use double buffering on that case I don't have any experience on that topic ,can you provide me any example of that or any other way of retaining shapes using GDI+.
pasztorpisti at 5-Dec-10 13:06pm
   
Then you have to derive your own button class from the class you are currently using, and somehow override its OnPaint() method (or intercept the OnPaint() handler in the message map, I don't know what to tell because you haven't shown any reference code to bugfix.). And you should use your own button class instead of the current one. In the OnPaint() event handler you have to draw the entire button according to the current state (background, border, label, and maybe a focus rectangle).
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 1

When you call invalidate(), a WM_PAINT message is sent.
In your OnPaint[^]function, you can then do whatever is needed to redraw the picture (using the graphics class if you wish).
  Permalink  
v4

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
0 OriginalGriff 5,130
1 DamithSL 4,237
2 Maciej Los 3,700
3 Kornfeld Eliyahu Peter 3,470
4 Sergey Alexandrovich Kryukov 2,846


Advertise | Privacy | Mobile
Web02 | 2.8.141216.1 | Last Updated 3 Dec 2010
Copyright © CodeProject, 1999-2014
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100