I think the problem is that your CMy3dPanel01Ctrl::m_hWnd is actually NULL at this point of construction of the control - this does not cause the WNT_Window to fail, but it will cause the failure in SetWindow. I got around this for my ActiveX control by moving all the OpenCascade initialisation out of the control's constructor into a new function Initialise3DView which I then call from my VB app.
I don't think the C++ purists would approve of this, but it works for me!
Also in the WNT_Window constructor I used GetSafeHwnd() instead of your CMy3dPanel01Ctrl::m_hWnd - I don't know if this will make any difference.
Good luck!
Neil
CMy3dPanel01Ctrl::CMy3dPanel01Ctrl()
{
InitializeIIDs(&IID_DMy3dPanel01, &IID_DMy3dPanel01Events);
}
CMy3dPanel01Ctrl::Initialise3DView()
{
// Create the Graphic Device created
try
{myGraphicDevice = new Graphic3d_WNTGraphicDevice();}
catch(Standard_Failure)
{AfxMessageBox("Fatal Error During Graphic Initialisation");};
// Create myViewer as a center to manage many 3d_views
// Via myViewer to initialize the default settings for each 3d_views
myViewer = new V3d_Viewer(myGraphicDevice,(short *) "Visu3D");
myViewer->SetDefaultLights();
myViewer->SetLightOn();
// Create an interactive context based on the myViewer
myAISContext = new AIS_InteractiveContext(myViewer);
// Get the HWnd (Windows Handle of this OLE Control)
//HWNd theWindowHandle=CMy3dPanel01Ctrl::Handle;
// Create the 3D view
myView = myViewer->CreateView();
// set the default mode in wireframe ( not hidden line ! )
myView->SetDegenerateModeOn();
// store for restore state after rotation (witch is in Degenerated mode)
myDegenerateModeIsOn = Standard_True;
AfxMessageBox ("before WNT_Window");
// Create a 3D display window on the current control window
Handle(WNT_Window) aWNTWindow = new WNT_Window(myGraphicDevice,GetSafeHwnd());
AfxMessageBox ("after WNT_Window");
myView->SetWindow(aWNTWindow);
AfxMessageBox ("after myView->SetWindow");
//Map the 3D display window on the current control's window
if (!aWNTWindow->IsMapped()) aWNTWindow->Map();
Standard_Integer w=100 , h=100 ; /* Debug Matrox */
aWNTWindow->Size (w,h) ; /* Keeps me unsatisfied (rlb)..... */
/* Resize is not supposed to be done on */
/* Matrox */
/* I suspect another problem elsewhere */
::PostMessage ( GetSafeHwnd () , WM_SIZE , SIZE_RESTORED , w + h*65536 ) ;
// store the mode ( nothing , dynamic zooming, dynamic ... )
myCurrentMode = CurAction3d_Nothing;
}