C++无法在对话框 CFormView 中显示 ActiveX 控件,则控件变量为 NULL



我在项目中使用 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;
....
}

我的应用视图.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,并且智能图形不会显示在对话框中。同时,"确定"按钮变量不是 NULL,它显示正确。 我做错了什么?

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

最新更新