Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C / C++ / MFC
  4. Is any way to draw Background Image?

Is any way to draw Background Image?

Scheduled Pinned Locked Moved C / C++ / MFC
graphicswinformsquestion
5 Posts 4 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • 0 Offline
    0 Offline
    002comp
    wrote on last edited by
    #1

    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

    N N H 3 Replies Last reply
    0
    • 0 002comp

      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

      N Offline
      N Offline
      Nitheesh George
      wrote on last edited by
      #2

      Hi Please find the following link which answers your problem. Flicker Solution[] Nitheesh George http://www.simpletools.co.in

      1 Reply Last reply
      0
      • 0 002comp

        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

        N Offline
        N Offline
        Niklas L
        wrote on last edited by
        #3

        You might want to make sure your OnEraseBkgnd()[^] doesn't clear the screen (if you're going to fill it with a bitmap anyway). Return TRUE from this method.

        home

        1 Reply Last reply
        0
        • 0 002comp

          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

          H Offline
          H Offline
          Hans Dietrich
          wrote on last edited by
          #4

          You have three opportunities to reduce flicker: 1. Draw the image in the OnEraseBkgnd() handler and return TRUE. 2. Do other drawing in the OnPaint() handler. Use CMemDC 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" in OnPaint(); in fact, doing do would wipe out the image that was just drawn in OnEraseBkgnd(). 3. In the OnSize() 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 a WM_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 in OnEraseBkgnd() and foreground stuff in OnPaint(), although this is not a hard rule you have to follow; you can be sure that every WM_ERASEBKGND message will be followed by a WM_PAINT message.

          Best wishes, Hans


          [Hans Dietrich Software]

          0 1 Reply Last reply
          0
          • H Hans Dietrich

            You have three opportunities to reduce flicker: 1. Draw the image in the OnEraseBkgnd() handler and return TRUE. 2. Do other drawing in the OnPaint() handler. Use CMemDC 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" in OnPaint(); in fact, doing do would wipe out the image that was just drawn in OnEraseBkgnd(). 3. In the OnSize() 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 a WM_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 in OnEraseBkgnd() and foreground stuff in OnPaint(), although this is not a hard rule you have to follow; you can be sure that every WM_ERASEBKGND message will be followed by a WM_PAINT message.

            Best wishes, Hans


            [Hans Dietrich Software]

            0 Offline
            0 Offline
            002comp
            wrote on last edited by
            #5

            Hi Guys Thanks for your valuable time for my posting. I tried all the things but no Luck :( Thanks Yogesh

            1 Reply Last reply
            0
            Reply
            • Reply as topic
            Log in to reply
            • Oldest to Newest
            • Newest to Oldest
            • Most Votes


            • Login

            • Don't have an account? Register

            • Login or register to search.
            • First post
              Last post
            0
            • Categories
            • Recent
            • Tags
            • Popular
            • World
            • Users
            • Groups