www.gusucode.com > VC++遥感原理与数字摄影测量实习源码程序 > VC++遥感原理与数字摄影测量实习源码程序\code\ImageProcess\ChangeDtc.cpp

    // ChangeDtc.cpp : implementation file
// Download by http://www.NewXing.com

#include "stdafx.h"
#include "ImageProcess.h"
#include "ChangeDtc.h"

#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif

/////////////////////////////////////////////////////////////////////////////
// CChangeDtc dialog


CChangeDtc::CChangeDtc(CWnd* pParent /*=NULL*/)
	: CDialog(CChangeDtc::IDD, pParent)
{
	//{{AFX_DATA_INIT(CChangeDtc)
	m_sImage1path = _T("");
	m_sImage2path = _T("");
	m_sSavepath = _T("");
	//}}AFX_DATA_INIT
}


void CChangeDtc::DoDataExchange(CDataExchange* pDX)
{
	CDialog::DoDataExchange(pDX);
	//{{AFX_DATA_MAP(CChangeDtc)
	DDX_Text(pDX, IDC_EDIT1, m_sImage1path);
	DDX_Text(pDX, IDC_EDIT2, m_sImage2path);
	DDX_Text(pDX, IDC_EDIT3, m_sSavepath);
	//}}AFX_DATA_MAP
}


BEGIN_MESSAGE_MAP(CChangeDtc, CDialog)
	//{{AFX_MSG_MAP(CChangeDtc)
	ON_BN_CLICKED(ID_PROCESS, OnProcess)
	ON_BN_CLICKED(IDC_BUTTON1, OnButton1)
	ON_BN_CLICKED(IDC_BUTTON2, OnButton2)
	ON_BN_CLICKED(IDC_BUTTON3, OnButton3)
	//}}AFX_MSG_MAP
END_MESSAGE_MAP()

/////////////////////////////////////////////////////////////////////////////
// CChangeDtc message handlers

BOOL CChangeDtc::OnInitDialog() 
{
	CDialog::OnInitDialog();
	
	// TODO: Add extra initialization here
	CheckDlgButton(IDC_CHECK1,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 CChangeDtc::OnButton1() 
{
	// TODO: Add your control notification handler code here
	CFileDialog dlg(TRUE, NULL, NULL, OFN_EXPLORER);
	dlg.m_ofn.lpstrTitle = "Choose the 1st image\0";
	dlg.m_ofn.lpstrFilter = "BMP files\0*.bmp\0";
	dlg.m_ofn.lStructSize = 88;
	if (dlg.DoModal() == IDOK)
	{
		m_sImage1path = dlg.GetPathName();
	}
	m_sImage1path += " ";
	UpdateData(FALSE);
}

void CChangeDtc::OnButton2() 
{
	// TODO: Add your control notification handler code here
	CFileDialog dlg(TRUE, NULL, NULL, OFN_EXPLORER);
	dlg.m_ofn.lpstrTitle = "Choose the 2nd image\0";
	dlg.m_ofn.lpstrFilter = "BMP files\0*.bmp\0";
	dlg.m_ofn.lStructSize = 88;
	if (dlg.DoModal() == IDOK)
	{
		m_sImage2path = dlg.GetPathName();
	}
	m_sImage2path += " ";
	UpdateData(FALSE);
}

void CChangeDtc::OnButton3() 
{
	// 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_sSavepath = dlg.GetPathName();
	}
	UpdateData(FALSE);
}

void CChangeDtc::OnProcess() 
{
	// TODO: Add your control notification handler code here
	if (GetFileAttributes(m_sImage1path) == -1)
	{
		//the module does not exist
		GetDlgItem(IDC_EDIT1)->SetFocus();
		CString err;
		err.Format("Bad file path name: %s", m_sImage1path);		
		::MessageBox(NULL,err, "Error", MB_ICONERROR);
		return;
	}
	if (GetFileAttributes(m_sImage2path) == -1)
	{
		//the module does not exist
		GetDlgItem(IDC_EDIT2)->SetFocus();
		CString err;
		err.Format("Bad file path name: %s", m_sImage2path);		
		::MessageBox(NULL,err, "Error", MB_ICONERROR);
		return;
	}

	CString module = m_sModuleDirectory + "\\ChangeDetection.exe";
	CString cmdline = m_sImage1path + m_sImage2path + m_sSavepath;
	if (IsDlgButtonChecked(IDC_CHECK1))
		cmdline += " 1";
	else
		cmdline += " 2";
	
	HINSTANCE h = ShellExecute(NULL, NULL, module, cmdline, NULL, SW_SHOWNORMAL);
	if ((int)h <= 32)
	{
		MessageBox("Start NDVI module failed", "Error", MB_ICONERROR);
		return;
	}
}