Wrox Programmer Forums
Go Back   Wrox Programmer Forums > C# and C > C++ and Visual C++ > Visual C++
|
Visual C++ Questions specific to Microsoft's Visual C++. For questions not specific to this Microsoft version, use the C++ Programming forum instead.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the Visual C++ section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old April 5th, 2005, 04:38 AM
Registered User
 
Join Date: Feb 2005
Posts: 6
Thanks: 0
Thanked 0 Times in 0 Posts
Default Can someone help me wif CBrush and CPen

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);
    }

 
Old June 22nd, 2005, 07:20 PM
Registered User
 
Join Date: Jun 2005
Posts: 5
Thanks: 0
Thanked 0 Times in 0 Posts
Default

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
}
 
Old August 16th, 2005, 02:26 AM
Registered User
 
Join Date: May 2005
Posts: 5
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via AIM to vigorous365 Send a message via MSN to vigorous365
Default

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









Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.