OCX containment
Ed Kaltenbach -- kaltenba@ataway.aptec.com Wednesday, February 14, 1996 Hello All, I am using MSVC++ 4.0 on Windows 95 My view is derived from CView. I allow the user to add OLE Controls to the view by clicking where he/she wants the new OCX to be created. To test I create an OCX with MSVC++ 4.0 called TestocxCtrl. It is just the basic ellipse control that gets created by VC++. I did not add any code of my own to it yet. I am having some odd problems when I exit my program. Here is how I add the control to the view: void CContView::OnLButtonDblClk(UINT nFlags, CPoint point) { HRESULT hr = AfxGetClassIDFromString("TESTOCX.TestocxCtrl.1", &clsid); // some error checking is done here m_windows[m_numControls]->CreateControl(clsid, "Channel", WS_VISIBLE, tempRect, this, WM_USER + m_numControls, NULL,FALSE,NULL); LPUNKNOWN temp = m_windows[m_numControls]->GetControlUnknown(); HRESULT res = temp->QueryInterface(IID_IOleObject, (void**)&m_OleControls[m_numControls]); . . . Now I want to call DoVerb to hide the control and I will call OleDraw in OnDraw for the view. This way I can get mouse clicks in the rect containing the OCX. m_OleControls[m_numControls]->DoVerb(OLEIVERB_HIDE,0,???,0,m_hWnd,&tempRect); What should I pass as the 3rd parameter to DoVerb? I tried passing the view "(IOleClientSite*)this", and everything seems to work fine, but when I exit the program I get an ASSERT in wincore.cpp line 360. The line is: ASSERT( pWnd != NULL); I then tried to call GetClientSite for the IOleObject: m_OleControls[m_numControls]->GetClientSite(&temp_clientSite); When I passed temp_clientSite as the 3rd parameter to DoVerb everything seems fine until I exit the program. On exiting I get an ASSERT in cmdtarg.cpp at line 52. The line is: ASSERT( m_dwRef <= 1); The value of m_dwRef is 2. If I never call DoVerb with OLEIVERB_HIDE, then I don't have any problems. I can call DoVerb with OLEIVERB_SHOW and OLEIVERB_PROPERTIES and everything is fine. I pass "(IOleClientSite*)this" as the 3rd parameter for the SHOW and PROPERTIES verbs. Can someone please help me? I don't know where else to turn. Thanks, Ed Kaltenbach --------------------------------------------------------------- Ed Kaltenbach Email: kaltenba@ataway.aptec.com ---------------------------------------------------------------
John & Annette Elsbree -- elsbree@msn.com Friday, February 16, 1996 From: owner-mfc-l@netcom.com on behalf of Ed Kaltenbach > Now I want to call DoVerb to hide the control and I will call OleDraw in OnDraw > for the view. This way I can get mouse clicks in the rect containing the OCX. > m_OleControls[m_numControls]- > >DoVerb(OLEIVERB_HIDE,0,???,0,m_hWnd,&tempRect); Why use DoVerb, when you can just call ShowWindow? E.g., m_windows[m_numControls]->ShowWindow(SW_HIDE); This *does* do the right thing (i.e., it calls DoVerb). > What should I pass as the 3rd parameter to DoVerb? I tried passing the view > "(IOleClientSite*)this", and everything seems to work fine, but when I exit the > program I get an ASSERT in wincore.cpp line 360. The line is: > ASSERT( pWnd != NULL); 'this' (which I assume is the view window that contains the controls) isn't derived from IOleClientSite, so casting it to IOleClientSite is completely bogus. > I then tried to call GetClientSite for the IOleObject: > m_OleControls[m_numControls]->GetClientSite(&temp_clientSite); This'll work, but it also AddRef's the client site, which explains why... > When I passed temp_clientSite as the 3rd parameter to DoVerb everything seems > fine until I exit the program. On exiting I get an ASSERT in cmdtarg.cpp > at line 52. The line is: > ASSERT( m_dwRef <= 1); > The value of m_dwRef is 2. After calling DoVerb, be sure to Release() your temp_clientSite. #if _MFC_VER <= 0x0410 mfcTeam.m_johnels; // does not represent Microsoft #endif
| Вернуться в корень Архива |