<div dir="ltr"><div>try  add<br><br>renWin-&gt;SetParentId(handler);<br><br></div>to<br><div>drawSphere(HWND handler)<br><br></div><div>vtk source has Win32Cone.cxx example which might be useful<br><br></div><div>Alex<br></div>
<div><br></div></div><div class="gmail_extra"><br><br><div class="gmail_quote">On Wed, May 22, 2013 at 2:36 AM, Le Minh Nhat <span dir="ltr">&lt;<a href="mailto:nhatleminh10@gmail.com" target="_blank">nhatleminh10@gmail.com</a>&gt;</span> wrote:<br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir="ltr"><div><div><div><div>Hi everyone,<br></div>I am quite new to Vtk, and I have tried to create a sphere using Vtk. However, the rendering window is separated from my existing window. Here is my source code:<br>

<br>#include &lt;windows.h&gt;<br><br>#include &quot;vtkSphereSource.h&quot;<br>#include &quot;vtkPolyDataMapper.h&quot;<br>#include &quot;vtkProperty.h&quot;<br>#include &quot;vtkActor.h&quot;<br>#include &quot;vtkRenderWindow.h&quot;<br>

#include &quot;vtkRenderer.h&quot;<br>#include &quot;vtkRenderWindowInteractor.h&quot;<br>#include &quot;vtkWin32OpenGLRenderWindow.h&quot;<br>#include &quot;vtkNew.h&quot;<br>#include &quot;vtkCamera.h&quot;<br>//<br>//<br>

void drawSphere(HWND handler)<br>{<br>  // create sphere geometry<br>  vtkSphereSource *sphere = vtkSphereSource::New();<br>  sphere-&gt;SetRadius(1.0);<br>  sphere-&gt;SetThetaResolution(18);<br>  sphere-&gt;SetPhiResolution(18);<br>

<br>  // map to graphics library<br>  vtkPolyDataMapper *map = vtkPolyDataMapper::New();<br>  map-&gt;SetInput(sphere-&gt;GetOutput());<br><br>  // actor coordinates geometry, properties, transformation<br>  vtkActor *aSphere = vtkActor::New();<br>

  aSphere-&gt;SetMapper(map);<br>  aSphere-&gt;GetProperty()-&gt;SetColor(0,0,1); // sphere color blue<br><br>  // a renderer and render window<br>  vtkRenderer *ren1 = vtkRenderer::New();<br>  vtkRenderWindow *renWin = vtkRenderWindow::New();<br>

  <br>  renWin-&gt;AddRenderer(ren1);<br><br>  // an interactor<br>  vtkRenderWindowInteractor *iren = vtkRenderWindowInteractor::New();<br>  iren-&gt;SetRenderWindow(renWin);<br><br>  // add the actor to the scene<br>  ren1-&gt;AddActor(aSphere);<br>

  ren1-&gt;SetBackground(1,1,1); // Background color white<br><br>  // render an image (lights and cameras are created automatically)<br>  //renWin-&gt;InitializeFromCurrentContext();<br>  renWin-&gt;Render();<br>  <br><br>

  // begin mouse interaction<br>  iren-&gt;Start();<br><br>  // release memory and return<br>  sphere-&gt;Delete();<br>  map-&gt;Delete();<br>  aSphere-&gt;Delete();<br>  ren1-&gt;Delete();<br>  renWin-&gt;Delete();<br>  iren-&gt;Delete();<br>

  <br>}<br><br>LRESULT CALLBACK WndProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam)<br>{<br>    switch(msg)<br>    {<br>        <br><br>        case WM_CLOSE:<br>            DestroyWindow(hwnd);<br>        break;<br>

<br>        case WM_DESTROY:<br>            PostQuitMessage(0);<br>        break;<br><br>        case WM_PAINT:<br>            drawSphere(hwnd);<br>        break;<br><br>        default:<br>            return DefWindowProc(hwnd, msg, wParam, lParam);<br>

    }<br>    return 0;<br>}<br><br>int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nCmdShow)<br>{<br>    WNDCLASSEX wc;<br>    HWND hwnd;<br>    MSG Msg;<br><br>    wc.cbSize            = sizeof(WNDCLASSEX);<br>

    wc.style            = 0;<br>    wc.lpfnWndProc        = WndProc;<br>    wc.cbClsExtra        = 0;<br>    wc.cbWndExtra        = 0;<br>    wc.hInstance        = hInstance;<br>    wc.hIcon            = LoadIcon(NULL, IDI_APPLICATION);<br>

    wc.hCursor            = LoadCursor(NULL, IDC_ARROW);<br>    wc.hbrBackground    = (HBRUSH)(COLOR_WINDOW+1);<br>    wc.lpszMenuName        = NULL;<br>    wc.lpszClassName    = &quot;mySphere&quot;;<br>    wc.hIconSm            = LoadIcon(NULL, IDI_APPLICATION);<br>

<br>    if(!RegisterClassEx(&amp;wc))<br>    {<br>        MessageBox(NULL, &quot;Window Registration Failed!&quot;, &quot;Error!&quot;, MB_ICONEXCLAMATION | MB_OK);<br>        return 0;<br>    }<br><br>    hwnd = CreateWindowEx(<br>

        WS_EX_CLIENTEDGE,<br>        &quot;mySphere&quot;,<br>        &quot;Sphere&quot;,<br>        WS_OVERLAPPEDWINDOW,<br>        CW_USEDEFAULT, CW_USEDEFAULT, 240, 120,<br>        NULL, NULL, hInstance, NULL);<br><br>

    if(hwnd == NULL)<br>    {<br>        MessageBox(NULL, &quot;Window Creation Failed!&quot;, &quot;Error!&quot;,<br>            MB_ICONEXCLAMATION | MB_OK);<br>        return 0;<br>    }<br><br>    ShowWindow(hwnd, nCmdShow);<br>

    UpdateWindow(hwnd);<br><br>    while(GetMessage(&amp;Msg, NULL, 0, 0) &gt; 0)<br>    {<br>        TranslateMessage(&amp;Msg);<br>        DispatchMessage(&amp;Msg);<br>    }<br>    return Msg.wParam;<br>}<br><br></div>

Anyone has any idea how to set the rendering window and the existing window to be one! Any response will be appreciated.<br></div>Best regards,<br></div>Bent<br></div>
<br>_______________________________________________<br>
Powered by <a href="http://www.kitware.com" target="_blank">www.kitware.com</a><br>
<br>
Visit other Kitware open-source projects at <a href="http://www.kitware.com/opensource/opensource.html" target="_blank">http://www.kitware.com/opensource/opensource.html</a><br>
<br>
Please keep messages on-topic and check the VTK FAQ at: <a href="http://www.vtk.org/Wiki/VTK_FAQ" target="_blank">http://www.vtk.org/Wiki/VTK_FAQ</a><br>
<br>
Follow this link to subscribe/unsubscribe:<br>
<a href="http://www.vtk.org/mailman/listinfo/vtkusers" target="_blank">http://www.vtk.org/mailman/listinfo/vtkusers</a><br>
<br></blockquote></div><br></div>