Paint a line 
Author Message
 Paint a line

Hey

Might very simple! I need to draw a line in an operation, like the MFC
created:

void CSDIView::OnDraw(CDC* pDC)
{
 CSDIGraphicTestDoc* pDoc = GetDocument();
 ASSERT_VALID(pDoc);
 // TODO: add draw code for native data here

 CPen RedPen;
 RedPen.CreatePen(PS_SOLID,1,RGB(255,0,0));

 pDC->SelectObject(&RedPen);
 pDC->MoveTo(1,1);
 pDC->LineTo(1,5);

Quote:
}

I create an operation, which shall do the same and this is no problem, but
how shall I call the operation, I need the parameter??? The CDC object,
which the wizard automatic has created???

Thanks Denker(DK)



Sat, 25 Oct 2003 19:17:55 GMT  
 Paint a line

Quote:
>void CSDIView::OnDraw(CDC* pDC)
>I create an operation, which shall do the same and this is no problem, but
>how shall I call the operation, I need the parameter??? The CDC object,
>which the wizard automatic has created???

Are you looking for CWnd::GetDC ?

Dave
--
MVP VC++ FAQ: http://www.mvps.org/vcfaq
My address is altered to discourage junk mail.
Please post responses to the newsgroup thread,
there's no need for follow-up email copies.



Sat, 25 Oct 2003 20:42:55 GMT  
 Paint a line
Denker!

You are on the right track, the OnDraw inparameter is indeed what you should
pass to your own function.

So, you'll get:

void CSDIView::OnDraw(CDC* pDC)
{
  CSDIGraphicTestDoc* pDoc = GetDocument();
  ASSERT_VALID(pDoc);
  // TODO: add draw code for native data here
  MyFunction(pDC);

Quote:
}

void CSDIView::MyFunction(CDC* pDC)
{
  CPen RedPen;
  RedPen.CreatePen(PS_SOLID,1,RGB(255,0,0));

  pDC->SelectObject(&RedPen);
  pDC->MoveTo(1,1);
  pDC->LineTo(1,5);

Quote:
}

Johan Rosengren
Responsable Informatique
PACTA S.A.


Quote:
> Hey

> Might very simple! I need to draw a line in an operation, like the MFC
> created:

> void CSDIView::OnDraw(CDC* pDC)
> {
>  CSDIGraphicTestDoc* pDoc = GetDocument();
>  ASSERT_VALID(pDoc);
>  // TODO: add draw code for native data here

>  CPen RedPen;
>  RedPen.CreatePen(PS_SOLID,1,RGB(255,0,0));

>  pDC->SelectObject(&RedPen);
>  pDC->MoveTo(1,1);
>  pDC->LineTo(1,5);
> }

> I create an operation, which shall do the same and this is no problem, but
> how shall I call the operation, I need the parameter??? The CDC object,
> which the wizard automatic has created???

> Thanks Denker(DK)



Sat, 25 Oct 2003 20:21:19 GMT  
 Paint a line
Yes, it was... Thank you!

-Denker(DK)


Quote:
> >void CSDIView::OnDraw(CDC* pDC)
> >I create an operation, which shall do the same and this is no problem,
but
> >how shall I call the operation, I need the parameter??? The CDC object,
> >which the wizard automatic has created???

> Are you looking for CWnd::GetDC ?

> Dave
> --
> MVP VC++ FAQ: http://www.mvps.org/vcfaq
> My address is altered to discourage junk mail.
> Please post responses to the newsgroup thread,
> there's no need for follow-up email copies.



Sat, 25 Oct 2003 20:57:39 GMT  
 Paint a line
Thanks, it works! But, what if I need to call MyFunction(pDC) with ex. a
menu call e.g. from another function. Not from the OnDraw function. I tried
to assign a CDC pointer to the *pDC and then use that one, but I got a debug
error.

???

Thanks Denker(DK)


Quote:
> Denker!

> You are on the right track, the OnDraw inparameter is indeed what you
should
> pass to your own function.

> So, you'll get:

> void CSDIView::OnDraw(CDC* pDC)
> {
>   CSDIGraphicTestDoc* pDoc = GetDocument();
>   ASSERT_VALID(pDoc);
>   // TODO: add draw code for native data here
>   MyFunction(pDC);

> }

> void CSDIView::MyFunction(CDC* pDC)
> {
>   CPen RedPen;
>   RedPen.CreatePen(PS_SOLID,1,RGB(255,0,0));

>   pDC->SelectObject(&RedPen);
>   pDC->MoveTo(1,1);
>   pDC->LineTo(1,5);
> }

> Johan Rosengren
> Responsable Informatique
> PACTA S.A.



> > Hey

> > Might very simple! I need to draw a line in an operation, like the MFC
> > created:

> > void CSDIView::OnDraw(CDC* pDC)
> > {
> >  CSDIGraphicTestDoc* pDoc = GetDocument();
> >  ASSERT_VALID(pDoc);
> >  // TODO: add draw code for native data here

> >  CPen RedPen;
> >  RedPen.CreatePen(PS_SOLID,1,RGB(255,0,0));

> >  pDC->SelectObject(&RedPen);
> >  pDC->MoveTo(1,1);
> >  pDC->LineTo(1,5);
> > }

> > I create an operation, which shall do the same and this is no problem,
but
> > how shall I call the operation, I need the parameter??? The CDC object,
> > which the wizard automatic has created???

> > Thanks Denker(DK)



Sat, 25 Oct 2003 20:50:19 GMT  
 Paint a line
It depends on where you're going to be calling your new method from.  OnDraw
is given a pointer to the DC in the CView version of  OnPaint before it is
passed to you.  CView::OnPaint() does it like this:

CPaintDC dc(this);
OnPrepareDC(&dc);
OnDraw(&dc);

where the OnDraw() call goes to your overridden version of OnDraw()

If you're going to call it from your OnDraw just pass along what OnDraw is
given.  If you're going to be doing it from somewhere else you could mimic
what CView::OnPaint() does.

Also, CWnd::GetDC will return a CDC* to you so you could call that on your
view.

I'd recommend passing along the parameter from OnDraw() so you're doing your
drawing all at once.

-Dave
"No interesting quotes here"


Hey

Might very simple! I need to draw a line in an operation, like the MFC
created:

void CSDIView::OnDraw(CDC* pDC)
{
 CSDIGraphicTestDoc* pDoc = GetDocument();
 ASSERT_VALID(pDoc);
 // TODO: add draw code for native data here

 CPen RedPen;
 RedPen.CreatePen(PS_SOLID,1,RGB(255,0,0));

 pDC->SelectObject(&RedPen);
 pDC->MoveTo(1,1);
 pDC->LineTo(1,5);

Quote:
}

I create an operation, which shall do the same and this is no problem, but
how shall I call the operation, I need the parameter??? The CDC object,
which the wizard automatic has created???

Thanks Denker(DK)



Mon, 24 Nov 2003 06:50:24 GMT  
 
 [ 6 post ] 

 Relevant Pages 

1. How to paint a line in a CListView ?

2. paint rectangle with diagonal lines

3. OnNcPaint painting being painted over

4. CDC stops painting my rectangle after several paints??

5. Paint brushes and pots of paint

6. Printing line-by-line

7. Reading from a text file line by line

8. Opening a text file/Displaying text line by line

9. Multi-Line Comments Nested in Single Line Comments

10. char *line vs. char line[]

11. Reading Line per line in C

12. Dispaly lines of Lines of file with Win 3.1 SDK

 

 
Powered by phpBB® Forum Software