Solved

Drawing and deleting lines

Posted on 2000-03-17
2
178 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

Threat Intelligence Starter Resources

Integrating threat intelligence can be challenging, and not all companies are ready. These resources can help you build awareness and prepare for defense.

Join & Write a Comment

Suggested Solutions

This is to be the first in a series of articles demonstrating the development of a complete windows based application using the MFC classes.  I’ll try to keep each article focused on one (or a couple) of the tasks that one may meet.   Introductio…
Introduction: Load and Save to file, Document-View interaction inside the SDI. Continuing from the second article about sudoku.   Open the project in visual studio. From the class view select CSudokuDoc and double click to open the header …
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.
Access reports are powerful and flexible. Learn how to create a query and then a grouped report using the wizard. Modify the report design after the wizard is done to make it look better. There will be another video to explain how to put the final p…

706 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

Need Help in Real-Time?

Connect with top rated Experts

13 Experts available now in Live!

Get 1:1 Help Now