Solved

Drawing and deleting lines

Posted on 2000-03-17
2
197 Views
Last Modified: 2013-11-20
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
Comment
Question by:erebel
2 Comments
 
LVL 12

Expert Comment

by:migel
ID: 2629708
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
 
LVL 3

Accepted Solution

by:
kulina earned 50 total points
ID: 2654484
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

3 Use Cases for Connected Systems

Our Dev teams are like yours. They’re continually cranking out code for new features/bugs fixes, testing, deploying, testing some more, responding to production monitoring events and more. It’s complex. So, we thought you’d like to see what’s working for us.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Introduction: Finishing the grid – keyboard support for arrow keys to manoeuvre, entering the numbers.  The PreTranslateMessage function is to be used to intercept and respond to keyboard events. Continuing from the fourth article about sudoku. …
Introduction: Hints for the grid button.  Nested classes, templated collections.  Squash that darned bug! Continuing from the sixth article about sudoku.   Open the project in visual studio. First we will finish with the SUD_SETVALUE messa…
This video will show you how to get GIT to work in Eclipse.   It will walk you through how to install the EGit plugin in eclipse and how to checkout an existing repository.
This video shows how to quickly and easily add an email signature for all users on Exchange 2016. The resulting signature is applied on a server level by Exchange Online. The email signature template has been downloaded from: www.mail-signatures…

809 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question