C ++不能在对话框CFormView中显示ActiveX控件,控件变量为NULL

时间:2017-07-26 08:49:37

标签: c++ null mfc activex cview

我在项目中使用SmartGraph ActiveX控件(Visual Studio 2015,MFC,C ++)。它已成功注册。 我尝试将这个控件的对话框装入CFormView

MyAppView.h:

#pragma once
#include "SmartGraph.h"
#include "afxwin.h"

class CMyAppView : public CFormView
{
protected: // create from serialization only
    CMyAppView();
    DECLARE_DYNCREATE(CMyAppView)

    enum { IDD = IDD_DIALOG1 };

    CSmartGraph m_Graph; //!!!!! ActiveX control variable
    CButton m_ctrlOK;
....
}

MyAppView.cpp:

....

void CMyAppView::DoDataExchange(CDataExchange* pDX)
{
    CFormView::DoDataExchange(pDX);
    DDX_Control(pDX, IDOK, m_ctrlOK);
    DDX_Control(pDX, IDC_SMARTGRAPH1, m_Graph);
}

void CMyAppView::OnInitialUpdate()
{
    CFormView::OnInitialUpdate();
    ResizeParentToFit();

    m_Graph.SetParentWnd(this->m_hWnd);
    m_Graph.SetPlotType(0);
    m_Graph.put_xLable(_T("Time"));
    m_Graph.put_yLable(_T("Amplitude"));
    m_Graph.put_Title(_T("Graph Test"));
}
...

因此m_Graph为NULL,并且SmartGraph未显示在对话框中。同时OK按钮变量不是NULL并且它正确显示。 我做错了什么?

1 个答案:

答案 0 :(得分:0)

您需要创建此对象的实例。 m_Graph.CreateControl(...);