在 CView 而不是 CMainFrame 中创建停靠窗格

发布于 2024-07-08 08:30:45 字数 398 浏览 16 评论 0原文

当使用VS2008(加上功能包)的AppWizard创建“Visual Studio”风格的MDI应用程序时,CMainFrame类获得一个方法CreateDockingWindows()

由于我不希望所有窗格始终可见,而是根据活动文档的类型显示它们,因此我将这些窗口设置为视图的成员,并将创建内容移至 OnInitialUpdate()。 我以与 CMainFrame 相同的方式创建这些窗格,包括将主框架设置为父窗口。

停靠窗口的位置会自动保存到注册表中,但它们不会被恢复,因为在框架初始化时停靠窗口还不存在。

使用视图创建对接窗口是个好主意还是我应该期待更多问题? 有更好的方法来实现我想要的吗?

提前致谢!

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!

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

南巷近海 2024-07-15 08:30:45

事实证明,以下解决方案对我来说非常有效。

MainFrame 仍然拥有所有窗格,从而保留所有现有的框架功能。

我从实现我需要的“类似 CView”行为的类派生窗格:

/**
 * \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,
{
    DECLARE_DYNAMIC(CPseudoViewPane)

public:
    /// 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);

protected:
    CPseudoViewPane();
    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;

    DECLARE_MESSAGE_MAP()

private:
    CMyDoc* m_pDocument;
};

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,
{
    DECLARE_DYNAMIC(CPseudoViewPane)

public:
    /// 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);

protected:
    CPseudoViewPane();
    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;

    DECLARE_MESSAGE_MAP()

private:
    CMyDoc* m_pDocument;
};
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文