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. Draw in front of bitmap

Draw in front of bitmap

Scheduled Pinned Locked Moved C / C++ / MFC
questionc++graphicstutorial
3 Posts 2 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.
  • L Offline
    L Offline
    lor75
    wrote on last edited by
    #1

    Hello, in a MFC program I've put a picture control (bitmap type) that display a bitmap image inserted into the resources. I want to draw rectangles on the bitmap so I've put the OnDraw method like this for example:

    void CDialog3::OnPaint()
    {
    CPaintDC dc(this); // device context for painting
    dc.Rectangle(0,0,300,300);
    }

    it's very simple and the rectangle has been drawn but it's overlapped by the bitmap when it is drawn in the region where the bitmap is located. For every rectangle I draw there is the bitmap in front of it. How can I put the bitmap rear my rectangles and rear any shape that I want to draw?

    L 1 Reply Last reply
    0
    • L lor75

      Hello, in a MFC program I've put a picture control (bitmap type) that display a bitmap image inserted into the resources. I want to draw rectangles on the bitmap so I've put the OnDraw method like this for example:

      void CDialog3::OnPaint()
      {
      CPaintDC dc(this); // device context for painting
      dc.Rectangle(0,0,300,300);
      }

      it's very simple and the rectangle has been drawn but it's overlapped by the bitmap when it is drawn in the region where the bitmap is located. For every rectangle I draw there is the bitmap in front of it. How can I put the bitmap rear my rectangles and rear any shape that I want to draw?

      L Offline
      L Offline
      Lost User
      wrote on last edited by
      #2

      You need to understand how controls draw themselves in response to WM_PAINT messages. You probably need to draw the bitmap in the OnPaint method first, and then draw the rectangle over it.

      L 1 Reply Last reply
      0
      • L Lost User

        You need to understand how controls draw themselves in response to WM_PAINT messages. You probably need to draw the bitmap in the OnPaint method first, and then draw the rectangle over it.

        L Offline
        L Offline
        lor75
        wrote on last edited by
        #3

        Dear Richard, many thanks for your help. I followed your suggestion and it works. In my previous code I put the IDB_BITMAP of the bitmap into the IMAGE property of the Picture Control in order to load the bitmap automatically. I hadn't used a control variable to load the bitmap. Now I have add a control variable and I load the bitmap before drawing the rectangle. In this way the bitmap is under my rectangles.

        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