⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 subsetpaldlg.cpp

📁 提取NOAA PAL(Pathfinder AVHRR Land cover data)中的中国部分子集
💻 CPP
字号:
// SubsetPALDlg.cpp : implementation file
//

#include "stdafx.h"
#include "SubsetPAL.h"
#include "SubsetPALDlg.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()

/////////////////////////////////////////////////////////////////////////////
// CSubsetPALDlg dialog

CSubsetPALDlg::CSubsetPALDlg(CWnd* pParent /*=NULL*/)
	: CDialog(CSubsetPALDlg::IDD, pParent)
{
	//{{AFX_DATA_INIT(CSubsetPALDlg)
	//}}AFX_DATA_INIT
	// Note that LoadIcon does not require a subsequent DestroyIcon in Win32
	m_hIcon = AfxGetApp()->LoadIcon(IDR_MAINFRAME);
}

void CSubsetPALDlg::DoDataExchange(CDataExchange* pDX)
{
	CDialog::DoDataExchange(pDX);
	//{{AFX_DATA_MAP(CSubsetPALDlg)
	DDX_Text(pDX, IDC_ED_NLRLINE, m_nCorner.LRLine);
	DDV_MinMaxUInt(pDX, m_nCorner.LRLine, 1, 2168);
	DDX_Text(pDX, IDC_ED_NULLINE, m_nCorner.ULLine);
	DDV_MinMaxUInt(pDX, m_nCorner.ULLine, 1, 2168);
	DDX_Text(pDX, IDC_ED_NULSAMPLE, m_nCorner.ULSample);
	DDV_MinMaxUInt(pDX, m_nCorner.ULSample, 1, 5004);
	DDX_Text(pDX, IDC_ED_NLRSAMPLE, m_nCorner.LRSample);
	DDV_MinMaxUInt(pDX, m_nCorner.LRSample, 1, 5004);
	DDX_Text(pDX, IDC_ED_SLRLINE, m_sCorner.LRLine);
	DDV_MinMaxUInt(pDX, m_sCorner.LRLine, 1, 2168);
	DDX_Text(pDX, IDC_ED_SLRSAMPLE, m_sCorner.LRSample);
	DDV_MinMaxUInt(pDX, m_sCorner.LRSample, 1, 5004);
	DDX_Text(pDX, IDC_ED_SULLINE, m_sCorner.ULLine);
	DDV_MinMaxUInt(pDX, m_sCorner.ULLine, 1, 2168);
	DDX_Text(pDX, IDC_ED_SULSAMPLE, m_sCorner.ULSample);
	DDV_MinMaxUInt(pDX, m_sCorner.ULSample, 1, 5004);
	//}}AFX_DATA_MAP
}

BEGIN_MESSAGE_MAP(CSubsetPALDlg, CDialog)
	//{{AFX_MSG_MAP(CSubsetPALDlg)
	ON_WM_SYSCOMMAND()
	ON_WM_PAINT()
	ON_WM_QUERYDRAGICON()
	ON_BN_CLICKED(IDC_LOADFILE, OnLoadfile)
	ON_BN_CLICKED(IDABOUT, OnAbout)
	//}}AFX_MSG_MAP
END_MESSAGE_MAP()

/////////////////////////////////////////////////////////////////////////////
// CSubsetPALDlg message handlers

BOOL CSubsetPALDlg::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
	
	m_nCorner = ((CSubsetPALApp*)AfxGetApp())->m_northCorner;
	m_sCorner = ((CSubsetPALApp*)AfxGetApp())->m_southCorner;

	UpdateData(FALSE);
	
	return TRUE;  // return TRUE  unless you set the focus to a control
}

void CSubsetPALDlg::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 CSubsetPALDlg::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 CSubsetPALDlg::OnQueryDragIcon()
{
	return (HCURSOR) m_hIcon;
}

void CSubsetPALDlg::OnLoadfile() 
{
	CFileDialog fDlg(TRUE, NULL, NULL, OFN_HIDEREADONLY | OFN_OVERWRITEPROMPT, 
		"Boundary Files (*.bnd)|*.bnd|All Files (*.*)|*.*||", NULL);
	if (fDlg.DoModal() == IDOK)
	{
		CStdioFile file;
		CFileException fe;
		if (file.Open(fDlg.GetPathName(), CFile::modeRead, &fe))
		{
			CString string;
			file.ReadString(string);
			file.ReadString(string);
			m_nCornerold.ULSample = m_nCorner.ULSample = atoi((string.Left(string.Find(","))).GetBuffer(0));
			m_nCornerold.ULLine = m_nCorner.ULLine = atoi((string.Right(string.Find(","))).GetBuffer(0));
			file.ReadString(string);
			file.ReadString(string);
			m_nCornerold.LRSample = m_nCorner.LRSample = atoi((string.Left(string.Find(","))).GetBuffer(0));
			m_nCornerold.LRLine = m_nCorner.LRLine = atoi((string.Right(string.Find(","))).GetBuffer(0));
			file.ReadString(string);
			file.ReadString(string);
			m_sCornerold.ULSample = m_sCorner.ULSample = atoi((string.Left(string.Find(","))).GetBuffer(0));
			m_sCornerold.ULLine = m_sCorner.ULLine = atoi((string.Right(string.Find(","))).GetBuffer(0));
			file.ReadString(string);
			file.ReadString(string);
			m_sCornerold.LRSample = m_sCorner.LRSample = atoi((string.Left(string.Find(","))).GetBuffer(0));
			m_sCornerold.LRLine = m_sCorner.LRLine = atoi((string.Right(string.Find(","))).GetBuffer(0));
			UpdateData(FALSE);
			file.Close();
		}
	}
}

void CSubsetPALDlg::OnAbout() 
{
	CAboutDlg dlg;
	dlg.DoModal();
	
}

void CSubsetPALDlg::OnOK() 
{
	((CSubsetPALApp*)AfxGetApp())->m_northCorner = m_nCorner;
	((CSubsetPALApp*)AfxGetApp())->m_southCorner = m_sCorner;
	CDialog::OnOK();	

	if (m_nCornerold != m_nCorner || m_sCornerold != m_sCorner)
	{
		if (MessageBox("是否将边界定义保存为文件?", "请选择", MB_YESNO) == IDYES)
		{
			CFileDialog fDlg(FALSE, NULL, NULL, OFN_HIDEREADONLY | OFN_OVERWRITEPROMPT, 
				"Boundary Files (*.bnd)|*.bnd|All Files (*.*)|*.*||", NULL);
			if (fDlg.DoModal() == IDOK)
			{
				CStdioFile file;
				CFileException fe;
				CString fileName = fDlg.GetPathName();
				if (fileName.Find(".") == -1)
					fileName += ".bnd";
				if (file.Open(fileName, CFile::modeCreate | CFile::modeWrite, &fe))
				{
					CString string;
					string = "% Northern Part Up-Left Corner: Sample, Line\n";
					file.WriteString(string);
					string.Format("%d, %d\n", m_nCorner.ULSample, m_nCorner.ULLine);
					file.WriteString(string);

					string = "% Northern Part Low-Right Corner: Sample, Line\n";
					file.WriteString(string);
					string.Format("%d, %d\n", m_nCorner.LRSample, m_nCorner.LRLine);
					file.WriteString(string);

					string = "% Sourthern Part Up-Left Corner: Sample, Line\n";
					file.WriteString(string);
					string.Format("%d, %d\n", m_sCorner.ULSample, m_sCorner.ULLine);
					file.WriteString(string);

					string = "% Southern Part Low-Right Corner: Sample, Line\n";
					file.WriteString(string);
					string.Format("%d, %d\n", m_sCorner.LRSample, m_sCorner.LRLine);
					file.WriteString(string);

					file.Close();
				}
			}
		}
	}
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -