Refresh under MFC or wxMSW

Paul Hsieh pahsieh at usgs.gov
Wed Aug 25 21:57:33 EDT 1999


Hi Brian:

I don't know wxWindows, but here is what happens in Win32/MFC
regarding window redraw.

When a window is uncovered and needs to be redrawn, the 
message WM_PAINT is sent to the window. In the your vtk program, 
you need to respond to this message by invoking

    renWin->Render();

where renWin is the pointer to your instance of
vtkOpenGLWin32RenderWindow.

In win32 api programming (not using MFC), you would
would respond to window messages in the a callback function
typically called WndProc, although the name can vary.
You can see an example of this in the source code for 
vtkOpenGLWin32RenderWindow.cxx, because this code actually 
sets up a window. The callback function here is called MessageProc:

LRESULT vtkWin32OpenGLRenderWindow::MessageProc(HWND hWnd, UINT message, 
                                                WPARAM wParam, LPARAM lParam)
{
  switch (message) 
  {

    // handles various windows messages, such as WM_CREATE, WM_DESTROY, WM_SIZE, etc

    case WM_PAINT:
    {
        PAINTSTRUCT ps;
        BeginPaint(hWnd, &ps);
        if (this->ContextId) 
        {
          this->Render();    //****** This does the repainting of the vtk display *****
        }
        EndPaint(hWnd, &ps);
        return 0;
    }
    break;

    // more message handling
  }
  return DefWindowProc(hWnd, message, wParam, lParam);
}

If you are using MFC and the Doc/View architecture, the WM_PAINT
message is handled by a chain of function calls that evantually
ends in the OnDraw method of the "View" class. Therefore, you
override the OnDraw method. You can see an example of this in 
the Sample MFC application that is included in  the vtk source 
distribution. See the source code for vtkMFCRenderView.cpp in the 
Sample folder. (Note that the OnDraw method handles printing as well.)

void vtkMFCRenderView::OnDraw(CDC* pDC)
{
    // some initialization stuff

    if (pDC->IsPrinting())
    {
        // printing code...
    }
    else
    {
        this->RenderWindow->Render();   //***** this does the repainting of the vtk display***
    }   
    CView::OnDraw(pDC);
}

Finally, if you are using MFC but not the Doc/View architecture,
then your window display is probably handled by a child window
inside the application frame. This child window is a subclass
of CWnd. In this case the WM_PAINT message is handled by
the OnPaint method. So you override the OnPaint method,
something like

CMyChildWnd::OnPaint()
{
    renWin->Render();
}

Hope this helps. Gool luck.
Paul


Brian Alexander Todd wrote:

> I am working on a a vtkRenderWindow for wxWindows on Win95.
> Using vtkOpenGLWin32RenderWindow I can easily
> get the window drawn in my wxFrame by SetWindowId(HWND ...).
> This works beautifully.  The only problem I am having is
> that after the window becomes obscured by another window
> or goes off the edge of the screen it goes to background
> and doesn't redraw.
> 
> I am unfamiliar windows programming and need a bit of
> help.  What action am I to take to get the window redrawn.
> Is there somekind of OnExpose method or something I haven't
> overridden?  The wxWindows classes are extremely similar to
> MFC so anyone with experience there could probably help me.
>

Brian Alexander Todd wrote:
> 
> Dear vtkers with MFC or wxWindows expertise/interest,
> 
> I am working on a a vtkRenderWindow for wxWindows on Win95.
> Using vtkOpenGLWin32RenderWindow I can easily
> get the window drawn in my wxFrame by SetWindowId(HWND ...).
> This works beautifully.  The only problem I am having is
> that after the window becomes obscured by another window
> or goes off the edge of the screen it goes to background
> and doesn't redraw.
> 
> I am unfamiliar windows programming and need a bit of
> help.  What action am I to take to get the window redrawn.
> Is there somekind of OnExpose method or something I haven't
> overridden?  The wxWindows classes are extremely similar to
> MFC so anyone with experience there could probably help me.
> 
> On the otherhand perhaps I haven't handed off the pixel info
> from the Win32OpenGL to my window properly?
> 
> Thanks so much,
> Brian Todd
> 
>            _____________________________________________________
>   ________|                                                     |________
>   \       |   Brian Todd                email: bat5 at po.cwru.edu |       /
>    \      |   N.O.B.L.                 office: (216) 791-2407   |      /
>     \     |   C.W.R.U.                   home: (216) 368-4209   |     /
>     /     |   Cleveland, OH 44106         fax: (216) 368-4969   |     \
>    /      |_____________________________________________________|      \
>   /___________)                                              (__________\
> 
> -----------------------------------------------------------------------------
> This is the private VTK discussion list.  Please keep messages on-topic.
> Check the FAQ at: <http://www.automatrix.com/cgi-bin/vtkfaq>
> To UNSUBSCRIBE, send message body containing "unsubscribe vtkusers" to
> <majordomo at gsao.med.ge.com>.  For help, send message body containing
> "info vtkusers" to the same address.     Live long and prosper.
> -----------------------------------------------------------------------------


-----------------------------------------------------------------------------
This is the private VTK discussion list.  Please keep messages on-topic.
Check the FAQ at: <http://www.automatrix.com/cgi-bin/vtkfaq>
To UNSUBSCRIBE, send message body containing "unsubscribe vtkusers" to
<majordomo at gsao.med.ge.com>.  For help, send message body containing
"info vtkusers" to the same address.     Live long and prosper.
-----------------------------------------------------------------------------





More information about the vtkusers mailing list