Solved

Drawing and deleting lines

Posted on 2000-03-17
2
219 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Introduction: Dynamic window placements and drawing on a form, simple usage of windows registry as a storage place for information. Continuing from the first article about sudoku.  There we have designed the application and put a lot of user int…
Introduction: Database storage, where is the exe actually on the disc? Playing a game selected randomly (how to generate random numbers).  Error trapping with try..catch to help the code run even if something goes wrong. Continuing from the seve…
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.
In this video, viewers are given an introduction to using the Windows 10 Snipping Tool, how to quickly locate it when it's needed and also how make it always available with a single click of a mouse button, by pinning it to the Desktop Task Bar. Int…

729 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