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