You'll notice a very strange implementation of OnInitMenuPopup() in CBHOCopDlg. This is the solution recommended by Microsoft for triggering the UPDATE_COMMAND_UI handlers in a dialog-based MFC application. Microsoft's Knowledge Base article on this issue can be found at http://support.microsoft.com/support/kb/articles/Q242/5/77.asp.
The UPDATE_COMMAND_UI handlers are used by the MFC framework to update the visual state of user interface elements;( enable/disable and check/uncheck, for example. This mechanism doesn't work for dialog-based applications, however, because CDialog has no OnInitMenuPopup handler. The CWnd default handler, which is used by CDialog, doesn't call UPDATE_COMMAND_UI handlers for menu items. The code in OnInitMenuPopup() fixes the problem by doing the work that the MFC framework doesn't implement for this kind of application.
The computations at the beginning of OnInitDialog are for resizing. The OnSize() handler uses these values to move the controls to the correct location each time the window is resized. This behavior could be handled in a generic class, but that was beyond the scope of this project. For an example of how this might be implemented, visit www.codeguru.com.
Once you know where the useful information about BHOs is located, disabling and re-enabling them is not particularly difficult. The main challenge is to keep things in sync once you have disabled a BHO. BHO Cop does this as safely as possible by constantly checking the consistency between its own data and the contents of the Registry.
Patrick Philippot, the author of BHO Cop, is a developer based in Draveil, France. Sheryl Canter is the editor of the Utilities column and a contributing editor of PC Magazine.