0

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?

Nika_Rika
  • 613
  • 2
  • 6
  • 29

1 Answers1

0

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

xMRi
  • 14,982
  • 3
  • 26
  • 59
  • In "SmartGraph.h" there are two methods that return CreateControl(), but in working Demo Project from the author he doesn't use this methonds at all. – Nika_Rika Jul 26 '17 at 09:25
  • I've tried this method - debug assertion Faled in occsite.cpp Line 212 – Nika_Rika Jul 26 '17 at 09:30
  • Thew working demo may us a dialog template were the control is created implicit in the template... Anyhow you need to create the object! – xMRi Jul 26 '17 at 09:48
  • @xMRi: m_Graph's control should be created by DDX_Control, as far as I remember. To Nika_Rika: Put a breakpoint on DDX_Control, step through it, and see if it has been created successfully (i.e. m_Graph.m_hWnd is not NULL) and if not, try to determine the cause there. – thomiel Jul 27 '17 at 13:55