📄 dem_dealerdlg.cpp
字号:
// DEM_dealerDlg.cpp : implementation file
//
#include "stdafx.h"
#include "DEM_dealer.h"
#include "DEM_dealerDlg.h"
#include "ProgDlg.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
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()
/////////////////////////////////////////////////////////////////////////////
// CDEM_dealerDlg dialog
CDEM_dealerDlg::CDEM_dealerDlg(CWnd* pParent /*=NULL*/)
: CDialog(CDEM_dealerDlg::IDD, pParent)
{
//{{AFX_DATA_INIT(CDEM_dealerDlg)
m_Sigleinput = _T("");
m_Singleoutput = _T("");
m_BatchInput = _T("");
m_BatchOutput = _T("");
m_line1 = _T("");
m_line2 = _T("");
m_line3 = _T("");
m_line4 = _T("");
m_line5 = _T("");
m_line6 = _T("");
m_line7 = _T("");
m_line8 = _T("");
m_line9 = _T("");
m_line10 = _T("");
m_line11 = _T("");
m_line12 = _T("");
m_jia = _T("0");
m_jian = _T("0");
m_chen = _T("1");
m_chu = _T("1");
m_line124 = _T("");
m_line123 = _T("");
//}}AFX_DATA_INIT
// Note that LoadIcon does not require a subsequent DestroyIcon in Win32
m_hIcon = AfxGetApp()->LoadIcon(IDR_MAINFRAME);
}
void CDEM_dealerDlg::DoDataExchange(CDataExchange* pDX)
{
CDialog::DoDataExchange(pDX);
//{{AFX_DATA_MAP(CDEM_dealerDlg)
DDX_Text(pDX, IDC_EDIT1, m_Sigleinput);
DDX_Text(pDX, IDC_EDIT2, m_Singleoutput);
DDX_Text(pDX, IDC_EDIT3, m_BatchInput);
DDX_Text(pDX, IDC_EDIT4, m_BatchOutput);
DDX_Text(pDX, IDC_EDIT111, m_line1);
DDX_Text(pDX, IDC_EDIT112, m_line2);
DDX_Text(pDX, IDC_EDIT113, m_line3);
DDX_Text(pDX, IDC_EDIT114, m_line4);
DDX_Text(pDX, IDC_EDIT115, m_line5);
DDX_Text(pDX, IDC_EDIT116, m_line6);
DDX_Text(pDX, IDC_EDIT117, m_line7);
DDX_Text(pDX, IDC_EDIT118, m_line8);
DDX_Text(pDX, IDC_EDIT119, m_line9);
DDX_Text(pDX, IDC_EDIT120, m_line10);
DDX_Text(pDX, IDC_EDIT121, m_line11);
DDX_Text(pDX, IDC_EDIT122, m_line12);
DDX_Text(pDX, IDC_EDIT6, m_jia);
DDX_Text(pDX, IDC_EDIT7, m_jian);
DDX_Text(pDX, IDC_EDIT8, m_chen);
DDX_Text(pDX, IDC_EDIT9, m_chu);
DDX_Text(pDX, IDC_EDIT124, m_line124);
DDX_Text(pDX, IDC_EDIT123, m_line123);
//}}AFX_DATA_MAP
}
BEGIN_MESSAGE_MAP(CDEM_dealerDlg, CDialog)
//{{AFX_MSG_MAP(CDEM_dealerDlg)
ON_WM_SYSCOMMAND()
ON_WM_PAINT()
ON_WM_QUERYDRAGICON()
ON_BN_CLICKED(IDC_BUTTON1, OnButton1)
ON_BN_CLICKED(IDC_BUTTON2, OnButton2)
ON_BN_CLICKED(IDC_BUTTON3, OnButton3)
ON_BN_CLICKED(IDC_BUTTON4, OnButton4)
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// CDEM_dealerDlg message handlers
BOOL CDEM_dealerDlg::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 CDEM_dealerDlg::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 CDEM_dealerDlg::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 CDEM_dealerDlg::OnQueryDragIcon()
{
return (HCURSOR) m_hIcon;
}
void CDEM_dealerDlg::OnButton1()
{
static char BASED_CODE file[] = "DEM文件(*.dem)|*.dem|所有格式(*.*)|*.*||";
CFileDialog SelectFile(TRUE,NULL,NULL,OFN_HIDEREADONLY | OFN_OVERWRITEPROMPT,file,NULL);
SelectFile.DoModal();
m_Sigleinput = SelectFile.GetPathName();
if(m_Sigleinput.IsEmpty())
{
AfxMessageBox("请选择输入文件路径!");
return;
}
//////////////////////////////////////////////
else
{
fileUnion[0]=m_Sigleinput;
filenumber=1;
FILE * pfdem;
pfdem = fopen(m_Sigleinput,"r");
if(pfdem == NULL)
{
AfxMessageBox("文件打开失败!");
return;
}
UpdateData(FALSE);
BeginWaitCursor();
char Line1[1000];
char Line2[1000];
char Line3[1000];
char Line4[1000];
char Line5[1000];
char Line6[1000];
char Line7[1000];
char Line8[1000];
char Line9[1000];
char Line10[1000];
char Line11[1000];
char Line12[1000];
char Line123[1000];
char Line124[1000];
fgets(Line1,1000,pfdem);
fgets(Line2,1000,pfdem);
fgets(Line3,1000,pfdem);
fgets(Line4,1000,pfdem);
fgets(Line5,1000,pfdem);
fgets(Line6,1000,pfdem);
fgets(Line7,1000,pfdem);
fgets(Line8,1000,pfdem);
fgets(Line9,1000,pfdem);
fgets(Line10,1000,pfdem);
fgets(Line11,1000,pfdem);
fgets(Line12,1000,pfdem);
fscanf(pfdem,"%s%s",Line123,Line124);
////////////////////////////////////
m_line1=Line1;
m_line2=Line2;
m_line3=Line3;
m_line4=Line4;
m_line5=Line5;
m_line6=Line6;
m_line7=Line7;
m_line8=Line8;
m_line9=Line9;
m_line10=Line10;
m_line11=Line11;
m_line12=Line12;
m_line123=Line123;
m_line124=Line124;
fclose(pfdem);
}
UpdateData(FALSE);
}
void CDEM_dealerDlg::OnButton2()
{
static char BASED_CODE file[] = "DEM-DAT文件(*.dat)|*.dat|所有格式(*.*)|*.*||";
CFileDialog SelectFile(TRUE,NULL,NULL,OFN_HIDEREADONLY | OFN_OVERWRITEPROMPT,file,NULL);
SelectFile.DoModal();
m_Singleoutput = SelectFile.GetPathName();
if(m_Singleoutput.IsEmpty())
{
AfxMessageBox("请选择输出文件路径!");
return;
}
UpdateData(FALSE);
}
void CDEM_dealerDlg::OnButton3()
{
LPMALLOC pMalloc;
if (::SHGetMalloc(&pMalloc) == NOERROR)
{
BROWSEINFO bi;
char pszBuffer[MAX_PATH];
LPITEMIDLIST pidl;
bi.hwndOwner = GetSafeHwnd();
bi.pidlRoot = NULL;
bi.pszDisplayName = pszBuffer;
bi.lpszTitle = _T("请选择总文件目录:");
bi.ulFlags = BIF_RETURNFSANCESTORS | BIF_RETURNONLYFSDIRS;
bi.lpfn = NULL;
bi.lParam = 0;
if ((pidl=::SHBrowseForFolder(&bi)) != NULL)
{
// 将PIDL转换为路径串
if (::SHGetPathFromIDList(pidl, pszBuffer))
{
m_BatchInput = (LPCTSTR)pszBuffer;
if (pszBuffer[strlen(pszBuffer)-1] != '\\')
{
m_BatchInput += "\\";
}
}
else
{
m_BatchInput.Empty();
}
pMalloc->Free(pidl);
}
else
{
m_BatchInput.Empty();
}
pMalloc->Release();
}
else
{
m_BatchInput.Empty();
}
UpdateData(FALSE);
filenumber=0;
/////////////////////////////////////////
CString csou;
WIN32_FIND_DATA wfd;
csou = m_BatchInput + "*.*";
HANDLE hfind = ::FindFirstFile((LPCSTR)(LPCTSTR)csou, &wfd);
if (hfind != INVALID_HANDLE_VALUE)
{
// 搜索源目录下的所有文件
do
{
// 排除子目录项
if (wfd.dwFileAttributes&FILE_ATTRIBUTE_DIRECTORY)
{
continue;
}
CString filename;
filename=(LPCTSTR)wfd.cFileName;
csou = m_BatchInput;
csou += (LPCTSTR)wfd.cFileName;
fileUnion[filenumber]=csou;
filenumber++;
}while(::FindNextFile(hfind, &wfd));
::FindClose(hfind);
}
////////////////////////////////////////
}
void CDEM_dealerDlg::OnButton4()
{
LPMALLOC pMalloc;
if (::SHGetMalloc(&pMalloc) == NOERROR)
{
BROWSEINFO bi;
char pszBuffer[MAX_PATH];
LPITEMIDLIST pidl;
bi.hwndOwner = GetSafeHwnd();
bi.pidlRoot = NULL;
bi.pszDisplayName = pszBuffer;
bi.lpszTitle = _T("请选择总文件目录:");
bi.ulFlags = BIF_RETURNFSANCESTORS | BIF_RETURNONLYFSDIRS;
bi.lpfn = NULL;
bi.lParam = 0;
if ((pidl=::SHBrowseForFolder(&bi)) != NULL)
{
// 将PIDL转换为路径串
if (::SHGetPathFromIDList(pidl, pszBuffer))
{
m_BatchOutput = (LPCTSTR)pszBuffer;
if (pszBuffer[strlen(pszBuffer)-1] != '\\')
{
m_BatchOutput += "\\";
}
}
else
{
m_BatchOutput.Empty();
}
pMalloc->Free(pidl);
}
else
{
m_BatchOutput.Empty();
}
pMalloc->Release();
}
else
{
m_BatchOutput.Empty();
}
UpdateData(FALSE);
}
void CDEM_dealerDlg::OnOK()
{
UpdateData(TRUE);
double jia=0.0,jian=0.0,chen=0.0,chu=0.0;
jia=atof(m_jia);
jian=atof(m_jian);
chen=atof(m_chen);
chu=atof(m_chu);
/////////////////////////////////////////////////如果是单个文件处理进行以下操作/////////
CString des=_T("");
if(filenumber<2&&filenumber>0)
{
int index = m_Singleoutput.ReverseFind('\\');
des = m_Singleoutput.Left(index);
}
else if(filenumber>1)
{
int index = m_BatchOutput.ReverseFind('\\');
des = m_BatchOutput.Left(index);
}
CProgressDlg prgdlg;
prgdlg.Create();
prgdlg.StepIt();
for(int i=0;i<filenumber;i++)
{
CString filename=_T("");
CString Filename=_T("");
CString interchar=_T(".dem");
int index = fileUnion[i].ReverseFind('\\');
filename = fileUnion[i].Right(fileUnion[i].GetLength()-index-1);
if(filename.Find(interchar)!=-1)
{
int idex = filename.ReverseFind('.');
Filename = filename.Left(idex);
Filename=des+"\\"+ Filename+".dat";
}
FILE * pfdem1;
pfdem1 = fopen(fileUnion[i],"r");
FILE * pResult;
pResult = fopen(Filename,"w");
if(pfdem1 == NULL)
{
AfxMessageBox("文件打开失败!");
return;
}
UpdateData(FALSE);
BeginWaitCursor();
char Line1[1000];
char Line2[1000];
char Line3[1000];
char Line4[1000];
char Line5[1000];
char Line6[1000];
char Line7[1000];
char Line8[1000];
char Line9[1000];
char Line10[1000];
char Line11[1000];
char Line12[1000];
fgets(Line1,1000,pfdem1);
fgets(Line2,1000,pfdem1);
fgets(Line3,1000,pfdem1);
fgets(Line4,1000,pfdem1);
fgets(Line5,1000,pfdem1);
fgets(Line6,1000,pfdem1);
fgets(Line7,1000,pfdem1);
fgets(Line8,1000,pfdem1);
fgets(Line9,1000,pfdem1);
fgets(Line10,1000,pfdem1);
fgets(Line11,1000,pfdem1);
fgets(Line12,1000,pfdem1);
if(strcmp(Line8,Line9)!=0)
{
AfxMessageBox("此格式dem-水平竖直方向分辨率不同,欲处理还需要修改程序源代码!请联系程序编写人张涛!");
return;
}
////////////////////////////////////以上读取文件头///////////////////
BeginWaitCursor();
CString hang=_T("");
CString lie=_T("");
CString Xstr=_T("");
CString Ystr=_T("");
CString X_interval=_T("");
CString Y_interval=_T("");
CString scale=_T("");
hang=Line10;
lie=Line11;
Xstr=Line6;
Ystr=Line7;
X_interval=Line8;
Y_interval=Line9;
scale=Line12;
long int HANG=atoi(hang);
long int LIE=atoi(lie);
double X=0.0;
X=atof(Xstr);
double Y=0.0;
Y=atof(Ystr);
double XINERVAL=0.0;
XINERVAL=atof(X_interval);
double YINTERVAL=0.0;
YINTERVAL=atof(Y_interval);
long int SCALE=atoi(scale);
for(int o=1;o<HANG+1;o++)
{
PicPoint * pData1 = NULL;
pData1 = new PicPoint[LIE];
for(int oo=1;oo<LIE+1;oo++)
{
fscanf(pfdem1,"%s",pData1[oo].ZZ);
double XX=0.0,YY=0.0;
XX=(double)(X-(o-1)*XINERVAL);
YY=(double)(Y+(oo-1)*YINTERVAL);
double zz=0.0,zz1=0.0;
zz1=zz=atof(pData1[oo].ZZ);
if(zz<=0.0)
{zz=0.0;}
else if(zz>0.0)
{zz=(double)(((zz1+jia-jian)*chen)/chu);}
fprintf(pResult,"\t%.3lf\t%.3lf\t%.3lf\n",XX,YY,zz);
prgdlg.StepIt();
}
// delete pData1;
pData1 = NULL;
BeginWaitCursor();
}
EndWaitCursor();
fclose(pfdem1);
fclose(pResult);
}
AfxMessageBox("SUCESS!");
////////////////////////////////////////////////////////////////////
// CDialog::OnOK();
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -