C++ can't display ActiveX control in the dialog CFormView, control variable is NULL

351 views Asked by At

I use a SmartGraph ActiveX control in my project (Visual Studio 2015, MFC, C++). It has been registered successfully. I try to fit a dialog with this control into 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"));
}
...

So the m_Graph is NULL and SmartGraph isn't displayed in the dialog. At the same time the OK button variable isn't NULL and it is displayed correctly. What I do wrong?

1

There are 1 answers

4
xMRi On

You need to create an instance of this object. m_Graph.CreateControl(...);