?? 5454dlg.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 + -