[vtkusers] Enabling use a ContextMenu with vtk and MFC (mouse-clickdetection)

John Platt jcplatt at dsl.pipex.com
Mon Feb 27 17:29:02 EST 2006


Hi Mark,

Have you tried adding an observer to your interactor for the right
button press event, something like this in your CView derived class ....

MyView.h

   vtkCallbackCommand* m_vtkMouseEventCBC;
   static void ProcessMouseEvents( vtkObject* object, unsigned long
event, 						void* clientdata, void*
calldata );

MyView.cpp

   m_vtkMouseEventCBC = vtkCallbackCommand::New();
   m_vtkMouseEventCBC->SetCallback( CMyView::ProcessMouseEvents );
   m_vtkMouseEventCBC->SetClientData( this );

   m_vtkInteractor->AddObserver( vtkCommand::RightButtonPressEvent, 
                                             m_vtkMouseEventCBC, 0.5 );


   void CMyView::ProcessMouseEvents(vtkObject* vtkNotUsed(object), 
                                    unsigned long event, 
                                    void* clientdata, 
                                    void* callData )
   {
      CMyView* self = reinterpret_cast< CMyView*>( clientdata );
      switch( event )
      {
         case vtkCommand::RightButtonPressEvent:
            TRACE("Right Button Down.\n" );
            self->DoSomeStuff();

            // Prevent others from handling this event.
            self->m_vtkMouseEventCBC->SetAbortFlag(1);
            break; 
	}
   }

HTH

John.

-----Original Message-----
From: vtkusers-bounces+jcplatt=dsl.pipex.com at vtk.org
[mailto:vtkusers-bounces+jcplatt=dsl.pipex.com at vtk.org] On Behalf Of
Mark Gooding
Sent: 27 February 2006 10:13
To: vtkusers
Subject: [vtkusers] Enabling use a ContextMenu with vtk and MFC
(mouse-clickdetection)

Hello all,

A while ago I emailed about trying to set up a ContextMenu when the
right mouse button is clicked on the vtkWindow in MFC. The problem was
that the vtkMFCWindow does not respond to the clicks (despite the
example having a function within it that appears to suggest it
should), instead the mouse action seems to passed directly to the
vtkWindowInteractor.

To solve this problem I think I should be subclassing
vtkWindowInteractorStyle, so that I can either remove the handling of
right mouse click (so that the window handles it) or modify it to pass
clicks directly to the CView class.

Does this sound like a sensible approach? Or is there a better/more
standard solution? I didn't want to set off programming without at
least knowing that I heading in the right direction!

Cheers,

Mark
_______________________________________________
This is the private VTK discussion list. 
Please keep messages on-topic. Check the FAQ at:
http://www.vtk.org/Wiki/VTK_FAQ
Follow this link to subscribe/unsubscribe:
http://www.vtk.org/mailman/listinfo/vtkusers





More information about the vtkusers mailing list