Drawing Graph In VC++

M

matt

I am trying to draw a rectangle in a dialog window. I put the code in
OnPaint(), even though I see a message put there by VC++ saying "Do
not call CDialog::OnPaint() for painting messages." I don't know what
that means.

The code below worked in one dialog window, but not in another. Any
idea what could cause this to work in one window but not in a similar
one? (there are no buttons or controls overlapping where the rectangle
should be)

CPaintDC dc(this); // device context for painting
CPoint upperLeft,lowerRight;
upperLeft.x=40;
upperLeft.y=40;
lowerRight.x=upperLeft.x+40;
lowerRight.y=80;
CRect recGraph(upperLeft.x,upperLeft.y,lowerRight.x,lowerRight.y);
CPen penBlack(PS_SOLID,2,RGB(0,0,0));
dc.SelectObject(&penBlack);
CBrush brGreen(RGB(92,200,92));
dc.SelectObject(&brGreen);
recGraph.DeflateRect(5,5);
dc.RoundRect(recGraph,CPoint(15,15));
 
G

Guillaume Brocker

matt said:
I am trying to draw a rectangle in a dialog window. I put the code in
OnPaint(), even though I see a message put there by VC++ saying "Do
not call CDialog::OnPaint() for painting messages." I don't know what
that means.

The code below worked in one dialog window, but not in another. Any
idea what could cause this to work in one window but not in a similar
one? (there are no buttons or controls overlapping where the rectangle
should be)

CPaintDC dc(this); // device context for painting
CPoint upperLeft,lowerRight;
upperLeft.x=40;
upperLeft.y=40;
lowerRight.x=upperLeft.x+40;
lowerRight.y=80;
CRect recGraph(upperLeft.x,upperLeft.y,lowerRight.x,lowerRight.y);
CPen penBlack(PS_SOLID,2,RGB(0,0,0));
dc.SelectObject(&penBlack);
CBrush brGreen(RGB(92,200,92));
dc.SelectObject(&brGreen);
recGraph.DeflateRect(5,5);
dc.RoundRect(recGraph,CPoint(15,15));

You should post such messages in <microsoft.public.vc.mfc>.

Have you already tryed to put your drawing code in the OnEraseBkgnd
message hander ?
 
H

Howard

matt said:
I am trying to draw a rectangle in a dialog window. I put the code in
OnPaint(), even though I see a message put there by VC++ saying "Do
not call CDialog::OnPaint() for painting messages." I don't know what
that means.

That means do not call the CDialog::OnPaint function yourself in response to
a WM_PAINT message. It's perfectly fine to write painting functions in the
OnPaint function...that's what it's there for! Your message dispatcher will
call OnPaint for you when appropriate, and that's when you do your custom
painting. I'm just guessing here, but it might be that calling OnPaint in
response to WM_PAINT will cause another WM_PAINT message to occur, which
will then call OnPaint again, which will generate another WM_PAINT, etc,
etc. In other words, infinite recursion, and a stack crash results. (Just
my guess, though...ask in a Windows newsgroup for better answers.)

-Howard
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,755
Messages
2,569,536
Members
45,015
Latest member
AmbrosePal

Latest Threads

Top