<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML><HEAD>
<META http-equiv=Content-Type content="text/html; charset=iso-8859-1">
<META content="MSHTML 5.50.4134.600" name=GENERATOR>
<STYLE></STYLE>
</HEAD>
<BODY bgColor=#ffffff>
<DIV><FONT face=Arial size=2>Hi all vtk users,</FONT></DIV>
<DIV><FONT face=Arial size=2></FONT>&nbsp;</DIV>
<DIV><FONT face=Arial size=2>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&nbsp;implementation of the vtk library. </FONT></DIV>
<DIV><FONT face=Arial size=2>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.</FONT></DIV>
<DIV><FONT face=Arial size=2>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.</FONT></DIV>
<DIV><FONT face=Arial size=2></FONT>&nbsp;</DIV>
<DIV><FONT face=Arial size=2>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.</FONT></DIV>
<DIV><FONT face=Arial size=2></FONT>&nbsp;</DIV>
<DIV><FONT face=Arial size=2>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.</FONT></DIV>
<DIV><FONT face=Arial size=2></FONT>&nbsp;</DIV>
<DIV><FONT face=Arial size=2>The following lines of code are from the original 
sample of the vtkMFC sample.</FONT></DIV>
<DIV><FONT face=Arial size=2></FONT>&nbsp;</DIV>
<DIV><FONT face=Arial size=2>BOOL vtkMFCView::PreCreateWindow(CREATESTRUCT&amp; 
cs) <BR>{<BR>&nbsp;&nbsp;&nbsp;&nbsp; // TODO: Add your specialized code here 
and/or call the base class<BR>&nbsp;&nbsp;&nbsp; &nbsp;//&nbsp; the CREATESTRUCT 
cs<BR>&nbsp;&nbsp;&nbsp; cs.style |= WS_CLIPSIBLINGS | WS_CLIPCHILDREN | 
CS_OWNDC;</FONT></DIV>
<DIV><FONT face=Arial size=2></FONT>&nbsp;</DIV>
<DIV><FONT face=Arial size=2>&nbsp;&nbsp;&nbsp; return 
CView::PreCreateWindow(cs);</FONT></DIV>
<DIV><FONT face=Arial size=2>}<BR></FONT></DIV>
<DIV><FONT face=Arial size=2>This is replaced by the following 
implementation:</FONT></DIV>
<DIV><FONT face=Arial size=2></FONT>&nbsp;</DIV>
<DIV><FONT face=Arial size=2>BOOL vtkMFCView::PreCreateWindow(CREATESTRUCT&amp; 
cs) <BR>{<BR>&nbsp;&nbsp;&nbsp;&nbsp;</FONT><FONT face=Arial size=2> // these 
styles are requested by OpenGL<BR>&nbsp;&nbsp;&nbsp; &nbsp;cs.style |= 
WS_CLIPSIBLINGS | WS_CLIPCHILDREN;</FONT></DIV>
<DIV><FONT face=Arial size=2></FONT>&nbsp;</DIV>
<DIV><FONT face=Arial size=2>&nbsp;&nbsp;&nbsp;&nbsp; // these styles are meant 
for a use of this class in a MDI application<BR>&nbsp;&nbsp;&nbsp; 
&nbsp;cs.lpszClass = AfxRegisterWndClass(CS_OWNDC | CS_HREDRAW | 
CS_VREDRAW);</FONT></DIV>
<DIV><FONT face=Arial size=2></FONT>&nbsp;</DIV>
<DIV><FONT face=Arial size=2>&nbsp;&nbsp;&nbsp; &nbsp;return 
CView::PreCreateWindow(cs);<BR>}<BR></FONT></DIV>
<DIV><FONT face=Arial size=2>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.</FONT></DIV>
<DIV><FONT face=Arial size=2></FONT>&nbsp;</DIV>
<DIV><FONT face=Arial size=2>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.</FONT></DIV>
<DIV><FONT face=Arial size=2></FONT>&nbsp;</DIV>
<DIV><FONT face=Arial size=2>Hope this helps</FONT></DIV>
<DIV><FONT face=Arial size=2>Andy Potts.</FONT></DIV>
<DIV><FONT face=Arial size=2></FONT>&nbsp;</DIV>
<DIV><FONT face=Arial size=2><A 
href="mailto:andypotts@ntlworld.com">andypotts@ntlworld.com</A></FONT></DIV>
<DIV><FONT face=Arial size=2>&nbsp;</DIV></FONT></BODY></HTML>