Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Dialog Box OnPaint a 2nd time

32 views
Skip to first unread message

Tony Maher

unread,
May 26, 2003, 11:58:38 PM5/26/03
to
G'Day

I have a simple little dialog box, with a few edit boxs and a calc button.
(as well as ok & cancel)

I'am using the OnPaint function to draw some lines on the dialog box, based
on the result of a Calculation, when Calc button is pressed I want to move
the lines to graphically show the result.


my code looks a bit like this

BOOL CWizardDlg::OnInitDialog()
{
CDialog::OnInitDialog();

iSkew=0;

return TRUE;
}


void CWizardDlg::OnPaint()
{
// draw lines on dialog based on the value of skew

CPaintDC dc(this); // device context for painting
CPen Pen1,Pen2;

Pen1.CreatePen(PS_SOLID, 2, RGB(0, 0, 0));
Pen2.CreatePen(PS_DASH, 1, RGB(0, 0, 0));

dc.SelectObject(&Pen1);

// Vertical Lines
dc.MoveTo(left,top+iSkew);
dc.LineTo(left,bott+iSkew);

..
..


}

void CWizardDlg::OnCalc()
{

// Do calc
// get result

iSkew=result;
OnPaint();

}


I know OnPaint() is being called a 2nd time, but for some reason its not
actually drawing on the screen.
Can anyone give me a few points, as to what iam doing wrong.

TIA
Tony


Jeff Partch

unread,
May 27, 2003, 12:23:56 AM5/27/03
to
Instead of calling OnPaint directly, call either Invalidate or
InvalidateRect -- possibly followed by a call to UpdateWindow if the
repaint doesn't happen fast enough for you.
--
Jeff Partch [VC++ MVP]

"Tony Maher" <TMa...@tommotek.com> wrote in message
news:3ed2e28d$0$31...@echo-01.iinet.net.au...

Tony Maher

unread,
May 27, 2003, 1:01:54 AM5/27/03
to
Jeff,

Invalidate did it..

void CWizardDlg::OnCalc()
{
// Do calc
// get result

iSkew=result;
Invalidate();
}


Thanks Again
Tony

"Jeff Partch" <je...@mvps.org> wrote in message
news:etCzCfAJ...@TK2MSFTNGP11.phx.gbl...

Joseph M. Newcomer

unread,
May 27, 2003, 7:00:32 PM5/27/03
to
Doing drawing directly on a dialog box is always a risky idea, and usually a bad idea. Put
a static control on the dialog and draw on that.

Calling OnPaint yourself is a technique so deeply and fundamentally flawed that it cannot
possibly work. Don't do it. Invalidate the area you want to redraw (in your case, perhaps
the whole dialog, which will produce annoying flashes), and let the WM_PAINT message
materialize on its own. The reason is the CPaintDC expects a clipping region, which is not
set when you call OnPaint yourself, so you may have an empty clipping region, and no
visible painting would take place.
joe

Joseph M. Newcomer [MVP]
email: newc...@flounder.com
Web: http://www.flounder.com
MVP Tips: http://www.flounder.com/mvp_tips.htm

0 new messages