Click to See Complete Forum and Search --> : WM_PAINT() question


odin
April 17th, 1999, 05:40 AM
Hello,

I'm doing some NC area painting in the WM_PAINT() procedure. The thing is that the painting doesn't always seem to work. But it always work if I put a AfxMessageBox() call in the beginning, I guess this changes the focus of the window somehow so the painting works, but I don't know how. Any ideas?

I'm processing the WM_PAINT in the CMainFrame and I got a splitter window in the main CView.

This is some of my code:

void CMainFrame::OnPaint()
{
CFrameWnd::OnPaint();

AfxMessageBox("now itll work but with a annoying msgbox");
CWindowDC dc(this);
CView* pView = GetRightPane();
CPen penGrey, penWhite, penDark;

RECT rectTmp;

pView->GetWindowRect(&rectTmp);

penGrey.CreatePen(PS_SOLID, 2, ::GetSysColor(COLOR_ACTIVEBORDER));
penWhite.CreatePen(PS_SOLID, 1, ::GetSysColor(COLOR_BTNHILIGHT));
penDark.CreatePen(PS_SOLID, 1, ::GetSysColor(COLOR_BTNSHADOW));

RECT rect;
GetWindowRect(&rect);
ScreenToClient(&rect);
CPen* penOld = dc.SelectObject(&penGrey);

// sidlinjer grå
dc.MoveTo(rect.left + 9, rect.top + 115);
dc.LineTo(rect.left + 9, rect.bottom + 18);
dc.MoveTo(rect.right, rect.top + 115);
dc.LineTo(rect.right, rect.bottom + 18);

.
.
.
}

-- HENRIK

Lynx
April 17th, 1999, 05:48 AM
Try not to call the CFrameWnd::OnPaint(); in the OnPaint().

Lynx

Jason Teagle
April 19th, 1999, 02:51 AM
It is OK to call the base class of OnPaint() as long as you have not constructed a CPaintDC in your derived class; this is because the CPaintDC includes the calls to ::BeginPaint() and ::EndPaint(), and more than one call to these may produce undefined (and possibly undesirable) behaviour.

In some cases it may be important to call the base class, if, for example, the base class did some painting you don't want to have to reproduce in your derived class. True, this is not usually the case with CFrameWnd as the base class, but the principle is the same. If you need to do some painting after the base class has finished, you can then construct a normal CClientDC object.

Jason Teagle
April 19th, 1999, 02:53 AM
I'm not really sure why the message box makes it work; possibly because it covers more of your window and therefore causes more of it to be repainted. However, what I WOULD suggest is that you trap the WM_NCPAINT message to paint outside the client area; this is its purpose. That may cure your problem.