Measurement Studio for VC++

cancel
Showing results for 
Search instead for 
Did you mean: 

Using the Measurement Studio 2019 Chart Control in Visual Studio C++

Solved!
Go to solution

Hello, I am trying to use the Measurement Studio 2019 Chart control in a Visual Studio 2019 / C++ project.  My C++ project uses MFC and I have enabled .NET functionality with the /clr option and I have been successful using the .NET PulseParameter function in the the NationalInstruments::Analysis:Dsp namespace.  However, I have been unable to find a way to use any of the .NET Graphing controls (Like Chart).  Has anyone had success using these controls in Visual Studio C++ ?  This application was originally written using MS2013 and VS2012.  The use of these Measurement Studio functions represent a very small but critical part of the application.  Rewriting the project in C# or VB is really not an option.

0 Kudos
Message 1 of 2
(186 Views)
Solution
Accepted by topic author kenny55

This creates the NI WaveformGraph control in a Visual Studio MFC project. Before beginning, make sure you have set your project properties to support Common Language Runtime (/clr option).  Also, make sure you have added the .NET references:

 

NationalInstruments.Common

NationalInstruments.UI

NationalInstruments.UI.WindowsForms

 

 

Add a .h file to your project.  In this example, the namespace is NIWaveform. The control is called NIGraph.

 

#pragma once
#include "pch.h"

using namespace System;
using namespace System::Windows::Forms;
using namespace System::Drawing;
using namespace NationalInstruments::UI;
using namespace NationalInstruments::UI::WindowsForms;

namespace NIWaveform {
    public ref class NIGraph : public UserControl
    {
    private:
          WaveformGraph^ waveformGraph;
          WaveformPlot^ waveformPlot;
          XAxis^ xAxis;
          YAxis^ yAxis;
    public:
        NIGraph()
        {
            InitializeComponent();
        }
    public:
        void InitializeComponent() 
        {
             // Create axes
             xAxis = gcnew XAxis();
             yAxis = gcnew YAxis();
             // Create plots
             waveformPlot = gcnew WaveformPlot();
             waveformPlot->XAxis = xAxis;
             waveformPlot->YAxis = yAxis;
             waveformPlot->LineColor = Color::Green;
             // Create graph
             waveformGraph = gcnew WaveformGraph();
             waveformGraph->Plots->Add(waveformPlot);
             waveformGraph->XAxes->Add(xAxis);
             waveformGraph->YAxes->Add(yAxis);
             this->Controls->Add(waveformGraph);
        }
        void setSize(int width, int height)
        {
            waveformGraph->Size = Drawing::Size(width, height);
        }
        void setYaxisLabel(System::String^ label)
        {            
            yAxis->Caption = label;
        }
        void setXaxisLabel(System::String^ label)
        {
            xAxis->Caption = label;
        }
        void clearGraph()
        {
            waveformGraph->ClearData();
        }
        void plotData(array<double>^ data)
        {
            waveformPlot->PlotY(data);
        }
    };
}

 

 

Then in your MFC app, create a CStatic control on the main dialog where you want the Graph control to be located.  Give the CStatic control a unique ID (IDC_MYGRAPH).

 

in the .h file of your MFC dialog, add the following:

using namespace System;
using namespace System::Windows::Forms;
using namespace NationalInstruments::UI;
using namespace NationalInstruments::UI::WindowsForms;
using namespace NIWaveform;

and define as public

public:
	CWinFormsControl<NIGraph> m_graph1;

 

In the DoDataExchange of your MFC Dialog, add the following:

 

	DDX_ManagedControl(pDX, IDC_MYGRAPH, m_graph1);

 

Run your program and the graph should be displayed.  At points within your MDC app you can make calls into NIWaveform to configure your graph and to add waveform data.

 

array<double>^ waveform = gcnew array<double>(500);
//
CRect rect;
CStatic *pStatic = (CStatic*) this->GetDlgItem(IDC_MYGRAPH);
pStatic->GetWindowRect(&rect);
m_graph1->setSize(rect.Width(), rect.Height());
//
// populate waveform array with your data
//
m_graph1->plotData(waveform);

 

 

 

 

 

 

 

0 Kudos
Message 2 of 2
(104 Views)