Wed, 09/17/2003 - 18:58
class CMy3dPanel01Ctrl : public COleControl
{
DECLARE_DYNCREATE(CMy3dPanel01Ctrl)
private:
Handle_Graphic3d_WNTGraphicDevice myGraphicDevice;
Handle_V3d_Viewer myViewer;
Handle_AIS_InteractiveContext myAISContext;
Handle_V3d_View myView;
........;
/*
public:
// Constructor
CMy3dPanel01Ctrl();
// Memeber virables
Handle(Graphic3d_WNTGraphicDevice) GetGraphicDevice() const
{ return myGraphicDevice; };
Handle_V3d_Viewer GetViewer()
{ return myViewer; };
Handle_AIS_InteractiveContext GetAISContext()
{ return myAISContext; };
.............
................
CMy3dPanel01Ctrl::CMy3dPanel01Ctrl()
{
InitializeIIDs(&IID_DMy3dPanel01, &IID_DMy3dPanel01Events);
// 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,CMy3dPanel01Ctrl::m_hWnd );
AfxMessageBox ("after WNT_Window");
/////////////////////////////////////////////
//////////////////////////////////////////////
// no problem in the above-mention codes
myView->SetWindow(aWNTWindow); // here is the problem
/////////////////////////////////////////
////////////////////////////////////////
////////////////////////////////////////
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;
}
Wed, 09/17/2003 - 20:17
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;
}
Thu, 09/18/2003 - 13:32
Thank you very much, Neil.
Terry
Sat, 05/08/2004 - 09:19
-()-
.
Sat, 05/08/2004 - 09:40
²»ÒªÔÚ¹¹Ô캯ÊýÖгõʼ»¯ÕâЩÊÓͼÀà¶ÔÏó£¬ÒòΪÏÂÃæÕâ¾ä»°ÓÐÎÊÌ⣺
// Get the HWnd (Windows Handle of this OLE Control)
//HWNd theWindowHandle=CMy3dPanel01Ctrl::Handle;
CMy3dPanel01Ctrl¶ÔÏóʵÀýËäÈ»±»new³öÀ´£¬µ«ÊÇÓйش°¿ÚµÄHandle×ÊÔ´»¹Ã»Óд´½¨£¬¾ßÌå´´½¨ÐèÒªÏÔʾµ÷ÓÃÆäCreateº¯Êý£¬ÄÇÄ©ÔÚÄãµÄ¿Ø¼þÖУ¬ÐèÒªÖØÔØ
OnCreate()º¯Êý£¬È»ºó½«ÄãÔÚ¹¹Ô캯ÊýÖÐдµÄÕⲿ·Ö´úÂ븴ÖƵ½ÀïÃæÈ¥£¬¼´¿É¡£
ÎÒµÄÀý×ÓÊÇ£º
int CG_3DViewerCtrl::OnCreate(LPCREATESTRUCT lpCreateStruct)
{
if (COleControl::OnCreate(lpCreateStruct) == -1)//´´½¨´°¿Ú×ÊÔ´µÄÖØÔص÷ÓÃ
return -1;
// TODO: Add your specialized creation code here
WNT_Window aWNTWindow(m_GraphicDevice,GetSafeHwnd());
m_Viewer = new Handle(V3d_Viewer(m_GraphicDevice, (short *) "Visu3D", ""));//;
m_Viewer->SetDefaultLights();
m_Viewer->SetLightOn();
// Create an interactive context based on the myViewer
m_AISContext = new AIS_InteractiveContext(m_Viewer);
// Get the HWnd (Windows Handle of this OLE Control)
HWND theWindowHandle = this->m_hWnd;//²»Ê¹ÓÃthisÒ²¿ÉÒÔ£¬Ö±½Óдm_hWnd¡£
// Create the 3D view
m_PView = myViewer->CreateView();
// set the default mode in wireframe ( not hidden line ! )
m_PView->SetDegenerateModeOn();
// store for restore state after rotation (witch is in Degenerated mode)
myDegenerateModeIsOn = Standard_True;
// Create a 3D display window on the current control window
Handle(WNT_Window) aWNTWindow = new WNT_Window(myGraphicDevice,GetSafeHwnd());
AfxMessageBox ("after WNT_Window");
m_PView->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 ... )
m_CurrentMode = CurAction3d_Nothing;
return 0;
}
ÁíÍ⣬ÏÂÃæÕâ¾ä»°Ò²ÓÐÎÊÌ⣺
Handle(WNT_Window) aWNTWindow = new WNT_Window(myGraphicDevice,CMy3dPanel01Ctrl::m_hWnd );
m_hWndÊÇCMy3dPanel01CtrlµÄ³ÉÔ±£¬µ«²»ÊǾ²Ì¬³ÉÔ±£¬ËùÒÔÄãÕâÑùµ÷ÓÃËü¿Ï¶¨³öÎÊÌâ¡£
ÕâÀïÓëdelphiÖеĴ°¿Ú¾ä±ú²»Í¬¡£ÕýÈ·µÄÊÇҪʹÓÃassert(m_hWnd == NULL);¼ì²âÒ»°ÑÏÈ£¡
ÔÚVCÖУ¬Ò»¸öMFC¿ò¼ÜÅÉÉú´°¿Ú£¬»òÕßʹÓÃMFC´´½¨Ò»¸öOCXµÄ»°£¬Äã×îºÃÖØÔØWM_CREATEʼþ£¬ÖØдOnCreate()º¯Êý£¬ÔÚÆäÖгõʼ»¯¶ÔÏóʵÀý£¬È»ºóÔÚOnDrawÖÐʵÏֿؼþ»æÖƵķ½·¨¡£
ÒÔÉÏʹÓÃÖÐÎÄ£¬ÒòΪÎÒÖªµÀÄãÊÇÄÜ¿´¶®µÄ£¬ÎÒÃÇÔÚMSNÉÏÁĹý¡£:-)
jianghp@vip.sina.com