www.gusucode.com > VC++遥感原理与数字摄影测量实习源码程序 > VC++遥感原理与数字摄影测量实习源码程序\code\ImageProcess\MoravecDlg.cpp
//Download by http://www.NewXing.com // MoravecDlg.cpp : implementation file // #include "stdafx.h" #include "ImageProcess.h" #include "MoravecDlg.h" #ifdef _DEBUG #define new DEBUG_NEW #undef THIS_FILE static char THIS_FILE[] = __FILE__; #endif ///////////////////////////////////////////////////////////////////////////// // CMoravecDlg dialog CMoravecDlg::CMoravecDlg(CWnd* pParent /*=NULL*/) : CDialog(CMoravecDlg::IDD, pParent) { //{{AFX_DATA_INIT(CMoravecDlg) m_strSrcFile = _T(""); m_strDstImage = _T(""); m_strDstData = _T(""); m_nThreshold = 0; m_nWindowSize1 = 0; m_nWindowSize2 = 0; //}}AFX_DATA_INIT } void CMoravecDlg::DoDataExchange(CDataExchange* pDX) { CDialog::DoDataExchange(pDX); //{{AFX_DATA_MAP(CMoravecDlg) DDX_Text(pDX, IDC_EDIT1, m_strSrcFile); DDX_Text(pDX, IDC_EDIT2, m_strDstImage); DDX_Text(pDX, IDC_EDIT3, m_strDstData); DDX_Text(pDX, IDC_EDIT4, m_nThreshold); DDX_Text(pDX, IDC_EDIT5, m_nWindowSize1); DDX_Text(pDX, IDC_EDIT6, m_nWindowSize2); //}}AFX_DATA_MAP } BEGIN_MESSAGE_MAP(CMoravecDlg, CDialog) //{{AFX_MSG_MAP(CMoravecDlg) ON_BN_CLICKED(IDC_BUTTON1, OnButton1) ON_BN_CLICKED(IDC_BUTTON2, OnButton2) ON_BN_CLICKED(IDC_BUTTON4, OnButton4) ON_BN_CLICKED(ID_PROCESS, OnProcess) //}}AFX_MSG_MAP END_MESSAGE_MAP() ///////////////////////////////////////////////////////////////////////////// // CMoravecDlg message handlers BOOL CMoravecDlg::OnInitDialog() { CDialog::OnInitDialog(); // TODO: Add extra initialization here CheckDlgButton(IDC_CHECK1, 1); CheckDlgButton(IDC_CHECK2, 1); char current[MAX_PATH] = {0}; GetCurrentDirectory(MAX_PATH, current); m_sModuleDirectory.Format("%s",current); return TRUE; // return TRUE unless you set the focus to a control // EXCEPTION: OCX Property Pages should return FALSE } void CMoravecDlg::OnButton1() { // TODO: Add your control notification handler code here CFileDialog dlg(TRUE, NULL, NULL, OFN_EXPLORER); dlg.m_ofn.lpstrTitle = "Choose the source 8bit bitmap\0"; dlg.m_ofn.lpstrFilter = "BMP files\0*.bmp\0"; dlg.m_ofn.lStructSize = 88; if (dlg.DoModal() == IDOK) { m_strSrcFile = dlg.GetPathName(); } m_strSrcFile += " "; UpdateData(FALSE); } void CMoravecDlg::OnButton2() { // TODO: Add your control notification handler code here CFileDialog dlg(FALSE, NULL, NULL, OFN_EXPLORER | OFN_OVERWRITEPROMPT); dlg.m_ofn.lpstrTitle = "Save the result image\0"; dlg.m_ofn.lpstrFilter = "BMP files\0*.bmp\0"; dlg.m_ofn.lpstrDefExt = ".bmp\0"; dlg.m_ofn.lStructSize = 88; if (dlg.DoModal() == IDOK) { m_strDstImage = dlg.GetPathName(); } m_strDstImage += " "; UpdateData(FALSE); } void CMoravecDlg::OnButton4() { // TODO: Add your control notification handler code here CFileDialog dlg(FALSE, NULL, NULL, OFN_EXPLORER | OFN_OVERWRITEPROMPT); dlg.m_ofn.lpstrTitle = "Save the result data\0"; dlg.m_ofn.lpstrFilter = "TXT files\0*.txt\0"; dlg.m_ofn.lpstrDefExt = ".txt\0"; dlg.m_ofn.lStructSize = 88; if (dlg.DoModal() == IDOK) { m_strDstData = dlg.GetPathName(); } m_strDstData += " "; UpdateData(FALSE); } void CMoravecDlg::OnProcess() { // TODO: Add your control notification handler code here UpdateData(TRUE); if (GetFileAttributes(m_strSrcFile) == -1) { //the module does not exist GetDlgItem(IDC_EDIT1)->SetFocus(); CString err; err.Format("Bad file path name: %s", m_strSrcFile); ::MessageBox(NULL,err, "Error", MB_ICONERROR); return; } if (m_strDstData.IsEmpty() || m_strDstImage.IsEmpty()) { MessageBox("Bad file path name", "Error", MB_ICONERROR); return; } if (m_nThreshold <= 0 || m_nWindowSize1 <= 0 || m_nWindowSize2 <= 0) { MessageBox("Bad parameters exist", "Error", MB_ICONERROR); return; } CString module = m_sModuleDirectory + "\\Moravec.exe"; CString cmdline = m_strSrcFile + m_strDstImage + m_strDstData; CString str; str.Format("%d %d %d", m_nThreshold, m_nWindowSize1, m_nWindowSize2); cmdline += str; if (IsDlgButtonChecked(IDC_CHECK1)) cmdline += " 1"; else cmdline += " 2"; if (IsDlgButtonChecked(IDC_CHECK2)) cmdline += " 1"; else cmdline += " 2"; HINSTANCE h = ShellExecute(NULL, NULL, module, cmdline, NULL, SW_HIDE); // STARTUPINFO sui; // PROCESS_INFORMATION pi; // BOOL ret = CreateProcess("NDVI.exe",(LPTSTR)cmdline.GetBuffer(cmdline.GetLength()),0,0,0,CREATE_NEW_PROCESS_GROUP,0,0,&sui,&pi); if ((int)h <= 32) { MessageBox("Start Moravec module failed", "Error", MB_ICONERROR); return; } }