When creating an MDI Application with "Visual Studio" style using the AppWizard of VS2008 (plus Feature Pack), the CMainFrame class gets a method CreateDockingWindows().

Since I don't want all panes to be always visible but display them depending on the type of the active document, I made those windows to members of my views and also moved the creation to OnInitialUpdate(). I create those panes in the same manner as was done by the CMainFrame including setting the main frame as parent window.

The positions of the docking windows get saved to the registry automatically but they won't be restored because the docking windows don't yet exist when the frame is initialized.

Is it a good idea to create the docking windows with the views or should I expect more problems? Is there a better way to accomplish what I want?

Thanks in advance!


The following solution turned out to work pretty well for me.

The MainFrame still owns all the panes thus keeping all the existing framework-functionality.

I derive the panes from a class which implements the "CView-like" behavior I need:

 * \brief Mimics some of the behavior of a CView
 * CDockablePane derived class which stores a pointer to the document and offers
 * a behavior similar to CView classes.
 * Since the docking panes are child windows of the main frame,
 * they have a longer live time than a view. Thus the (de-)initialization code
 * cannot reside in the CTor/DTor.
class CPseudoViewPane :
    public CDockablePane,

    /// Initializes the pane with the specified document
    void Initialize(CMyDoc* pDoc);

    void DeInitialize();

    /// Checks if window is valid and then forwards call to pure virtual OnUpdate() method.
    void Update(const LPARAM lHint);

    virtual ~CPseudoViewPane();

    CMyDoc* GetDocument() const { ASSERT(NULL != m_pDocument); return m_pDocument; }

    CMainFrame* GetMainFrame() const;

     * This method is called after a document pointer has been set with #Initialize().
     * Override this in derived classes to mimic a view's "OnInitialUpdate()-behavior".
    virtual void OnInitialUpdate() = 0;

     * Called by #Update(). Overrider to mimic a view's "OnUpdate()-behavior".
     * This method has a simplified parameter list. Enhance this if necessary.
    virtual void OnUpdate(const LPARAM lHint) = 0;


    CMyDoc* m_pDocument;

Your Answer

