十步会用IOCOMP–iplotx控件

版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/Cracent/article/details/66968903

十步会用IOCOMP–iplotx控件

1、 新建项目-MFC-基于对话框
2、 插入ActiveX控件-选择iPlotX Control
3、右击该控件,添加变量,输入变量名
4、类向导-(Dlg结尾那个类)添加函数-IplotxInit(用于该控件基本参数设置)
5、在Dlg.cpp中开头处添加以下代码:

#import  "iPlotLibrary.tlb" named_guids
#include "atlbase.h"
using namespace iPlotLibrary;
CComPtr<iPlotLibrary::IiPlotX> PlotComponent;

6、在函数IplotxInit()中添加以下代码:

CWnd* pPlotWnd = GetDlgItem(IDC_IPLOTX1);
    IUnknown*  m_iUnknown;
    //Get iDispatch Inteface to Plot Component
    m_iUnknown = pPlotWnd->GetControlUnknown();
    m_iUnknown->QueryInterface(__uuidof(iPlotLibrary::IiPlotX), (LPVOID*)&PlotComponent);
    //Setup Channels
    PlotComponent->RemoveAllChannels();
    PlotComponent->AddChannel();
    PlotComponent->AddChannel();
    PlotComponent->AddChannel();
    PlotComponent->AddChannel();
    PlotComponent->AddChannel();
    PlotComponent->AddChannel();
    PlotComponent->XAxis[0]->Span = 5;
    PlotComponent->Labels[0]->Caption = "曲线图";

    PlotComponent->GetChannel(0)->TitleText = "曲线1";
    PlotComponent->GetChannel(1)->TitleText = "曲线2";
    PlotComponent->GetChannel(2)->TitleText = "曲线3";
    PlotComponent->GetChannel(3)->TitleText = "曲线4";
    PlotComponent->GetChannel(4)->TitleText = "曲线5";
    PlotComponent->GetChannel(5)->TitleText = "曲线6";

7、类向导-添加消息处理函数OnTimer();
8、在OnInitDialog()函数return TRUE前添加以下代码:

    IplotxInit();
    SetTimer(1, 10, NULL);

9、在函数OnTimer();中添加以下函数:

    static float i = 10;
    PlotComponent->GetChannel(0)->AddYElapsedSeconds(40*sin(0.01*i));//AddYNow((int)i);
    PlotComponent->GetChannel(1)->AddYElapsedSeconds(40 * cos(0.01*i));//AddYNow((int)i);
    PlotComponent->GetChannel(2)->AddYElapsedSeconds(40 * sin(0.01*i + 1));//AddYNow((int)i);
    PlotComponent->GetChannel(3)->AddYElapsedSeconds(40 * cos(0.01*i + 1));//AddYNow((int)i);
    PlotComponent->GetChannel(4)->AddYElapsedSeconds(40 * sin(0.01*i + 2));
    PlotComponent->GetChannel(5)->AddYElapsedSeconds(40 * cos(0.01*i + 2));
    i++;
    i++;
    i++;

10、按F5键。
效果图:
这里写图片描述
源码下载:http://download.csdn.net/detail/cracent/9794944

猜你喜欢

转载自blog.csdn.net/Cracent/article/details/66968903