|
Subject:
|
Can someone help me wif CBrush and CPen
|
|
Posted By:
|
conny
|
Post Date:
|
4/5/2005 4:38:06 AM
|
I've declared and created the brush and pen of bright color, but when i draw the line, it's still in black. Is there any problem with the codes? thanx alot.
if (m_Drag && PointOrigin!=point) // for mouse drag check { // Graphics CClientDC ClientDC(this); ClientDC.SetROP2(R2_NOT); CPen SolidPen (PS_SOLID, 1, RGB(0,255,255)); CPen *OldPen; OldPen = ClientDC.SelectObject(&SolidPen); //Declare and create the brush CBrush newBrush; newBrush.CreateSolidBrush( RGB(0, 255, 255)); CBrush *pBrushSv = ClientDC.SelectObject( &newBrush); //Arrow if (MotionFix && dline==1) DrawLine(&ClientDC,PointOrigin,PointOld); //check if "line" radio button clicked if(dline==1) { MotionFix=1; // MotionFix is used to prevent redrawing DrawLine(&ClientDC,PointOrigin,point); }
|
|
Reply By:
|
CharlieChan
|
Reply Date:
|
6/22/2005 7:20:35 PM
|
Here is what Ivor Horton did in Beginnig Visual C++ 6 to draw a line. This is from chapter 16. I don't know if it will help.
// Implementations of the element classes #include "stdafx.h"
#include <math.h>
#include "OurConstants.h" #include "Elements.h"
// CLine class constructor CLine::CLine(const CPoint& Start, const CPoint& End, const COLORREF& Color) { m_StartPoint = Start; // Set line start point m_EndPoint = End; // Set line end point m_Color = Color; // Set line color m_Pen = 1; // Set pen width
// Define the enclosing rectangle m_EnclosingRect = CRect(Start, End); m_EnclosingRect.NormalizeRect(); }
void CLine::Draw(CDC* pDC, const CElement* pElement) const { // Create a pen for this object and // initialize it to the object color and line width CPen aPen; COLORREF aColor = m_Color; // Initialize with element color if (this == pElement) // This element selected? aColor = SELECT_COLOR; // Set highlight color if (!aPen.CreatePen(PS_SOLID, m_Pen, aColor)) { // Pen creation failed. Abort the program AfxMessageBox("Pen creation failed drawing a line", MB_OK); AfxAbort(); }
CPen* pOldPen = pDC->SelectObject(&aPen); // Select the pen
// Now draw the line pDC->MoveTo(m_StartPoint); pDC->LineTo(m_EndPoint);
pDC->SelectObject(pOldPen); // Restore the old pen }
// Get the bounding rectangle for an element CRect CElement::GetBoundRect() const { CRect BoundingRect; // Object to store bounding rectangle BoundingRect = m_EnclosingRect; // Store the enclosing rectangle
// Increase the rectangle by the pen width BoundingRect.InflateRect(m_Pen, m_Pen);
return BoundingRect; // Return the bounding rectangle }
|
|
Reply By:
|
vigorous365
|
Reply Date:
|
8/16/2005 2:26:33 AM
|
Oh ,there is a small mistake in your code.Please remove the code" ClientDC.SetROP2(R2_NOT);"Because the code regulate that the current color is contray to the color of screen.
Redfox
|