更改后的InitInstance 写一遍
时间: 2024-04-13 14:30:06 浏览: 54
当然,下面是根据您的要求修改后的InitInstance函数代码:
```cpp
BOOL InitInstance(HINSTANCE hInstance, int nCmdShow)
{
hInst = hInstance; // 将实例句柄存储在全局变量中
HWND hWnd = CreateWindowW(szWindowClass, szTitle, WS_OVERLAPPEDWINDOW,
CW_USEDEFAULT, 0, CW_USEDEFAULT, 0, nullptr, nullptr, hInstance, nullptr);
if (!hWnd)
{
return FALSE;
}
vtkSmartPointer<vtkRenderWindow> renderWindow = vtkSmartPointer<vtkRenderWindow>::New();
renderWindow->SetWindowId(reinterpret_cast<void*>(hWnd));
renderWindow->SetSize(600, 600);
vtkSmartPointer<vtkRenderer> ren1 = vtkSmartPointer<vtkRenderer>::New();
ren1->SetBackground(0.1, 0.2, 0.4);
vtkSmartPointer<vtkConeSource> cone = vtkSmartPointer<vtkConeSource>::New();
cone->SetHeight(3.0);
cone->SetRadius(1.0);
cone->SetResolution(10);
vtkSmartPointer<vtkPolyDataMapper> coneMapper = vtkSmartPointer<vtkPolyDataMapper>::New();
coneMapper->SetInputConnection(cone->GetOutputPort());
vtkSmartPointer<vtkActor> coneActor = vtkSmartPointer<vtkActor>::New();
coneActor->SetMapper(coneMapper);
ren1->AddActor(coneActor);
ren1->SetActiveCamera(ren1->GetActiveCamera());
ren1->ResetCamera();
renderWindow->AddRenderer(ren1);
vtkSmartPointer<vtkRenderWindowInteractor> iren = vtkSmartPointer<vtkRenderWindowInteractor>::New();
iren->SetRenderWindow(renderWindow);
vtkSmartPointer<vtkInteractorStyleTrackballCamera> style = vtkSmartPointer<vtkInteractorStyleTrackballCamera>::New();
iren->SetInteractorStyle(style);
vtkSmartPointer<vtkBoxWidget> boxWidget = vtkSmartPointer<vtkBoxWidget>::New();
boxWidget->SetInteractor(iren);
boxWidget->SetPlaceFactor(1.25);
boxWidget->SetProp3D(coneActor);
boxWidget->PlaceWidget();
vtkSmartPointer<vtkMyCallback> callback = vtkSmartPointer<vtkMyCallback>::New();
boxWidget->AddObserver(vtkCommand::InteractionEvent, callback);
boxWidget->On();
iren->Initialize();
iren->Start();
ShowWindow(hWnd, nCmdShow);
UpdateWindow(hWnd);
renderWindow->Render();
return TRUE;
}
```
请注意,在最后调用了`renderWindow->Render()`方法来触发VTK的渲染过程,并在Win32窗口中显示VTK渲染结果。
希望这次的修改能够解决问题。如果问题仍然存在,请提供更多关于您的代码和环境的信息,以便我能够更具体地帮助您。
阅读全文