CDialog中嵌入CView

背景介绍:

1、BCG的甘特图控件继承自CView。

2、项目中需要用到对话框里显示甘特图。

需要实现CDialog中要嵌入CView。

CViewDlg的OnInitDialog方法中加入以下代码(示例查找自网络):

    CRect rect;
    GetClientRect(&rect);

    m_pFrame = new CFrameWnd(); //对话框内视图的父窗口
    m_pFrame->Create(NULL, NULL, WS_CHILD | WS_VISIBLE, rect, this);
    ASSERT(m_pFrame);


    m_pView = (CBCGPGanttDemoView*)RUNTIME_CLASS(CBCGPGanttDemoView)->CreateObject();
    m_pView->Create(NULL, NULL,WS_CHILD | WS_VISIBLE, rect, m_pFrame, 1, NULL);

    m_pView->OnInitialUpdate();

其中m_pFrame、m_pView 为CViewDlg成员变量:

    CFrameWnd* m_pFrame;
    CBCGPGanttDemoView*  m_pView;

CBCGPGanttDemoView继承自甘特控件CBCGPGanttView

设置OnInitialUpdate方法为public,在该方法体内调用图形创建接口。

转:https://blog.csdn.net/segen_jaa/article/details/6692274

猜你喜欢

转载自blog.csdn.net/eric_e/article/details/82952514