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
As shown in the example source code of the article, there
is a member variable,
of the ROccManager class. A pointer to that member is
passed through AfxEnableControlContainer() to wire the
OccManager into the framework.
The problem is that the thread global pointer afxOccManager
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.
What I did for my project was to create a single OccManager
object and install it once in InitiInstance() of the app. I
suggest declaring something like this in your application
class ROccManager *m_pROccManager;
Then in InitInstance() of the application class, create the
object and wire it in:
m_pROccManager = new ROccManager;
// If AppWizard has already put a call to
// 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...
Don't call AfxEnableControlContainer() again in the
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).
If as someone else suggested, this causes troubles for
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
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();
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
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.