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();
	}
}

运行程序

相关推荐
颖川守一1 小时前
C++c6-类和对象-封装-设计案例2-点和圆的关系
开发语言·c++
charlee442 小时前
将std容器的正向迭代器转换成反向迭代器
c++
arbboter2 小时前
【C++20】新特性探秘:提升现代C++开发效率的利器
c++·c++20·新特性·span·结构化绑定·初始化变量·模板参数推导
zc.ovo2 小时前
图论水题4
c++·算法·图论
眠りたいです3 小时前
Qt音频播放器项目实践:文件过滤、元数据提取与动态歌词显示实现
c++·qt·ui·音视频·媒体·qt5·mime
汤永红3 小时前
week2-[循环嵌套]数位和为m倍数的数
c++·算法·信睡奥赛
1白天的黑夜15 小时前
前缀和-560.和为k的子数组-力扣(LeetCode)
c++·leetcode·前缀和
No0d1es12 小时前
电子学会青少年软件编程(C/C++)5级等级考试真题试卷(2024年6月)
c语言·c++·算法·青少年编程·电子学会·五级
DjangoJason14 小时前
C++ 仿RabbitMQ实现消息队列项目
开发语言·c++·rabbitmq
weixin_3077791316 小时前
VS Code配置MinGW64编译GNU 科学库 (GSL)
开发语言·c++·vscode·算法