[vtk-developers] Re: GUISupport directory ?

Andrew Maclean a.maclean at cas.edu.au
Tue Feb 15 05:55:18 EST 2005

I hope this helps ....

For a dialog it is mot much different from the MDI and SDI examples, except
you have to use the PreTranslateMessage if you want keyboard interaction. I
normally do something like this (this is based on the old MIDI/SDI samples
in the GUI directory) (they also had printing set up too):

//We need to allow the interactor to process commands from the keyboard so
we add the PreTranslateMessage override and modify the code as follows:

//! Will allow passing of keystrokes to VTK.
BOOL CDLGDlg::PreTranslateMessage(MSG* pMsg)
    // Only process keystrokes that emanate from the render window.

    CRect rect;

    bool inWindow = (pMsg->pt.x >= rect.left && pMsg->pt.x <= rect.right &&
                                    pMsg->pt.y >= rect.top && pMsg->pt.y <=

    if (inWindow)
        switch (pMsg->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:

        // Don't process the vtk quit keyboard command.

        if ( pMsg->message == WM_CHAR &&
            ( ( pMsg->wParam == 'Q' || pMsg->wParam == 'q' ) ||
            ( pMsg->wParam == 'E' || pMsg->wParam == 'e' ) ) )

        if ( VTKApp->IRen()->GetInitialized() )
            return vtkHandleMessage2(this->m_hWnd, pMsg->message,
pMsg->wParam, pMsg->lParam,



return CDialog::PreTranslateMessage(pMsg);


-----Original Message-----
From: vtk-developers-bounces at vtk.org [mailto:vtk-developers-bounces at vtk.org]
On Behalf Of Clinton Stimpson
Sent: Tuesday, 15 February 2005 03:53
To: de Boer Ingo
Cc: vtk-developers at vtk.org
Subject: RE: [vtk-developers] Re: GUISupport directory ?

Quoting de Boer Ingo <I.deBoer at polytec.de>:

> > The source is in the current CVS (VTK/GUISupport/MFC).
> Thanks... I just took a look at it...
> I have a question. You wrote this:
>   // setup the parent window
>   this->renWin->SetWindowId(this->GetSafeHwnd());
>   this->iren->SetRenderWindow(this->renWin);
>   this->iren->Initialize();
> I did in my samples something like:
>   // setup the parent window
>   this->renWin->SetWindowId(this->GetSafeHwnd());
>   this->renWin->SetParentId(this->GetParent()->GetSafeHwnd());
>   this->iren->SetRenderWindow(this->renWin);
>   this->iren->Initialize();
> and set the parent ID. Isn't it necessary to set the parent ID ?

I don't think it is necessary.  The only place in the VTK code it makes a
difference is in the resizing window code, which is redundent, because MFC
is already doing that.

> Did you try my samples ?

I didn't.  I realize they were there in the bug tracker when I took this
code from the already existing examples and modified it.

> In my opinion, three samples would be needed, MDI,SDI and
> dialog-based. This is what people do. The only trouble
> with the dialog-based application I had, was, that I
> could not do a double click. For the MDI and SDI it worked
> fine.

We have an MDI and SDI sample already that uses this new class.  Do you want
to try it in a dialog?

> In WindowProc you set the focus for the button down.
> Is this necessary ? If yes, shouldn't you set the focus

Doing it on wheel mouse is preference, and I think most people want that.  A
window has to have input focus before it can get a key event.  So it is
redundent to set focus on key down because it already has focus.

> In the OnSize function, wouldn't a call like
> this->iren->UpdateSize(cx, cy);
> be enough ?

Yeah, it is.
I think it is weird that a window has already been sized and it is told to
be sized again recursively in VTK.  That is what iren->UpdateSize does.  My
code I had there prevents the recursion from happening and gets the same
work done.

The OnPaint function doesn't pass in a CDC to do printing like that.  It is
the OnDraw functions from CView that has that.  I don't think CWnd has an
OnDraw function.
Perhaps we have 4 widget classes in there, then some of them can support
printing like that.


> How about extending the OnPaint with printing ?
> Like this (pseudo, taken from my code)
> if ( pDC->IsPrinting() )
> {
> 	// Obtain the size of the printer page in pixels.
> 	int cxPage = pDC->GetDeviceCaps(HORZRES);
> 	int cyPage = pDC->GetDeviceCaps(VERTRES);
> 	// Get the size of the window in pixels.
> 	int *size = this->pvtkWin32OpenGLRW->GetSize();
> 	int cxWindow = size[0];
> 	int cyWindow = size[1];
> 	float fx = float(cxPage) / float(cxWindow);
> 	float fy = float(cyPage) / float(cyWindow);
> 	float scale = min(fx,fy);
> 	int x = int(scale * float(cxWindow));
> 	int y = int(scale * float(cyWindow));
> 	this->pvtkWin32OpenGLRW->SetupMemoryRendering(cxWindow, cyWindow,
> pDC->GetSafeHdc());
> 	this->pvtkWin32OpenGLRW->Render();
> 	HDC memDC = this->pvtkWin32OpenGLRW->GetMemoryDC();
> 	this->pvtkWin32OpenGLRW->ResumeScreenRendering();
> }
> else
> {
> 	// TODO: add draw code for native data here
> 	if (this->pvtkWin32RenderWI->GetInitialized())
> 	{
> 		this->pvtkWin32OpenGLRW->Render();
> 	}
> }
> greets
>   Ingo

vtk-developers mailing list
vtk-developers at vtk.org

More information about the vtk-developers mailing list