Is any way to draw Background Image?
-
Hello Friends I am Drawing a image using GDI+ on OnPaint().And Its Flickering Whenever I resize Window.I tried all the ways to reduce Flicker but no Luck. Actually,I am drawing it as background Image and I dont want to call it again and again.SO,Is there any way to draw background image using DC or some way so that OnPaint doesnt effect it and it remains there? Thanks & Regards Yogesh
-
Hello Friends I am Drawing a image using GDI+ on OnPaint().And Its Flickering Whenever I resize Window.I tried all the ways to reduce Flicker but no Luck. Actually,I am drawing it as background Image and I dont want to call it again and again.SO,Is there any way to draw background image using DC or some way so that OnPaint doesnt effect it and it remains there? Thanks & Regards Yogesh
Hi Please find the following link which answers your problem. Flicker Solution[] Nitheesh George http://www.simpletools.co.in
-
Hello Friends I am Drawing a image using GDI+ on OnPaint().And Its Flickering Whenever I resize Window.I tried all the ways to reduce Flicker but no Luck. Actually,I am drawing it as background Image and I dont want to call it again and again.SO,Is there any way to draw background image using DC or some way so that OnPaint doesnt effect it and it remains there? Thanks & Regards Yogesh
-
Hello Friends I am Drawing a image using GDI+ on OnPaint().And Its Flickering Whenever I resize Window.I tried all the ways to reduce Flicker but no Luck. Actually,I am drawing it as background Image and I dont want to call it again and again.SO,Is there any way to draw background image using DC or some way so that OnPaint doesnt effect it and it remains there? Thanks & Regards Yogesh
You have three opportunities to reduce flicker: 1. Draw the image in the
OnEraseBkgnd()
handler and return TRUE. 2. Do other drawing in theOnPaint()
handler. UseCMemDC
to double buffer the dc. Since the entire background (I assume) is being covered with the image, there is no need to do a "fill" inOnPaint()
; in fact, doing do would wipe out the image that was just drawn inOnEraseBkgnd()
. 3. In theOnSize()
handler, tell Windows to defer re-positioning your controls until you are finished, You do this by using the DeferWindowPos() function (there are two other functions you will need, they are explained at that link). The way Windows works, anything that obscures your window causes aWM_ERASEBKGND
message to be sent to your window. This means that your window has to be redrawn when it is uncovered. Examples: moving another window on top of your window, or minimizing/restoring your window. So to answer your question, there is no way to "permanently" paint the background, because it is constantly being redrawn due to normal window operations. It is also somewhat customary to do background stuff inOnEraseBkgnd()
and foreground stuff inOnPaint()
, although this is not a hard rule you have to follow; you can be sure that everyWM_ERASEBKGND
message will be followed by aWM_PAINT
message.Best wishes, Hans
-
You have three opportunities to reduce flicker: 1. Draw the image in the
OnEraseBkgnd()
handler and return TRUE. 2. Do other drawing in theOnPaint()
handler. UseCMemDC
to double buffer the dc. Since the entire background (I assume) is being covered with the image, there is no need to do a "fill" inOnPaint()
; in fact, doing do would wipe out the image that was just drawn inOnEraseBkgnd()
. 3. In theOnSize()
handler, tell Windows to defer re-positioning your controls until you are finished, You do this by using the DeferWindowPos() function (there are two other functions you will need, they are explained at that link). The way Windows works, anything that obscures your window causes aWM_ERASEBKGND
message to be sent to your window. This means that your window has to be redrawn when it is uncovered. Examples: moving another window on top of your window, or minimizing/restoring your window. So to answer your question, there is no way to "permanently" paint the background, because it is constantly being redrawn due to normal window operations. It is also somewhat customary to do background stuff inOnEraseBkgnd()
and foreground stuff inOnPaint()
, although this is not a hard rule you have to follow; you can be sure that everyWM_ERASEBKGND
message will be followed by aWM_PAINT
message.Best wishes, Hans