CDialogEx界面添加BCGSuite控件CView - 小众知识

CDialogEx界面添加BCGSuite控件CView

2015-10-29 15:20:15 苏内容
  标签: BCG/CView/CDialog
阅读:4044

背景介绍:

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,在该方法体内调用图形创建接口。

 

新建一个视图类:CMyView,派生自CView
在对话框类CCreateViewDlg上定义一个视图类指针
CMyView *m_pView;
为了使得视图创建在指定的区域,在对话框上放一个静态文本控件,资源ID为IDC_STATIC_VIEW
// OnInitDialog初始化中添加
UINT TargetCtrID = IDC_STATIC_VIEW;
 CWnd * pWnd = this->GetDlgItem(TargetCtrID);
 CRect RectTargetCtrl;
 pWnd->GetWindowRect(RectTargetCtrl);
 this->ScreenToClient(RectTargetCtrl);
 m_pView = (CMyView *)RUNTIME_CLASS(CMyView)->CreateObject();
 //
 if (NULL == m_pView)
 {
  return FALSE;
 }
 m_pView->Create(NULL, NULL, AFX_WS_DEFAULT_VIEW, RectTargetCtrl, this, TargetCtrID);
// 在view类中的OnDraw函数中
void CMyView::OnDraw(CDC* pDC)
{
 CDocument* pDoc = GetDocument();
 // TODO: add draw code here
 CRect rt(0, 50, 200, 200);
 pDC->DrawText(_T("这是在对话框上创建的视图"), &rt, DT_LEFT);
}

扩展阅读
相关阅读
© CopyRight 2010-2021, PREDREAM.ORG, Inc.All Rights Reserved. 京ICP备13045924号-1