[vtkusers] vtkMFCView

andypotts andypotts at ntlworld.com
Wed Nov 29 17:29:37 EST 2000


Hi all vtk users,

I have been looking at ways to solve the MFC/MDI problem that occurs with the vtk MFC sample that comes as part of the C++ setup implementation of the vtk library. 
The problem being that the vtkMFC implementation becomes unstable when any more than about four windows are created from the Window-New file menu or the File-New menu option.
Initially I got around this problem by implementing a version of the vtkWin32OpenGLRenderWindow that cleaned up the DeviceContext in almost every handler that used it. That is, all handlers that made calls to the wglMakeCurrent functions. This implementation actually involved a call to ReleaseDC in each handler and a corresponding GetDC call prior to calling MakeCurrent. My reasoning behind this was based on previous knowledge about OpenGL and Device Contexts.

This method worked well and allowed me to have any number of windows open from the Window-New file option, also the File-New menu option. Basically this made the vtkMFC application stable as far as the graphics system and MFC was concerned and allowed me to open as many windows as required.

However, since that time I've managed to come accross an even more efficient method of making the vtkMFC application work with as many windows as required. This new implementation requires no modification to the vtkWin32OpenGLRenderWindow. All that is required is a slight modification to the PreCreateWindow method in the vtkMFCView.

The following lines of code are from the original sample of the vtkMFC sample.

BOOL vtkMFCView::PreCreateWindow(CREATESTRUCT& cs) 
{
     // TODO: Add your specialized code here and/or call the base class
     //  the CREATESTRUCT cs
    cs.style |= WS_CLIPSIBLINGS | WS_CLIPCHILDREN | CS_OWNDC;

    return CView::PreCreateWindow(cs);
}

This is replaced by the following implementation:

BOOL vtkMFCView::PreCreateWindow(CREATESTRUCT& cs) 
{
     // these styles are requested by OpenGL
     cs.style |= WS_CLIPSIBLINGS | WS_CLIPCHILDREN;

     // these styles are meant for a use of this class in a MDI application
     cs.lpszClass = AfxRegisterWndClass(CS_OWNDC | CS_HREDRAW | CS_VREDRAW);

     return CView::PreCreateWindow(cs);
}

When this simple modification is made, the vtkMFC sample (or any other application based around MFC/MDI) runs without any hitches. I have tried this out and safely opened as many as twenty windows without any problems, although this is a bit extreme it illustrates that the vtk and MFC/MDI can at last operate in a useful error free implementation.

Obviously the desired implementation would be one with probably an XY, XZ, YZ, and an isometric view of the test sample, however each user of this technique will have thier own requirements.

Hope this helps
Andy Potts.

andypotts at ntlworld.com

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.vtk.org/pipermail/vtkusers/attachments/20001129/a8dbd0e4/attachment.htm>


More information about the vtkusers mailing list