开发者社区> 问答> 正文

vc中程序调用ntgraph控件

#include "stdafx.h"
#include "gt.h"
#include "gtDlg.h"

#include<iostream>
#include<fstream>
#include<math.h>
#include"hanshu.h"       //声明各个函数
#include"changshu.h"    //声明全局变量
using namespace std;

#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif

/////////////////////////////////////////////////////////////////////////////
// CAboutDlg dialog used for App About

class CAboutDlg : public CDialog
{
public:
    CAboutDlg();

// Dialog Data
    //{{AFX_DATA(CAboutDlg)
    enum { IDD = IDD_ABOUTBOX };
    //}}AFX_DATA

    // ClassWizard generated virtual function overrides
    //{{AFX_VIRTUAL(CAboutDlg)
    protected:
    virtual void DoDataExchange(CDataExchange* pDX);    // DDX/DDV support
    //}}AFX_VIRTUAL

// Implementation
protected:
    //{{AFX_MSG(CAboutDlg)
    //}}AFX_MSG
    DECLARE_MESSAGE_MAP()
};

CAboutDlg::CAboutDlg() : CDialog(CAboutDlg::IDD)
{
    //{{AFX_DATA_INIT(CAboutDlg)
    //}}AFX_DATA_INIT
}

void CAboutDlg::DoDataExchange(CDataExchange* pDX)
{
    CDialog::DoDataExchange(pDX);
    //{{AFX_DATA_MAP(CAboutDlg)
    //}}AFX_DATA_MAP
}

BEGIN_MESSAGE_MAP(CAboutDlg, CDialog)
    //{{AFX_MSG_MAP(CAboutDlg)
        // No message handlers
    //}}AFX_MSG_MAP
END_MESSAGE_MAP()

/////////////////////////////////////////////////////////////////////////////
// CGtDlg dialog

CGtDlg::CGtDlg(CWnd* pParent /*=NULL*/)
    : CDialog(CGtDlg::IDD, pParent)
{
    //{{AFX_DATA_INIT(CGtDlg)
        // NOTE: the ClassWizard will add member initialization here
    //}}AFX_DATA_INIT
    // Note that LoadIcon does not require a subsequent DestroyIcon in Win32
    m_hIcon = AfxGetApp()->LoadIcon(IDR_MAINFRAME);
}

void CGtDlg::DoDataExchange(CDataExchange* pDX)
{
    CDialog::DoDataExchange(pDX);
    //{{AFX_DATA_MAP(CGtDlg)
    DDX_Control(pDX, IDC_NTGRAPHCTRL1, m_Graph);
    //}}AFX_DATA_MAP
}

BEGIN_MESSAGE_MAP(CGtDlg, CDialog)
    //{{AFX_MSG_MAP(CGtDlg)
    ON_WM_SYSCOMMAND()
    ON_WM_PAINT()
    ON_WM_QUERYDRAGICON()
    ON_BN_CLICKED(IDC_BUTTON1, OnButton1)
    //}}AFX_MSG_MAP
END_MESSAGE_MAP()

/////////////////////////////////////////////////////////////////////////////
// CGtDlg message handlers

BOOL CGtDlg::OnInitDialog()
{
    CDialog::OnInitDialog();

    // Add "About..." menu item to system menu.

    // IDM_ABOUTBOX must be in the system command range.
    ASSERT((IDM_ABOUTBOX & 0xFFF0) == IDM_ABOUTBOX);
    ASSERT(IDM_ABOUTBOX < 0xF000);

    CMenu* pSysMenu = GetSystemMenu(FALSE);
    if (pSysMenu != NULL)
    {
        CString strAboutMenu;
        strAboutMenu.LoadString(IDS_ABOUTBOX);
        if (!strAboutMenu.IsEmpty())
        {
            pSysMenu->AppendMenu(MF_SEPARATOR);
            pSysMenu->AppendMenu(MF_STRING, IDM_ABOUTBOX, strAboutMenu);
        }
    }

    // Set the icon for this dialog.  The framework does this automatically
    //  when the application's main window is not a dialog
    SetIcon(m_hIcon, TRUE);         // Set big icon
    SetIcon(m_hIcon, FALSE);        // Set small icon

    // TODO: Add extra initialization here

    return TRUE;  // return TRUE  unless you set the focus to a control
}

void CGtDlg::OnSysCommand(UINT nID, LPARAM lParam)
{
    if ((nID & 0xFFF0) == IDM_ABOUTBOX)
    {
        CAboutDlg dlgAbout;
        dlgAbout.DoModal();
    }
    else
    {
        CDialog::OnSysCommand(nID, lParam);
    }
}

// If you add a minimize button to your dialog, you will need the code below
//  to draw the icon.  For MFC applications using the document/view model,
//  this is automatically done for you by the framework.

void CGtDlg::OnPaint() 
{
    if (IsIconic())
    {
        CPaintDC dc(this); // device context for painting

        SendMessage(WM_ICONERASEBKGND, (WPARAM) dc.GetSafeHdc(), 0);

        // Center icon in client rectangle
        int cxIcon = GetSystemMetrics(SM_CXICON);
        int cyIcon = GetSystemMetrics(SM_CYICON);
        CRect rect;
        GetClientRect(&rect);
        int x = (rect.Width() - cxIcon + 1) / 2;
        int y = (rect.Height() - cyIcon + 1) / 2;

        // Draw the icon
        dc.DrawIcon(x, y, m_hIcon);
    }
    else
    {
        CDialog::OnPaint();
    }
}

// The system calls this to obtain the cursor to display while the user drags
//  the minimized window.
HCURSOR CGtDlg::OnQueryDragIcon()
{
    return (HCURSOR) m_hIcon;
}

CNTGraph * g;
int i;

void display(double x, double y)
{
    g->PlotXY(i, x, 0);
    g->PlotXY(i++, y*5000, 1);
}

void CGtDlg::OnButton1()
{
    g = &m_Graph;

    i = 0;

    m_Graph.SetShowGrid(TRUE);

    m_Graph.SetElementLineColor(RGB(255,0,0));
    m_Graph.SetRange (0,100,0,8000);
    m_Graph.AddElement();
    m_Graph.SetElementLineColor(RGB(0,0,100));
    m_Graph.SetRange (0,100,0,8000);
    m_Graph.SetElementIdentify(FALSE);



    /*打开文件*/
    ifstream  file;             //打开文本文件
    file.open("C:\\Program Files\\Microsoft Visual Studio\\MyProjects\\gt\\06_hit08.txt");     //06_hit08是存放9列数据的txt文件,只取前3000行。
    if (!file)                 //判断文件是否打开
    {
        cerr << "error: unable to open input file: "
             << file << endl;
        file.close();
        file.clear();
    }

    struct list      //给txt文件的9列分别命名
    {
        int list1;       //公式中未用
        double v0;          
        double S;           
        double list4;    //未用
        double gamair;
        double gamself;
        double E;           
        double n;
        double list9;       //未用
    };

    //将txt文件中的9列放在数组中
    list txt[3000];     //ROW=3000
    int i;
    for(i=0;i<ROW;i++)
    {
        file>>txt[i].list1>>txt[i].v0>>txt[i].S>>txt[i].list4>>txt[i].gamair
            >>txt[i].gamself>>txt[i].E>>txt[i].n>>txt[i].list9;
    }

    file.close();  //关闭文件

    double array_tran[3000];        //ROW=3000
    for(i=0;i<3000;i++)
    {
        double y_seta, y_aL, y_aG, y_fL, y_fG, y_CH4, y_tao, y_tran;    //用来保存公式的计算结果
        y_seta=seta(txt[i].S , txt[i].E , txt[i].v0); //调用线强修正函数seta       x=txt[i].v0,y=y_seta画图
        y_aL=aL(txt[i].n,  txt[i].gamair,  txt[i].gamself);  //计算洛伦兹半宽度
        y_aG=aG(txt[i].v0);             //计算多普勒半宽度
        y_fL=fL(y_aL,txt[i].v0,i);         //洛伦兹展宽         x=txt[i].v0,y=y_fL画图
        y_fG=fG(y_aG,txt[i].v0,i);      //多普勒展宽            x=txt[i].v0,y=y_fG画图
        y_CH4=CH4(y_fL,y_fG,y_seta);     //CH4吸收截面          x=txt[i].v0,y=y_CH4画图
        y_tao=tao(y_CH4);                //光学厚度             x=txt[i].v0,y=y_tao画图
        y_tran=tran(y_tao);                 //透过率            x=txt[i].v0,y=y_tran画图
        array_tran[i]=y_tran;

    }

    avgs(txt[1].v0,array_tran, display);
}

展开
收起
a123456678 2016-03-23 14:12:35 3597 0
1 条回答
写回答
取消 提交回答
  • #include "stdafx.h"
    #include "gt.h"
    #include "gtDlg.h"
    
    #include<iostream>
    #include<fstream>
    #include<math.h>
    #include"hanshu.h"       //声明各个函数
    #include"changshu.h"    //声明全局变量
    using namespace std;
    
    #ifdef _DEBUG
    #define new DEBUG_NEW
    #undef THIS_FILE
    static char THIS_FILE[] = __FILE__;
    #endif
    
    /////////////////////////////////////////////////////////////////////////////
    // CAboutDlg dialog used for App About
    
    class CAboutDlg : public CDialog
    {
    public:
        CAboutDlg();
    
    // Dialog Data
        //{{AFX_DATA(CAboutDlg)
        enum { IDD = IDD_ABOUTBOX };
        //}}AFX_DATA
    
        // ClassWizard generated virtual function overrides
        //{{AFX_VIRTUAL(CAboutDlg)
        protected:
        virtual void DoDataExchange(CDataExchange* pDX);    // DDX/DDV support
        //}}AFX_VIRTUAL
    
    // Implementation
    protected:
        //{{AFX_MSG(CAboutDlg)
        //}}AFX_MSG
        DECLARE_MESSAGE_MAP()
    };
    
    CAboutDlg::CAboutDlg() : CDialog(CAboutDlg::IDD)
    {
        //{{AFX_DATA_INIT(CAboutDlg)
        //}}AFX_DATA_INIT
    }
    
    void CAboutDlg::DoDataExchange(CDataExchange* pDX)
    {
        CDialog::DoDataExchange(pDX);
        //{{AFX_DATA_MAP(CAboutDlg)
        //}}AFX_DATA_MAP
    }
    
    BEGIN_MESSAGE_MAP(CAboutDlg, CDialog)
        //{{AFX_MSG_MAP(CAboutDlg)
            // No message handlers
        //}}AFX_MSG_MAP
    END_MESSAGE_MAP()
    
    /////////////////////////////////////////////////////////////////////////////
    // CGtDlg dialog
    
    CGtDlg::CGtDlg(CWnd* pParent /*=NULL*/)
        : CDialog(CGtDlg::IDD, pParent)
    {
        //{{AFX_DATA_INIT(CGtDlg)
            // NOTE: the ClassWizard will add member initialization here
        //}}AFX_DATA_INIT
        // Note that LoadIcon does not require a subsequent DestroyIcon in Win32
        m_hIcon = AfxGetApp()->LoadIcon(IDR_MAINFRAME);
    }
    
    void CGtDlg::DoDataExchange(CDataExchange* pDX)
    {
        CDialog::DoDataExchange(pDX);
        //{{AFX_DATA_MAP(CGtDlg)
        DDX_Control(pDX, IDC_NTGRAPHCTRL1, m_Graph);
        //}}AFX_DATA_MAP
    }
    
    BEGIN_MESSAGE_MAP(CGtDlg, CDialog)
        //{{AFX_MSG_MAP(CGtDlg)
        ON_WM_SYSCOMMAND()
        ON_WM_PAINT()
        ON_WM_QUERYDRAGICON()
        ON_BN_CLICKED(IDC_BUTTON1, OnButton1)
        //}}AFX_MSG_MAP
    END_MESSAGE_MAP()
    
    /////////////////////////////////////////////////////////////////////////////
    // CGtDlg message handlers
    
    BOOL CGtDlg::OnInitDialog()
    {
        CDialog::OnInitDialog();
    
        // Add "About..." menu item to system menu.
    
        // IDM_ABOUTBOX must be in the system command range.
        ASSERT((IDM_ABOUTBOX & 0xFFF0) == IDM_ABOUTBOX);
        ASSERT(IDM_ABOUTBOX < 0xF000);
    
        CMenu* pSysMenu = GetSystemMenu(FALSE);
        if (pSysMenu != NULL)
        {
            CString strAboutMenu;
            strAboutMenu.LoadString(IDS_ABOUTBOX);
            if (!strAboutMenu.IsEmpty())
            {
                pSysMenu->AppendMenu(MF_SEPARATOR);
                pSysMenu->AppendMenu(MF_STRING, IDM_ABOUTBOX, strAboutMenu);
            }
        }
    
        // Set the icon for this dialog.  The framework does this automatically
        //  when the application's main window is not a dialog
        SetIcon(m_hIcon, TRUE);         // Set big icon
        SetIcon(m_hIcon, FALSE);        // Set small icon
    
        // TODO: Add extra initialization here
    
        return TRUE;  // return TRUE  unless you set the focus to a control
    }
    
    void CGtDlg::OnSysCommand(UINT nID, LPARAM lParam)
    {
        if ((nID & 0xFFF0) == IDM_ABOUTBOX)
        {
            CAboutDlg dlgAbout;
            dlgAbout.DoModal();
        }
        else
        {
            CDialog::OnSysCommand(nID, lParam);
        }
    }
    
    // If you add a minimize button to your dialog, you will need the code below
    //  to draw the icon.  For MFC applications using the document/view model,
    //  this is automatically done for you by the framework.
    
    void CGtDlg::OnPaint() 
    {
        if (IsIconic())
        {
            CPaintDC dc(this); // device context for painting
    
            SendMessage(WM_ICONERASEBKGND, (WPARAM) dc.GetSafeHdc(), 0);
    
            // Center icon in client rectangle
            int cxIcon = GetSystemMetrics(SM_CXICON);
            int cyIcon = GetSystemMetrics(SM_CYICON);
            CRect rect;
            GetClientRect(&rect);
            int x = (rect.Width() - cxIcon + 1) / 2;
            int y = (rect.Height() - cyIcon + 1) / 2;
    
            // Draw the icon
            dc.DrawIcon(x, y, m_hIcon);
        }
        else
        {
            CDialog::OnPaint();
        }
    }
    
    // The system calls this to obtain the cursor to display while the user drags
    //  the minimized window.
    HCURSOR CGtDlg::OnQueryDragIcon()
    {
        return (HCURSOR) m_hIcon;
    }
    
    CNTGraph * g;
    int i;
    
    void display(double x, double y)
    {
        g->PlotXY(i, x, 0);
        g->PlotXY(i++, y*5000, 1);
    }
    
    void CGtDlg::OnButton1()
    {
        g = &m_Graph;
    
        i = 0;
    
        m_Graph.SetShowGrid(TRUE);
    
        m_Graph.SetElementLineColor(RGB(255,0,0));
        m_Graph.SetRange (0,100,0,8000);
        m_Graph.AddElement();
        m_Graph.SetElementLineColor(RGB(0,0,100));
        m_Graph.SetRange (0,100,0,8000);
        m_Graph.SetElementIdentify(FALSE);
    
    
    
        /*打开文件*/
        ifstream  file;             //打开文本文件
        file.open("C:\\Program Files\\Microsoft Visual Studio\\MyProjects\\gt\\06_hit08.txt");     //06_hit08是存放9列数据的txt文件,只取前3000行。
        if (!file)                 //判断文件是否打开
        {
            cerr << "error: unable to open input file: "
                 << file << endl;
            file.close();
            file.clear();
        }
    
        struct list      //给txt文件的9列分别命名
        {
            int list1;       //公式中未用
            double v0;          
            double S;           
            double list4;    //未用
            double gamair;
            double gamself;
            double E;           
            double n;
            double list9;       //未用
        };
    
        //将txt文件中的9列放在数组中
        list txt[3000];     //ROW=3000
        int i;
        for(i=0;i<ROW;i++)
        {
            file>>txt[i].list1>>txt[i].v0>>txt[i].S>>txt[i].list4>>txt[i].gamair
                >>txt[i].gamself>>txt[i].E>>txt[i].n>>txt[i].list9;
        }
    
        file.close();  //关闭文件
    
        double array_tran[3000];        //ROW=3000
        for(i=0;i<3000;i++)
        {
            double y_seta, y_aL, y_aG, y_fL, y_fG, y_CH4, y_tao, y_tran;    //用来保存公式的计算结果
            y_seta=seta(txt[i].S , txt[i].E , txt[i].v0); //调用线强修正函数seta       x=txt[i].v0,y=y_seta画图
            y_aL=aL(txt[i].n,  txt[i].gamair,  txt[i].gamself);  //计算洛伦兹半宽度
            y_aG=aG(txt[i].v0);             //计算多普勒半宽度
            y_fL=fL(y_aL,txt[i].v0,i);         //洛伦兹展宽         x=txt[i].v0,y=y_fL画图
            y_fG=fG(y_aG,txt[i].v0,i);      //多普勒展宽            x=txt[i].v0,y=y_fG画图
            y_CH4=CH4(y_fL,y_fG,y_seta);     //CH4吸收截面          x=txt[i].v0,y=y_CH4画图
            y_tao=tao(y_CH4);                //光学厚度             x=txt[i].v0,y=y_tao画图
            y_tran=tran(y_tao);                 //透过率            x=txt[i].v0,y=y_tran画图
            array_tran[i]=y_tran;
    
        }
    
        avgs(txt[1].v0,array_tran, display);
    }
    
    
    
    2019-07-17 19:10:56
    赞同 展开评论 打赏
问答分类:
问答地址:
问答排行榜
最热
最新

相关电子书

更多
15分钟打造你自己的小程序 立即下载
小程序 大世界 立即下载
《15分钟打造你自己的小程序》 立即下载