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

📄 5454dlg.cpp

📁 针对国内环境检测领域内
💻 CPP
字号:
// 5454Dlg.cpp : implementation file
//

#include "stdafx.h"
#include "5454.h"
#include "5454Dlg.h"

#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
CString pathName("", MAX_PATH);	//文件路径名,路径字串
float signal[500];
double date[500];////////这个地方用int,float类型,精度太小
CString str_tmp;
CString pathtmp;	//路径字串
int count=0;
CString time0;

/////////////////////////////////////////////////////////////////////////////
// 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()

/////////////////////////////////////////////////////////////////////////////
// CMy5454Dlg dialog

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

void CMy5454Dlg::DoDataExchange(CDataExchange* pDX)
{
	CDialog::DoDataExchange(pDX);
	//{{AFX_DATA_MAP(CMy5454Dlg)
	DDX_Text(pDX, IDC_EDIT1, m_str);
	//}}AFX_DATA_MAP
}

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

/////////////////////////////////////////////////////////////////////////////
// CMy5454Dlg message handlers

BOOL CMy5454Dlg::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
	for(int i=0;i<500;i++)
	{
		signal[i]=0;
	}
	return TRUE;  // return TRUE  unless you set the focus to a control
}

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

void CMy5454Dlg::OnButton1() 
{
	// TODO: Add your control notification handler code here
	
	CString pathName("", MAX_PATH);	//文件路径名,路径字串
	 
   CStdioFile tf;
   CString signal_str,signal_str1;
    int signal_num=0;
	int signal_count=0;
   CString str_tmp,str_tmp1,str_sig;
   TCHAR ch=9;  ///9代表tab键,用ultredit一看就明白拉


	static char BASED_CODE szFilter[] = "Lidar ASCII数据文件Files (*.dat;*.txt)|*.dat;*.txt|Lidar 二进制数据文件(*.sig)|*.sig||";
	CFileDialog fd(TRUE,NULL,NULL,OFN_HIDEREADONLY,szFilter);
	fd.m_ofn.lpstrTitle="查找激光雷达数据文件...";
	if(fd.DoModal()==IDCANCEL)
		return;

	pathName=fd.GetPathName();
	
	CString timestr="";	
		
    m_str=pathName;
     UpdateData(false);
    

	tf.Open(fd.GetPathName(),CFile::modeRead|CFile::typeText);
	if(!tf)
	{
		AfxEndThread(0);
		AfxMessageBox("Failed to open file,Exit!!");
	}
	
       CString time1,time2,time3,time4,time5,time6;
	   while(tf.ReadString(signal_str))//////////////这一部分是对付常规保存,即3321默认保存结果
	   {
		        if(signal_num==0)
				{			    
                  
		          str_tmp=signal_str.Left(6);
				  
			     //
			       if(str_tmp.Compare("Sample")==0)
				   {
					
				   }
				   else
				   {
					 goto none;
					 
				   }    
				  		
				}
			    	if(signal_num==7)
					 {
			                str_tmp=signal_str.Right(signal_str.GetLength()-signal_str.Find(ch)-1);
			               time1=str_tmp.Mid(0,2);
			                time2=str_tmp.Mid(3,2);
			                time3=str_tmp.Mid(6,2);
                
					 }
		             if(signal_num==8)
					 {
			                str_tmp=signal_str.Right(8);
			                time4=str_tmp.Mid(0,2);
			                 time5=str_tmp.Mid(3,2);
			                time6=str_tmp.Mid(6,2);
			                time0="20"+time3+time1+time2+time4+time5+time6;///////////年,月,日,小时,分钟,秒
					 }
	    	         if(signal_num==87)
					 {
                             str_tmp=signal_str.Right(signal_str.GetLength()-signal_str.Find(ch)-1);		
		                      signal[count]=float(atof(str_tmp));			  
					 }	
		     signal_num+=1;
	   }
none:	  tf.SeekToBegin();
	   while(tf.ReadString(signal_str1))///////////这一部分是专门对付,王倍处理后的数据

{
			   if(signal_count==0)
			   {
				   str_tmp1=signal_str1.Left(6);
				  
				    
			            if(str_tmp1.Compare("Sample")==0)
						{
				                	goto none1;
						}
				          else
						  {
					                pathtmp=pathName.Right(16);
                                 	timestr=pathtmp.Left(12);
					            	time1=timestr.Mid(4,2);
					             	time2=timestr.Mid(0,2);
					            	time3=timestr.Mid(2,2);
					            	time4=timestr.Mid(6,2);
					            	time5=timestr.Mid(8,2);
						            time6=timestr.Mid(10,2);
					             	time0="20"+time1+time2+time3+time4+time5+time6;
                                    
					    	 //////////以上为求出时间,用以作为文件名
							         str_tmp1=signal_str1.Right(signal_str1.GetLength()-signal_str1.Find(ch)-1);		
		                             signal[count]+=float(atof(str_tmp1));
						            
						  }  
			   }
                    if(signal_count>0)
					{

                      str_tmp1=signal_str1.Right(signal_str1.GetLength()-signal_str1.Find(ch)-1);		
		              signal[count]+=float(atof(str_tmp1));
					  
					}
                     
				   signal_count+=1;				 
}
none1:	   date[count]=atof(time0);
     	tf.Close();	//关闭文件
		signal_num=0;
		signal_count=0;
		count+=1;

	
}

void CMy5454Dlg::Onsave() 
{
	// TODO: Add your control notification handler code here
	FILE *fr;
	
	if(!(fr=fopen("d:\\Totalconcentration.lvd","w")))	
	{
		AfxMessageBox("Failed to open file to write result!!!!");
		return;
	}
	
	for(int i=0;i<=count;i++)
	{
	fprintf(fr,"%-.f\t%-.3f\n",date[i],signal[i]);
	}
     fclose(fr);//关闭临时文件
	 for(int j=0;j<500;j++)
	{
		signal[j]=0;
	}
}

⌨️ 快捷键说明

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