⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 3321batchprocessdlg.cpp

📁 美国TSI公司3321仪器数据文件批处理
💻 CPP
📖 第 1 页 / 共 2 页
字号:
// 3321batchprocessDlg.cpp : implementation file
//

#include "stdafx.h"
#include "3321batchprocess.h"
#include "3321batchprocessDlg.h"
#include "FECFileDialog.h"

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

CString path_quanju;
/////////////////////////////////////////////////////////////////////////////
// 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()

/////////////////////////////////////////////////////////////////////////////
// CMy3321batchprocessDlg dialog

CMy3321batchprocessDlg::CMy3321batchprocessDlg(CWnd* pParent /*=NULL*/)
	: CDialog(CMy3321batchprocessDlg::IDD, pParent)
{
	//{{AFX_DATA_INIT(CMy3321batchprocessDlg)
	m_setnumber = 0;
	m_printfscreen = _T("");
	//}}AFX_DATA_INIT
	// Note that LoadIcon does not require a subsequent DestroyIcon in Win32
	m_hIcon = AfxGetApp()->LoadIcon(IDR_MAINFRAME);
}

void CMy3321batchprocessDlg::DoDataExchange(CDataExchange* pDX)
{
	CDialog::DoDataExchange(pDX);
	//{{AFX_DATA_MAP(CMy3321batchprocessDlg)
	DDX_Text(pDX, IDC_EDIT1, m_setnumber);
	DDX_Text(pDX, IDC_STATIC1, m_printfscreen);
	//}}AFX_DATA_MAP
}

BEGIN_MESSAGE_MAP(CMy3321batchprocessDlg, CDialog)
	//{{AFX_MSG_MAP(CMy3321batchprocessDlg)
	ON_WM_SYSCOMMAND()
	ON_WM_PAINT()
	ON_WM_QUERYDRAGICON()
	ON_BN_CLICKED(IDC_BUTTON1, OnButton1)
	ON_EN_CHANGE(IDC_EDIT1, OnChangeEdit1)
	ON_BN_CLICKED(IDC_BUTTON2, Onbatchtotalconcentration)
	ON_BN_CLICKED(IDC_BUTTON3, OnButton3)
	ON_BN_CLICKED(IDC_BUTTON4, OnButton4)
	//}}AFX_MSG_MAP
END_MESSAGE_MAP()

/////////////////////////////////////////////////////////////////////////////
// CMy3321batchprocessDlg message handlers

BOOL CMy3321batchprocessDlg::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
	m_setnumber=0;
	return TRUE;  // return TRUE  unless you set the focus to a control
}

void CMy3321batchprocessDlg::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 CMy3321batchprocessDlg::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 CMy3321batchprocessDlg::OnQueryDragIcon()
{
	return (HCURSOR) m_hIcon;
}

void CMy3321batchprocessDlg::OnButton1() 
{
	// TODO: Add your control notification handler code here
		 CString pathName("", MAX_PATH);	//文件路径名,路径字串
		 CString str_tmp;/////////临时转换用
		 CString getfilename;////获取打开批文件的文件名
		 CString getpathname;///////////获取打开批文件的路径名
		 CString title;////////////获取批处理文件左侧的名字,如Sample File,Date,等等		  
         CString time0,time1,time2,time3,time4,time5,time6;////////获取时间信息
         int setnumber,ifover=0;///////setnumber代表文件数,ifover用于判断是否结束
         CStdioFile tf;
         FILE *filesave;
         CString signal_str;//读取批处理文件的内容
         int signal_num=0;	
         TCHAR ch=9;  ///9代表tab键,用ultredit一看就明白拉
       
/////////////////打开批处理文件
		 setnumber=m_setnumber;////////把接收到的要处理数据的组数,传给内部变量
		 UpdateData(true);
	static char BASED_CODE szFilter[] = "3321数据文件Files (*.dat;*.txt)|*.dat;*.txt|Lidar 二进制数据文件(*.sig)|*.sig||";
	CFileDialog fd(TRUE,NULL,NULL,OFN_HIDEREADONLY,szFilter);
	fd.m_ofn.lpstrTitle="查找3321数据文件...";
	if(fd.DoModal()==IDCANCEL)
		return;

	pathName=fd.GetPathName();///////获取绝对路径,包括文件名    
	tf.Open(fd.GetPathName(),CFile::modeRead|CFile::typeText);////打开批处理文件
	if(!tf)
	{
		AfxEndThread(0);
		AfxMessageBox("Failed to open file,Exit!!");
	}
	
       
begin: 
	   tf.SeekToBegin();/////把指针移到文件头
	   while(tf.ReadString(signal_str))//////////////这一部分是提取时间信息的
	   {		        
			    	if(signal_num==7)
					 {
			                str_tmp=signal_str.Right(signal_str.GetLength()-signal_str.Find(ch)-1);
			               time1=str_tmp.Mid(0,2);//month
			                time2=str_tmp.Mid(3,2);//date
			                time3=str_tmp.Mid(6,2);//year                
					 }
		             if(signal_num==8)
					 {
						 str_tmp=signal_str;
						for(int i=0;i<=ifover;i++)
						 {
                           str_tmp=str_tmp.Right(str_tmp.GetLength()-str_tmp.Find(ch)-1);						   
						 }
						    time4=str_tmp.Mid(0,2);//hour
			                 time5=str_tmp.Mid(3,2);//minute
			                time6=str_tmp.Mid(6,2);///second
			                time0="20"+time3+time1+time2+time4+time5+time6;///////////年,月,日,小时,分钟,秒
					    //	AfxMessageBox(time0);
					 }
	    	         
		     signal_num+=1;
	   }                        
       signal_num=0;		
	   getfilename=fd.GetFileName();	   
	   getpathname=pathName.Left(pathName.GetLength()-getfilename.GetLength());	  
	   time0+=".dat";
	   getpathname+=time0;
	   //////////改名结束


	  ////////////写入保存的文件中
	if( (filesave=fopen( getpathname, "w" )) == NULL)  ///if( (fp1=fopen("C:\\ti\\myprojects\\fopentry\\Debug\\1.dat", "w+" )) == NULL)

	{
         AfxMessageBox("file could not be opened");
		 exit(1);
	}   
     tf.SeekToBegin();/////移到文件头
	while(tf.ReadString(signal_str))
	{
			if(signal_num<6)
			{
			    fprintf(filesave,"%s\n",signal_str);////头6行直接读出
			}
			if(signal_num>=6 && signal_num<=87)//if(signal_num>=5 && signal_num<10)
			{
                str_tmp=signal_str;
			    title=signal_str.Left(signal_str.Find(ch));	////////读取文件左侧部分			
				for(int i=0;i<=ifover;i++)
				{						
				     str_tmp=str_tmp.Right(str_tmp.GetLength()-str_tmp.Find(ch)-1);	//////读取数据				
				}
				
				if(ifover==setnumber-1)//////////处理最后一组的情况
				{
					str_tmp=str_tmp.Right(str_tmp.GetLength()-str_tmp.Find(ch)-1);
//					AfxMessageBox(str_tmp);//overjudge=atof(str_tmp);
					fprintf(filesave,"%s\t%s\n",title,str_tmp);
				}
				else////////非最后一组的情况
				{
				    str_tmp=str_tmp.Left(str_tmp.Find(ch));
			       fprintf(filesave,"%s\t%s\n",title,str_tmp);
				}
						        
			}
			signal_num+=1;
	}
	signal_num=0;
	fclose(filesave);//关闭保存文件
	  ifover+=1;
	  m_printfscreen.Format("%d",ifover);//目的在屏幕显示现在正在处理那个文件
	  UpdateData(false);

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -