[vtkusers] Visual C++ forms

T.R.Shashwath trshash at gmail.com
Sat Oct 3 14:47:30 EDT 2009


On Monday 28 Sep 2009 5:36:23 pm Renato Cesar Pompeu wrote:
> Hello all,
> 
> 
> 
> I'm new in VTK. I would like to make some applications using VTK and Visual
>  C++ 2008 windows forms. Could anyone help me? Are there some installation
>  tutorials with examples?

Hi,

I don't have any working examples I can readily show you, but what you need to 
do is have a hosting control (say a Panel), create a vtkRenderWindow and set 
its parent id as the panel's handle.

Generally, something like this:

renWin->SetParentId( myHostingControl->Handle.ToPointer() );

You also need to handle resizing by yourself, since the renwin doesn't know 
when the parent has resized. Handle OnPaint on the hosting control, and call 
something like this:

renWin->SetSize(myHostingControl->Width,myHostingControl->Height);

Apart from that, if your vtk objects are members of a managed class, be sure 
to use the finalizer (like C++'s destructor, but written as !ClassName() 
instead of ~ClassName() ) as follows:

MyClass::!MyClass()
{
	if (this->myVtkObject)
		this->myVtkObject->Delete();
	this->myVtkObject = nullptr;
}

This way, your resources will get cleaned up properly. Otherwise you'll end up 
with leaks.

Regards,
Shash



More information about the vtkusers mailing list