CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 4 of 4
  1. #1
    Join Date
    May 1999
    Location
    Sweden
    Posts
    30

    WM_PAINT() question

    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



  2. #2
    Join Date
    Apr 1999
    Location
    CA, USA
    Posts
    78

    Re: WM_PAINT() question

    Try not to call the CFrameWnd::OnPaint(); in the OnPaint().

    Lynx


  3. #3
    Join Date
    May 1999
    Location
    Farnborough, Hants, England
    Posts
    710

    Re: WM_PAINT() question

    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
    [email protected]

  4. #4
    Join Date
    May 1999
    Location
    Farnborough, Hants, England
    Posts
    710

    Re: WM_PAINT() question

    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.



    --
    Jason Teagle
    [email protected]

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured