Drawing Colored Rectangles
-
I'm currently testing my project on Windows ME and have found the following problem: I'm using a SDI project using the Doc/View architecture. Using the code at the bottom of this post i'm drawing rectangles on to the screen. When redrawing the screen (Most often when I've got an Invalidate() command in the MouseMove Handler), after a certain number of redraws (A different number each time), suddenly lose the color from my blocks and just get a black outline. I have absolutely no idea why this happens, could somebody help me? Thanks in advance, - X The Code (This is placed in a function and called for each block I need to draw): CBrush br; CRect rect; rect.left = point.x - BLOCKWIDTH/2; rect.top = point.y - BLOCKHEIGHT/2; rect.right = point.x + BLOCKWIDTH/2; rect.bottom = point.y + BLOCKHEIGHT/2 - NODELENGTH; // I'm writing a Flow Chart application, so the following line draw // little 'nodes' at the top and bottom of each block pDC->MoveTo(point.x, point.y + BLOCKHEIGHT/2 - NODELENGTH); pDC->LineTo(point.x, point.y + BLOCKHEIGHT/2); br.CreateSolidBrush(RGB(0,200,0)); pDC->SelectObject(&br); pDC->Rectangle(rect); br.DeleteObject();
-
I'm currently testing my project on Windows ME and have found the following problem: I'm using a SDI project using the Doc/View architecture. Using the code at the bottom of this post i'm drawing rectangles on to the screen. When redrawing the screen (Most often when I've got an Invalidate() command in the MouseMove Handler), after a certain number of redraws (A different number each time), suddenly lose the color from my blocks and just get a black outline. I have absolutely no idea why this happens, could somebody help me? Thanks in advance, - X The Code (This is placed in a function and called for each block I need to draw): CBrush br; CRect rect; rect.left = point.x - BLOCKWIDTH/2; rect.top = point.y - BLOCKHEIGHT/2; rect.right = point.x + BLOCKWIDTH/2; rect.bottom = point.y + BLOCKHEIGHT/2 - NODELENGTH; // I'm writing a Flow Chart application, so the following line draw // little 'nodes' at the top and bottom of each block pDC->MoveTo(point.x, point.y + BLOCKHEIGHT/2 - NODELENGTH); pDC->LineTo(point.x, point.y + BLOCKHEIGHT/2); br.CreateSolidBrush(RGB(0,200,0)); pDC->SelectObject(&br); pDC->Rectangle(rect); br.DeleteObject();
Select the brush out of the device context before destroying the brush.
CBrush* pOldBrush = pDC->SelectObject(&br);
pDC->Rectangle(rect);
pDC->SelectObject ( pOldBrush );
br.DeleteObject();--Mike-- http://home.inreach.com/mdunn/ :love: your :bob: with :vegemite: and :beer:
-
I'm currently testing my project on Windows ME and have found the following problem: I'm using a SDI project using the Doc/View architecture. Using the code at the bottom of this post i'm drawing rectangles on to the screen. When redrawing the screen (Most often when I've got an Invalidate() command in the MouseMove Handler), after a certain number of redraws (A different number each time), suddenly lose the color from my blocks and just get a black outline. I have absolutely no idea why this happens, could somebody help me? Thanks in advance, - X The Code (This is placed in a function and called for each block I need to draw): CBrush br; CRect rect; rect.left = point.x - BLOCKWIDTH/2; rect.top = point.y - BLOCKHEIGHT/2; rect.right = point.x + BLOCKWIDTH/2; rect.bottom = point.y + BLOCKHEIGHT/2 - NODELENGTH; // I'm writing a Flow Chart application, so the following line draw // little 'nodes' at the top and bottom of each block pDC->MoveTo(point.x, point.y + BLOCKHEIGHT/2 - NODELENGTH); pDC->LineTo(point.x, point.y + BLOCKHEIGHT/2); br.CreateSolidBrush(RGB(0,200,0)); pDC->SelectObject(&br); pDC->Rectangle(rect); br.DeleteObject();
FillSolidRect is better because you pass in the brush as a parameter, instead of having to select it in and out. pDC->FillSolidRect(&rect, RGB(255,0,255)); Christian As I learn the innermost secrets of the around me, they reward me in many ways to keep quiet. Men with pierced ears are better prepared for marriage. They've experienced pain and bought Jewellery.