// Compiled VC++ 8.0
class ROccManager :public COccManager
{
public:
ROleControlSite *m_pROleControlSite;
COleControlContainer *m_pContainer;
ROccManager()
{
m_pContainer = NULL;
m_pROleControlSite = NULL;
}
~ROccManager()
{
delete m_pROleControlSite;
delete m_pContainer;
}
COleControlSite* CreateSite(COleControlContainer* pCtrlCont)
{
m_pContainer = pCtrlCont;
m_pROleControlSite = new ROleControlSite(pCtrlCont);
return m_pROleControlSite;
}
};
BOOL RHtmlView::Create(LPCTSTR lpszClassName, LPCTSTR lpszWindowName, DWORD dwStyle, const RECT& rect, CWnd* pParentWnd, UINT nID, CCreateContext* pContext)
{
///////////////////////////////////
// The following does the same as MFC source, except that
// AfxEnableControlContainer() is called with our handler.
///////////////////////////////////
///////////////////////////////////
// create the view window:
m_pCreateContext = pContext;
if (!CView::Create(lpszClassName, lpszWindowName, dwStyle, rect,
pParentWnd, nID, pContext))
{
return FALSE;
}
///////////////////////////////////
// create the control window:
CRect c_clientRect;
GetClientRect(&c_clientRect);
if (!m_wndBrowser.CreateControl(CLSID_WebBrowser, lpszWindowName,
WS_VISIBLE | WS_CHILD, rect, this, AFX_IDW_PANE_FIRST))
{
DestroyWindow();
return FALSE;
}
//LPDISPATCH pIContainer = GetContainer();
m_pROccManager = new ROccManager;
COleControlContainer *pContainer = m_pROccManager->CreateContainer(this);
m_pROccManager->CreateSite(pContainer);
AfxEnableControlContainer(m_pROccManager);
LPUNKNOWN lpUnk = m_wndBrowser.GetControlUnknown();
HRESULT hr = lpUnk->QueryInterface(IID_IWebBrowser2, (void**) &m_pBrowserApp);
if (!SUCCEEDED(hr))
{
m_pBrowserApp = NULL;
m_wndBrowser.DestroyWindow();
DestroyWindow();
return FALSE;
}
///////////////////////////////////
// Our initialisation:
SetWindowText("RHtmlView");
SetClassLong(this->m_hWnd, GCL_STYLE, CS_DBLCLKS);
///////////////////////////////////
return TRUE;
}
Reply
Originally posted by: D. Plate
As shown in the example source code of the article, there
ROccManager m_pROccManager;
of the ROccManager class. A pointer to that member is
The problem is that the thread global pointer afxOccManager
What I did for my project was to create a single OccManager
class ROccManager *m_pROccManager;
Then in InitInstance() of the application class, create the
BOOL InitInstance()
// If AppWizard has already put a call to
AfxEnableControlContainer(pROccManager);.
Don't call AfxEnableControlContainer() again in the
If as someone else suggested, this causes troubles for
After doing some debugging in a similar class, I think I
see a problem if you try to use this in an MDI
application. I've seen a few samples like this that are
based on the classic "Driller" sample and have a similar
problem.
is a member variable,
passed through AfxEnableControlContainer() to wire the
OccManager into the framework.
is set to the pointer that is passed in through
AfxEnableControlContainer(). At least it is in VC6. In an
MDI application, I'm pretty sure this will cause problems
because the CWnd class calls methods of the afxOccManager
object in some cases. For example, CWnd::IsDialogMessage()
can call afxOccManger->IsDialogMessage(). This means that
if the View that conatins the OccManager gets closed, other
Views may still try and call methods of that deleted object
by way of afxOccManager, and crash.
object and install it once in InitiInstance() of the app. I
suggest declaring something like this in your application
class:
object and wire it in:
{
m_pROccManager = new ROccManager;
// AfxEnableControlContainer() in InitInstance,
// replace it with this one that has the pointer
// argument. Calling this without an argument
// elsewhere in the app will unhook your OccManager.
//... other initialization stuff...
}
View class or anywhere else in the app - you won't need to. You can also do away with
the OccManager member in the ROccManager class and at a
glance, I don't see why the ControlSite pointer needs to be
saved in a member variable. In VC6, CWnd class keeps track
of the ControlSite and deletes in when the window is
destroyed (I think).
other controls, you might make the OccManager more
elaborate to pass Views that aren't of the your class on to
the base class implementation (guessing - haven't tried
that).
Originally posted by: DarkMist
BOOL RHtmlView::Create(LPCTSTR lpszClassName, LPCTSTR lpszWindowName, DWORD dwStyle, const RECT& rect, CWnd* pParentWnd, UINT nID, CCreateContext* pContext)
AfxEnableControlContainer(&m_pROccManager);
if (!m_wndBrowser.CreateControl(CLSID_WebBrowser, lpszWindowName, WS_VISIBLE | WS_CHILD, c_clientRect, this, AFX_IDW_PANE_FIRST))
// add this line
// ...
If you have another controls in your application you have to restore OccManager after control's creating.
If you not do so, it causes traps in mshtml(IE6.0).
{
// ...
{
DestroyWindow();
return FALSE;
}
AfxEnableControlContainer();
}
Originally posted by: Jos� Leandro Massada
Well i got this error because i used the class inside a CFormView. Why do I got the error? Because the view wasn't allocated directly from the heap. The solution is to override PostNcDestroy(). PostNcDestroy() does a "delete this;" to destroy the view, and that's the normal procedure to destroy a view allocated directly from the heap.
So, just override PostNcDestroy() and remove CHtmlView::PostNcDestroy();
void CMyDerivedHtmlViewFromRHtmlView::PostNcDestroy()
{
}
regards.
ReplyOriginally posted by: S. Bob
MFC implementation of the client site in VC++ 6.0 may be different from that of VC++ 7.0.
ReplyOriginally posted by: Marc Loxton
MainDlg.cpp
c:\documents and settings\spoonchops\my documents\programming\myprojects\thesis\maindlg.h(15) : error C2143: syntax error : missing ';' before '<class-head>'
c:\documents and settings\spoonchops\my documents\programming\myprojects\thesis\maindlg.h(15) : fatal error C1004: unexpected end of file found
Error executing cl.exe.
Creating browse info file...
BSCMAKE: error BK1506 : cannot open file '.\Debug\MainDlg.sbr': No such file or directory
Error executing bscmake.exe.
AsdkProject.arx - 3 error(s), 0 warning(s)
CMainDlg class is a standard CDialog based class, it throws an error on the class definition in it's h file and I have no idea why. I don't think it has anything to with with the definition as I haven't changed it maybe include file problem?? I am at a total loss so any pointers would be appreciated, thanks in advance
Originally posted by: David
Instead of loading an url from a resource. Navigate2(http://www.yahoo.com/";) then open up 2 or more windows. Now start to close them and the app will crash.
Reply
Originally posted by: Ganesan
Some how the scroll bars dont disappear when I click "no scroll bar" option. Can someone please tell me how to get rid of the scrollbar in CHtmlView?
Thanks ...
Originally posted by: Rakesh Sharma
When I tried to run you code in debug mode it give Assertion Failed in file Afxwin2.inl at line 98.
Can you please help me to overcome this problem.
Originally posted by: Ben
Great Job on the class!
I needed a way to not display the standard context menu for IE and this did the job. I am having problems though trying to display my own context menu when the user right clicks. OnRButtonUp and OnContextMenu are not getting called. Any Ideas would be really appreciated.
Reply