[vtkusers] Re: Single/Multiple Document Examples for MFC
Nigel Nunn
nNunn at ausport.gov.au
Sat Feb 2 14:59:25 EST 2002
Wrt MFC demos for Vtk 4 Sebastien BARRE wrote:
> At 1/30/2002 04:08 PM, Andrew J. P. Maclean wrote:
>
> > I have two examples, one for a Single Document Interface
> > (SDI) and the other for a Multiple Document Interface (MDI)
> > using MFC. Each example has a compressed html file (about 18k)
> > of instructions. Does anyone at Kitware want to look at it?
> > I would suggest that they could go into the directory tree
> > at: VTK\Examples\GUI\Win32
> >
> Go ahead, send them to me privately.
Andrew's examples are a neat repackaging of the old Sample,
and the well-crafted HTML instructions are great. However,
I feel the main shortcoming of the existing Sample is not
that it splits support for Vtk over 2+1 classes, but that
it buries the message handlers in WindowProc(). I used MFC
at a fairly advanced level for 5 years before ever meeting
a "WindowProc". Those getting started with both MFC and Vtk
might find things easier if we explicitly exposed the usual
set of message handlers in the normal MFC way: message maps.
//------------------------------------------------
class vtkMFCRenderView : public CView
//------------------------------------------------
{
protected:
vtkMFCRenderView();
DECLARE_DYNCREATE(vtkMFCRenderView)
vtkRenderer *m_Ren;
vtkWin32OpenGLRenderWindow *m_RenWin;
vtkWin32RenderWindowInteractor *m_IRen;
// etc.
...
protected:
//{{AFX_MSG(vtkMFCRenderView)
afx_msg int OnCreate(LPCREATESTRUCT lpCreateStruct);
afx_msg void OnSize(UINT nType, int cx, int cy);
afx_msg BOOL OnEraseBkgnd(CDC* pDC);
afx_msg void OnTimer(UINT nIDEvent);
afx_msg void OnChar(UINT nChar, UINT nRepCnt, UINT nFlags);
afx_msg void OnMouseMove(UINT nFlags, CPoint point);
afx_msg void OnLButtonDown(UINT nFlags, CPoint point);
afx_msg void OnLButtonUp(UINT nFlags, CPoint point);
afx_msg void OnMButtonDown(UINT nFlags, CPoint point);
afx_msg void OnMButtonUp(UINT nFlags, CPoint point);
afx_msg void OnRButtonDown(UINT nFlags, CPoint point);
afx_msg void OnRButtonUp(UINT nFlags, CPoint point);
afx_msg void OnEditCopy();
//}}AFX_MSG
DECLARE_MESSAGE_MAP()
};
A user can have their way in the usual MFC handler, and
when done, pass control through to vtkHandleMessage2(...);
//------------------------------------------------
void vtkMFCRenderView::OnLButtonDown(UINT nFlags, CPoint point)
//------------------------------------------------
{
if (nFlags & MK_CONTROL)
{
my_pick_operation();
go_wild();
}
CallInteractor(WM_LBUTTONDOWN, (WPARAM)(UINT)(nFlags),
MAKELPARAM((point.x), (point.y)));
}
CallInteractor(..) wraps the call to vtkHandleMessage2:
//------------------------------------------------
LRESULT vtkMFCRenderView::CallInteractor
(
UINT uMsg,
WPARAM wParam,
LPARAM lParam
)
//------------------------------------------------
{
// Replaces... WindowProc(UINT, WPARAM, LPARAM)
// Maintain individual event handlers that pass
// control here.
if (m_IRen->GetInitialized())
{
return vtkHandleMessage2(m_hWnd, uMsg, wParam, lParam, m_IRen);
}
return 0;
}
Of course, this highlights the problem: many of us using
Vtk under MFC have customised approaches to exploiting
the power of MFC to orchestrate the wonders of Vtk :-)
MFC and Win32 are vast -- may be why some folks give
up after a mere six months and start looking around for
less [huge/magical/awesome/beautiful] solutions?
thanks,
Nigel
More information about the vtkusers
mailing list