• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 230
  • Last Modified:

Drawing and deleting lines

Hi,

I made the following code. It should Draw lines with black color, if lDel is FALSE, if lDel is FALSE, it should delete this lines by setting the line-colour to the background-colour, so that the already drawn lines are overdrawn by the background-colour. But - that doesn´t work. How does it work the right way? Please give a detailed answer! Thanks in advance!


COLORREF BkColor, FgColor;

if (lDel)      // Set backgroundcolor
{      FgColor = dc->GetTextColor();
      BkColor = dc->GetBkColor();
      dc->SetTextColor(BkColor);
}

// Now I draw or delete some lines
...

if (lDel)      // Set old line-color as the new linecolor
{      dc->SetTextColor(FgColor);
}
0
erebel
Asked:
erebel
1 Solution
 
migelCommented:
Hi!
When you Draw line DC use PEN currently selected to it, so lines always appear in PEN`s color, not setted by SetTextColor functions.
Best way to erase lines is using XOR mode while drawing
to do it you must call SetROP2 with R2_XORPEN;
line will be erased when you draw it next time.
0
 
kulinaCommented:
In OnPaint enter these lines
// start
CPen pen;
CPaintDC dc(this);
// Don't forget to do this...
CPen* pOldPen = dc.SelectObject (&pen);
if(IDel == FALSE)
{
BkColor = dc->GetBkColor();
pen.CreatePen(PS_SOLID, 1, BkColor );
dc.SelectObject(&pen);
dc.MoveTo(x, y);
dc.LineTo(a, b);
}
dc.SelectObject(pOldPen);
// end

....where x and y are coordinates starting postition of your line, and a and b are ending positions of your line.
I haven't tried this possible solution but I'm pretty convicned it'll work.
Good Luck!
0

Featured Post

Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now