MFC工控项目实例之三theApp变量传递对话框参数

承接专栏《MFC工控项目实例之二主菜单制作》

用theApp变量传递对话框参数实时改变iPlotX坐标轴最小值、最大值。

1、新建IDD_SYS_DATA对话框,类名SYS_DATA。

三个编辑框IDC_EDIT1、IDC_EDIT2、IDC_EDIT3变量如图

2、SEAL_PRESSURE.h中添加代码

cpp 复制代码
#include "resource.h"		// main symbols
typedef struct sys_para
{
	union
	{
		struct
		{
		double	m_fMaxTime;
double	m_fMinTime;
double	m_fMaxPressure;
double	m_fMinPressure;				
				
		};
		char len1[4096];
	};

}SYS_PARA;


class CSEAL_PRESSUREApp : public CWinApp
{
public:
	CSEAL_PRESSUREApp();
    SYS_PARA m_sys_data;
	public:
	virtual BOOL InitInstance();
	DECLARE_MESSAGE_MAP()
};

extern class CSEAL_PRESSUREApp theApp;

3、SEAL_PRESSUREDlg.h中添加代码

cpp 复制代码
public:
void iPlotX_SHOW();

4、SYS_DATA.cpp中添加代码

cpp 复制代码
void SYS_DATA::OnOK() 
{
	// TODO: Add extra validation here	
	if(!UpdateData())
		return;
	CDialog::OnOK();
    theApp.m_sys_data.m_fMaxTime=m_fMaxTime;
	theApp.m_sys_data.m_fMinPressure=m_fMinPressure;
	theApp.m_sys_data.m_fMaxPressure=m_fMaxPressure;
}

5、SEAL_PRESSUREDlg.cpp中添加代码

cpp 复制代码
#include "SEAL_PRESSURE.h"
#include "SEAL_PRESSUREDlg.h"
#include "SYS_DATA.h"
#include "iplotchannelx.h"
#include "iPlotAxisX.h"
void CSEAL_PRESSUREDlg::iPlotX_SHOW() 
{
	// TODO: Add your control notification handler code here
	CiPlotAxisX axis;		
		axis = m_ctrlPlot_1.GetXAxis(0);
		axis.SetMin(0);
		axis.SetSpan(theApp.m_sys_data.m_fMaxTime);
		axis = m_ctrlPlot_1.GetYAxis(0);
		axis.SetMin(theApp.m_sys_data.m_fMinPressure);
		axis.SetSpan(theApp.m_sys_data.m_fMaxPressure - theApp.m_sys_data.m_fMinPressure);

}

void CSEAL_PRESSUREDlg::OnSysData() 
{
	
 SYS_DATA dlg;
	if(dlg.DoModal() == IDOK)
	{
		iPlotX_SHOW();
		Invalidate();
	}
}

运行程序

相关推荐
superior tigre10 分钟前
C++学习:六个月从基础到就业——C++20:协程(Coroutines)
c++·学习·c++20
superior tigre15 分钟前
C++学习:六个月从基础到就业——C++20:概念(Concepts)
c++·学习·c++20
wuqingshun31415929 分钟前
经典算法 (A/B) mod C
c语言·开发语言·c++·算法·蓝桥杯
半青年34 分钟前
Qt图表库推荐指南与分析
c语言·开发语言·javascript·c++·qt·信息可视化
姬公子52140 分钟前
leetcodehot100刷题——排序算法总结
数据结构·c++·算法·排序算法
烦躁的大鼻嘎1 小时前
【Linux】ELF与动静态库的“暗黑兵法”:程序是如何跑起来的?
linux·运维·服务器·c++·vscode·ubuntu
ShineSpark1 小时前
C++面试2——C与C++的关系
c语言·c++·面试
无聊的小坏坏2 小时前
【C++】set、map 容器的使用
c++·stl
※※冰馨※※2 小时前
彻底解决QT5 中文编译不过问题
c++·windows·qt
扶尔魔ocy2 小时前
QT使用QXlsx读取excel表格中的图片
c++·excel