gpt4 book ai didi

c++ - 在 CView 而不是 CMainFrame 中创建停靠面板

转载 作者:太空宇宙 更新时间:2023-11-04 12:28:58 25 4
gpt4 key购买 nike

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

因为我不希望所有 Pane 始终可见,而是根据事件文档的类型显示它们,所以我将这些窗口制作成我的 View 成员,并将创建移动到 OnInitialUpdate()。我以与 CMainFrame 相同的方式创建这些 Pane ,包括将主框架设置为父窗口。

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

用 View 创建对接窗口是个好主意还是我应该期待更多问题?有没有更好的方法来完成我想要的?

提前致谢!

最佳答案

事实证明,以下解决方案对我来说效果很好。

MainFrame 仍然拥有所有 Pane ,因此保留了所有现有的框架功能。

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

/**
* \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;
};

关于c++ - 在 CView 而不是 CMainFrame 中创建停靠面板,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/202007/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com