[vtkusers] RenderWindowInteractor and Win32

Dr. Peter Böttcher p.boettcher at anat.vetmed.uni-muenchen.de
Tue Feb 20 17:31:53 EST 2001


Dear VTK-Users!

I would like to implement vtkWin32RenderWindowInteractor in a
MFC-Application. Everything works good except the keystrokes. Any key
operation gives only a bell sound and no message is passed to the
MainDialog (::WindowProc(UINT message, WPARAM wParam, LPARAM lParam)). 


Any idea?

Thanks Peter.


The following is a abstract of my code:

BOOL CVtkTestDlg::OnInitDialog()
{
	CDialog::OnInitDialog();

	vtkConeSource* cone = vtkConeSource::New();
	vtkPolyDataMapper* mapper = vtkPolyDataMapper::New();
		mapper->SetInput(cone->GetOutput());
	vtkActor* actor = vtkActor::New();
		actor->SetMapper(mapper);

  this->Renderer->AddActor(actor);
  this->RenderWindow->SetParentId(this->m_hWnd);
  this->RenderWindow->SetWindowId(this->m_hWnd);
  this->RenderWindow->WindowInitialize();
		this->RenderWindow->AddRenderer(Renderer);
		this->Interactor->SetRenderWindow(RenderWindow);
		
	return TRUE;  // Geben Sie TRUE zurück, außer ein Steuerelement soll
den Fokus erhalten
}

void CVtkTestDlg::OnPaint() 
{
	if (IsIconic())
	{
		CPaintDC dc(this); // Gerätekontext für Zeichnen

		SendMessage(WM_ICONERASEBKGND, (WPARAM) dc.GetSafeHdc(), 0);

		// Symbol in Client-Rechteck zentrieren
		int cxIcon = GetSystemMetrics(SM_CXICON);
		int cyIcon = GetSystemMetrics(SM_CYICON);
		CRect rect;
		GetClientRect(&rect);
		int x = (rect.Width() - cxIcon + 1) / 2;
		int y = (rect.Height() - cyIcon + 1) / 2;

		// Symbol zeichnen
		dc.DrawIcon(x, y, m_hIcon);
	}
	else
	{
		if (!this->Interactor->GetInitialized())
			{
			this->Interactor->SetRenderWindow(this->RenderWindow);
			WNDPROC OldProc = (WNDPROC)GetWindowLong(this->m_hWnd,GWL_WNDPROC);
			this->Interactor->Initialize();
			SetWindowLong(this->m_hWnd,GWL_WNDPROC,(LONG)OldProc);
			}

    this->RenderWindow->Render();
    
		CDialog::OnPaint();
	}
}

LRESULT CVtkTestDlg::WindowProc(UINT message, WPARAM wParam, LPARAM
lParam) 
{
switch (message)
    {
    //case WM_PAINT: 
    case WM_CHAR:
    case WM_LBUTTONDOWN: 
    case WM_LBUTTONUP: 
    case WM_MBUTTONDOWN: 
    case WM_MBUTTONUP: 
    case WM_RBUTTONDOWN: 
    case WM_RBUTTONUP: 
    case WM_MOUSEMOVE:
	case WM_TIMER:
      if (this->Interactor->GetInitialized())
        {
        return vtkHandleMessage2(this->m_hWnd, message, wParam, lParam, 
                                 this->Interactor);
        }
      break;
    }
	return CDialog::WindowProc(message, wParam, lParam);
}





More information about the vtkusers mailing list