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

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

#include "stdafx.h"
#include "ImageProcess.h"
#include "NDVIDlg.h"


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

/////////////////////////////////////////////////////////////////////////////
// CNDVIDlg dialog


CNDVIDlg::CNDVIDlg(CWnd* pParent /*=NULL*/)
	: CDialog(CNDVIDlg::IDD, pParent)
{
	//{{AFX_DATA_INIT(CNDVIDlg)
	m_sIRpath = _T("");
	m_sRedpath = _T("");
	m_sSavepath = _T("");
	//}}AFX_DATA_INIT
}


void CNDVIDlg::DoDataExchange(CDataExchange* pDX)
{
	CDialog::DoDataExchange(pDX);
	//{{AFX_DATA_MAP(CNDVIDlg)
	DDX_Text(pDX, IDC_EDIT1, m_sIRpath);
	DDX_Text(pDX, IDC_EDIT2, m_sRedpath);
	DDX_Text(pDX, IDC_EDIT3, m_sSavepath);
	//}}AFX_DATA_MAP
}


BEGIN_MESSAGE_MAP(CNDVIDlg, CDialog)
	//{{AFX_MSG_MAP(CNDVIDlg)
	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()

/////////////////////////////////////////////////////////////////////////////
// CNDVIDlg message handlers

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

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

void CNDVIDlg::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 CNDVIDlg::OnProcess() 
{
	// TODO: Add your control notification handler code here

	if (GetFileAttributes(m_sIRpath) == -1)
	{
		//the module does not exist
		GetDlgItem(IDC_EDIT1)->SetFocus();
		CString err;
		err.Format("Bad file path name: %s", m_sIRpath);		
		::MessageBox(NULL,err, "Error", MB_ICONERROR);
		return;
	}
	if (GetFileAttributes(m_sRedpath) == -1)
	{
		//the module does not exist
		GetDlgItem(IDC_EDIT2)->SetFocus();
		CString err;
		err.Format("Bad file path name: %s", m_sRedpath);		
		::MessageBox(NULL,err, "Error", MB_ICONERROR);
		return;
	}

	CString module = m_sModuleDirectory + "\\NDVI.exe";
	CString cmdline = m_sIRpath + m_sRedpath + m_sSavepath;
	if (IsDlgButtonChecked(IDC_CHECK1))
		cmdline += " 1";
	else
		cmdline += " 2";
	
	HINSTANCE h = ShellExecute(NULL, NULL, module, cmdline, NULL, SW_SHOWNORMAL);
//	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 NDVI module failed", "Error", MB_ICONERROR);
		return;
	}
}