📄 txtmtotxtedlg.cpp
字号:
// TxtMToTxtEDlg.cpp : implementation file
//
#include "stdafx.h"
#include "TxtMToTxtE.h"
#include "TxtMToTxtEDlg.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
/////////////////////////////////////////////////////////////////////////////
// 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 void OnButton1();
//}}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)
ON_BN_CLICKED(IDC_BUTTON1, OnButton1)
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// CTxtMToTxtEDlg dialog
CTxtMToTxtEDlg::CTxtMToTxtEDlg(CWnd* pParent /*=NULL*/)
: CDialog(CTxtMToTxtEDlg::IDD, pParent)
{
SUM = MAX = nF = 0;
bComp = FALSE;
bFirst = FALSE;
//{{AFX_DATA_INIT(CTxtMToTxtEDlg)
m_strFiles = _T("");
//}}AFX_DATA_INIT
// Note that LoadIcon does not require a subsequent DestroyIcon in Win32
m_hIcon = AfxGetApp()->LoadIcon(IDR_MAINFRAME);
}
void CTxtMToTxtEDlg::DoDataExchange(CDataExchange* pDX)
{
CDialog::DoDataExchange(pDX);
//{{AFX_DATA_MAP(CTxtMToTxtEDlg)
DDX_Control(pDX, IDC_BT_CHANGE, m_btChange);
DDX_Control(pDX, IDC_PRO, m_CheckPro);
DDX_Text(pDX, IDC_ED_strFile, m_strFiles);
//}}AFX_DATA_MAP
}
BEGIN_MESSAGE_MAP(CTxtMToTxtEDlg, CDialog)
//{{AFX_MSG_MAP(CTxtMToTxtEDlg)
ON_WM_SYSCOMMAND()
ON_WM_PAINT()
ON_WM_QUERYDRAGICON()
ON_BN_CLICKED(IDC_BT_OPEN, OnBtOpen)
ON_BN_CLICKED(IDC_BT_CHANGE, OnBtChange)
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// CTxtMToTxtEDlg message handlers
BOOL CTxtMToTxtEDlg::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
return TRUE; // return TRUE unless you set the focus to a control
}
void CTxtMToTxtEDlg::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 CTxtMToTxtEDlg::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 CTxtMToTxtEDlg::OnQueryDragIcon()
{
return (HCURSOR) m_hIcon;
}
void CTxtMToTxtEDlg::OnBtOpen()
{
// TODO: Add your control notification handler code here
CFileDialog openBox(TRUE,NULL,"", OFN_ALLOWMULTISELECT," All Files(*.*)|*.txt||",NULL);
openBox.m_ofn.lpstrTitle="选择一个或多个文件并转换";
CString z1,z2,s1;
int n1,n2,NN;
n1 = n2 = NN =0;
int i=0;
if(openBox.DoModal()==IDOK) //|OFN_LONGNAMES显示文件对话框 OFN_HIDEREADONLY OFN_ALLOWMULTISELECT
{
z1 = openBox.GetPathName();
z2 = openBox.GetFileName();
//AfxMessageBox(z1+" -22- "+z2);
if(z2.IsEmpty())
{
n1=z1.GetLength();
POSITION pos = openBox.GetStartPosition();
do{
s1 = openBox.GetNextPathName(pos);
n2 = s1.GetLength();
ss[i++] = s1.Mid(n1+1,n2-n1);
}while(pos !=NULL);
NN = i;
for(int j=0;j<NN;j++)
m_strFiles += ss[j]+" ";
bComp = TRUE;
nF = NN;
}
else
{
m_strFiles= z2;
bComp = FALSE;
}
UpdateData(FALSE);
}
m_btChange.EnableWindow(TRUE);
return ;
}
void CTxtMToTxtEDlg::OnBtChange()
{
// TODO: Add your control notification handler code here
int i,n;
if(!bComp)
{
read(m_strFiles); //读取数据
n = m_strFiles.GetLength();
CString s0;
s0 = m_strFiles.Mid(0,n-4);
change(s0+".res"); //转换数据
bFirst = FALSE;
int nL=nFirst*500;
m_CheckPro.SetRange(0,nL);
for(i=0;i<nL;i++)
m_CheckPro.SetPos(i);
}
else
{
CString s0;
for(i=0;i<nF;i++)
{
read(ss[i]);
n = ss[i].GetLength();
s0 = ss[i].Mid(0,n-4);
change(s0+".res");
bFirst = FALSE;
int nL=nFirst*500;
m_CheckPro.SetRange(0,nL);
for(int j=0;j<nL;j++)
m_CheckPro.SetPos(j);
}
}
m_strFiles = _T(" ");
m_btChange.EnableWindow(FALSE);
UpdateData(FALSE);
}
void CTxtMToTxtEDlg::read(const CString &strFilename)
{
CStdioFile file;
int i=0;
char *name1;
int M=strlen(strFilename);
name1=new char[M];
strcpy(name1,strFilename);
file.Open(name1,CFile::modeRead);
SUM =20000;
ps =new CString[SUM];
for(i=0;i<SUM;i++)
{
file.ReadString(ps[i]);
if(i>1 && atoi(ps[i-1]) !=0 && atoi(ps[i]) ==0 && !bFirst)
{
bFirst = TRUE;
nFirst = i;
}
}
file.Close();
}
void CTxtMToTxtEDlg::change(const CString& filename)
{
if(!filename)
return;
else
{
char *name1;
int M=strlen(filename);
name1=new char[M];
strcpy(name1,filename);
FILE *fp=fopen(name1,"w");
CString s1,s2,s3;
double f1,f2,f22;
int sp[10];
int k,j,jk,nMax,nm;
f1 = f2 = f22 = 0.0;
j = jk = nMax = nm =0;
char m_zzx[150];
// BOOL bEnd = FALSE;
// UpdateData(TRUE);
// m_CheckPro.SetRange(0,SUM);
for(int i=0;i<nFirst;i++)
{ //
// if( ps[i].GetLength()>0 && (atof(ps[i+1]) !=0) )
// {
// MAX++;
jk = ps[i].GetLength();
strcpy(m_zzx,ps[i]);
k=0;
for(j=0;j<jk-1;j++)
{
if((isspace(m_zzx[j])) && (!isspace(m_zzx[j+1])))
{
sp[k] = j;
k++;
nMax++;
}
}
s1 = ps[i].Mid(0,sp[0]);
s2 = ps[i].Mid(sp[0]+1,sp[1]-sp[0]);
s3 = ps[i].Mid(sp[1]+1,jk-sp[1]);
if(i==0)
{
fprintf(fp,"%s\t\t%s\n","DEPTH",s3);
}
else {//i>1
f1 = atof(s1);
f2 = atof(s2);
if(i>1 && f2 != f22 )
{
fprintf(fp,"%.4f\t",(f1+f22)/2.0);
for(nm= 0;nm<nMax-1;nm++)
{
fprintf(fp,"-999.25\t");
}
fprintf(fp,"\n");
}
// if( f2>f22 && atof(s3)!=0 )
// {
fprintf(fp,"%.4f\t%s\n",f1,s3);
fprintf(fp,"%.4f\t%s\n",f2,s3);
// }
nMax =0;
f22 = f2;
}
// m_CheckPro.SetPos(i);
// UpdateData(FALSE);
// }
}
fclose(fp);
}
delete[] ps;
// nFirst = 0;
}
void CAboutDlg::OnButton1()
{
// TODO: Add your control notification handler code here
CString s,s2;
s = " 34 5 ";
int n;
n = atoi(s);
if(n==0)
n=3;
else
n = s.GetLength();
s2.Format("%d",n);
AfxMessageBox(s2);
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -