[vtkusers] Updating VTK window in MFC

Sinan Koksoy sinankoksoy at psu.edu
Thu Apr 1 14:36:59 EST 2004


Dear VTK users,

I am working on a program for electromagnetic visualization for my graduate
studies, and my program is based on MFC MDI Doc/View architecture. I have
multiple view classes for each document class, so that for each problem, I can
display several different results.

My problem is that I when I generate a new frame of another view class, the view
is rendered correctly; however, when I want to change something in the scene
(such as toggling axes, or switching between solid/wireframe view, or standard
views, etc.) via an item in the mainframe menu, initially it doesn't work. Once
I click somewhere inside the child frame window, then all the menu commands
start working. Therefore, I believe it must have something to do with the
Window Procedure, and actually there was a message posted here in Jan'04, but
the solution was not explicitly stated, although somebody hinted that one has
to use the Win32 sendmessage() command. Since I am not an expert on VTK or MFC,
I have been stuck on this after spending so many hours on it.
Below are my codes:

// Here is the part where we create the new view inside the DOC class.
CFrameWnd* pChild2 = pTemplate->CreateNewFrame(this,NULL);
CView* pNewView = (CView *) pNewViewClass->CreateObject();

CCreateContext context;
context.m_pNewViewClass = NULL;
context.m_pCurrentDoc = this;
context.m_pNewDocTemplate = pTemplate;
context.m_pLastView = NULL;
context.m_pCurrentFrame = pChild2;

pNewView->Create(NULL, NULL, AFX_WS_DEFAULT_VIEW, CRect(0, 0, 0, 0),
   pChild2, AFX_IDW_PANE_FIRST+1, &context);

pChild2->RecalcLayout();
pNewView->SendMessage(WM_INITIALUPDATE, 0, 0); 
pNewView->OnInitialUpdate();
pChild2->SetActiveView(pNewView);
pChild2->SetActiveWindow();

The strange thing with this part is that if I use "AFX_IDW_PANE_FIRST" instead
of "AFX_IDW_PANE_FIRST+1", I don't experience the problem I described above;
however, the newly generated view blinks when I interact with the scene or
resize it, showing the initial view or going completely crazy.

// For the command I have in the VIEW class, there's the following
// item in the message map:
ON_COMMAND(ID_VIEW_MESHSOLIDVIEW, OnViewSolidOrWireFrameToggle)

// And here is the function in my VIEW class:
void CBase3DView::OnViewSolidOrWireFrameToggle() 
{
  if(m_bSolidView)
  { // solid->wireframe
    this->Actor->GetProperty()->SetRepresentationToWireframe();
    this->Actor->GetProperty()->SetLineWidth(1);
    m_bSolidView = FALSE;
  }
  else
  {// wireframe->solid
    this->Actor->GetProperty()->SetRepresentationToSurface();
    this->Actor->GetProperty()->SetLineWidth(2);
    m_bSolidView = TRUE;
  }
  Invalidate();
}
// And here is the Window Procedure that I have taken from the standard
// MFC sample.
LRESULT CBase3DView::WindowProc(UINT message, WPARAM wParam, LPARAM lParam) 
{
  switch (message)
  {
    //case WM_PAINT: 
    case WM_LBUTTONDOWN: 
    case WM_LBUTTONUP: 
    case WM_MBUTTONDOWN: 
    case WM_MBUTTONUP: 
    case WM_RBUTTONDOWN: 
    case WM_RBUTTONUP: 
    case WM_MOUSEMOVE:
    case WM_CHAR:
    case WM_TIMER:
      if (this->iren->GetInitialized())
      {
        return vtkHandleMessage2(this->m_hWnd, message, wParam, lParam,
this->iren);
      }
      break;
  }
 
  return CView::WindowProc(message, wParam, lParam);
}


I would truly appreciate it if somebody could give me any advice or suggestion
about this.
Regards,

Sinan Köksoy
sinankoksoy at psu.edu
Graduate Researcher in ECL/CSSL at the Pennsylvania State University




More information about the vtkusers mailing list