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

📄 mymappdlg.cpp

📁 用C++中的MFC编程实现正轴等角割圆柱投影
💻 CPP
字号:
// mymappDlg.cpp : implementation file
//

#include "stdafx.h"
#include "mymapp.h"
#include "mymappDlg.h"
#include <math.h>
#include <string>
#include  <iostream>
#include  <vector>
#include  <list>
#include <iomanip>
#include <stdlib.h>
using namespace std;
#define pi 3.14159265358979
#define R 6371116
#define ae 6378245.0
#define be 6356863.0
int tagp=0;
int taga;



double x,y,m,p;

#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()

/////////////////////////////////////////////////////////////////////////////
// CMymappDlg dialog

CMymappDlg::CMymappDlg(CWnd* pParent /*=NULL*/)
: CDialog(CMymappDlg::IDD, pParent)
{
	//{{AFX_DATA_INIT(CMymappDlg)
	m_B = 0;
	m_BLarge = 25;
	m_BSmall = 0;
	m_dB = 5;
	m_dL = 5;
	m_L = 105;
	m_LLarge = 125;
	m_LSmall = 105;
	m_M = 1000000;
	m_radio = 0;
	m_Bk = 15;
	//}}AFX_DATA_INIT
	// Note that LoadIcon does not require a subsequent DestroyIcon in Win32
	m_hIcon = AfxGetApp()->LoadIcon(IDR_MAINFRAME);
}

void CMymappDlg::DoDataExchange(CDataExchange* pDX)
{
	CDialog::DoDataExchange(pDX);
	//{{AFX_DATA_MAP(CMymappDlg)
	DDX_Control(pDX, IDC_BUTTON_Open, m_OpenC);
	DDX_Control(pDX, IDC_BUTTON_Save, m_SaveC);
	DDX_Control(pDX, IDC_LIST, m_List);
	DDX_Control(pDX, IDC_BUTTON_AreaP, m_AreaPC);
	DDX_Control(pDX, IDC_BUTTON_PointP, m_PointPC);
	DDX_Control(pDX, IDC_EDIT_L, m_LC);
	DDX_Control(pDX, IDC_EDIT_B, m_BC);
	DDX_Control(pDX, IDC_EDIT_dL, m_dLC);
	DDX_Control(pDX, IDC_EDIT_dB, m_dBC);
	DDX_Control(pDX, IDC_EDIT_BSmall, m_BSmallC);
	DDX_Control(pDX, IDC_EDIT_BLarge, m_BLargeC);
	DDX_Control(pDX, IDC_EDIT_LLarge, m_LLargeC);
	DDX_Control(pDX, IDC_EDIT_LSmall, m_LSmallC);
	DDX_Text(pDX, IDC_EDIT_B, m_B);
	DDX_Text(pDX, IDC_EDIT_BLarge, m_BLarge);
	DDX_Text(pDX, IDC_EDIT_BSmall, m_BSmall);
	DDX_Text(pDX, IDC_EDIT_dB, m_dB);
	DDX_Text(pDX, IDC_EDIT_dL, m_dL);
	DDX_Text(pDX, IDC_EDIT_L, m_L);
	DDX_Text(pDX, IDC_EDIT_LLarge, m_LLarge);
	DDX_Text(pDX, IDC_EDIT_LSmall, m_LSmall);
	DDX_Text(pDX, IDC_EDIT_M, m_M);
	DDX_Radio(pDX, IDC_RADIO3, m_radio);
	DDX_Text(pDX, IDC_EDIT_Bk, m_Bk);
	//}}AFX_DATA_MAP
}

BEGIN_MESSAGE_MAP(CMymappDlg, CDialog)
//{{AFX_MSG_MAP(CMymappDlg)
ON_WM_SYSCOMMAND()
ON_WM_PAINT()
ON_WM_QUERYDRAGICON()
ON_BN_CLICKED(IDC_BUTTON_AreaP, OnBUTTONAreaP)
ON_BN_CLICKED(IDC_BUTTON_PointP, OnBUTTONPointP)
ON_BN_CLICKED(IDC_RADIO3, OnRadioPoint)
ON_BN_CLICKED(IDC_RADIO4, OnRadioArea)
ON_BN_CLICKED(IDC_BUTTON_Save, OnBUTTONSave)
ON_BN_CLICKED(IDC_BUTTON_Open, OnBUTTONOpen)
//}}AFX_MSG_MAP
END_MESSAGE_MAP()

/////////////////////////////////////////////////////////////////////////////
// CMymappDlg message handlers

BOOL CMymappDlg::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
	//单选按纽的控制,控制可写与不可写
	this->m_BLargeC.EnableWindow(false);
	this->m_BSmallC.EnableWindow(false);
	this->m_LLargeC.EnableWindow(false);
	this->m_LSmallC.EnableWindow(false);
	this->m_dBC.EnableWindow(false);
	this->m_dLC.EnableWindow(false);
	this->m_AreaPC.EnableWindow(false);
	this->m_SaveC.EnableWindow(false);
	this->m_OpenC.EnableWindow(false);
	m_BC.EnableWindow(true);
	m_LC.EnableWindow(true);
	this->m_marktag=false;

	//list control的初始化
	char* color[] = {"编号No","纬度B/角度","经度L/角度","横坐标x/cm","纵坐标y/cm","长度比m=n","面积比P"};
	CRect cd;
	m_List.GetClientRect(cd);
	this->m_List.GetDlgItem(IDC_LIST);
	DWORD dwStyle;
	dwStyle = m_List.GetStyle();
	dwStyle = LVS_EX_GRIDLINES |LVS_EX_FULLROWSELECT|LVS_SHOWSELALWAYS ;
	m_List.SetExtendedStyle(dwStyle);
	m_List.SetBkColor(RGB(0xec,0xf1,0xfd));
	m_List.SetTextBkColor(RGB(0xfe,0xFF,0xc6));
	for(int i = 0;i<7;i++){
		this->m_List.InsertColumn(i,color[i],LVCFMT_CENTER,cd.Width()/7);
	}
	
	return TRUE;  // return TRUE  unless you set the focus to a control
}

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

void CMymappDlg::OnBUTTONAreaP() 
{
	this->UpdateData();	
	taga=0;
	this->m_List.DeleteAllItems();
	mylist.clear();
	if(m_BSmall>=0&&m_BSmall<=90 && m_BLarge>=m_BSmall&&m_BLarge<=90 && m_LSmall>=0&&m_LSmall<=180 && m_LLarge>=m_LSmall&&m_LLarge<=180 && m_dB>0 && m_dL>0 && m_Bk>=0&&m_Bk<=90 &&m_M>0)
	{
		/**************************************
		计算
		e:第一偏心率
		i:纬度
		j:经度
		k=rk:标准纬线的纬圈半径
		r:投影点的纬圈半径
		********************************************/
		for(int i=this->m_BSmall;i<=this->m_BLarge;i=i+this->m_dB)
			for(int j=this->m_LSmall;j<=this->m_LLarge;j=j+this->m_dL)
			{
				double e=sqrt((ae*ae-be*be)/(ae*ae));
				double u=(tan(45*pi/180+(i*pi/180)/2))/pow(tan(45*pi/180+asin(e*sin(i*pi/180))/2),e);
				double k=ae*cos(m_Bk*pi/180)/sqrt(1-e*e*sin(m_Bk*pi/180)*sin(m_Bk*pi/180));
				double r=ae*cos(i*pi/180)/sqrt(1-e*e*sin(i*pi/180)*sin(i*pi/180));
				x=100*k*log(u)/m_M;
				y=100*k*(j*pi/180)/m_M;
				m=k/r;
				p=m*m;				
				//转化成字符串
				CString buf[7];
				buf[0].Format("%d",++taga);
				buf[1].Format("%d",i);
				buf[2].Format("%d",j);
				buf[3].Format("%lf",x);
				buf[4].Format("%lf",y);
				buf[5].Format("%lf",m);
				buf[6].Format("%lf",p);
				//保存到mylist的链表中
				mylist.push_back((double) i);
				mylist.push_back((double) j);
				mylist.push_back(x);
				mylist.push_back(y);
				mylist.push_back(m);
				mylist.push_back(p);
				//输出一行
				int ln;
				ln=this->m_List.InsertItem(taga,buf[0]);
				for(int col=0;col<7;col++)
					m_List.SetItemText(ln,col,buf[col]);
			}
	}
	else
		::MessageBox(NULL,"输入有误,请检查!","错误",MB_ICONHAND);
	//::MessageBox(NULL,"输入区域的格式不正确,请检查!","错误",MB_ICONHAND);
	this->m_marktag=true;
	
	// TODO: Add your control notification handler code here
	
}

void CMymappDlg::OnBUTTONPointP() 
{
	this->UpdateData();
	if(this->m_marktag)
		tagp=0;
	if(m_B>=0&&m_B<=90&&m_L>=0&&m_L<=180&&m_Bk>=0&&m_Bk<90&&m_M>0)
	{
		/**************************************
		计算
		e:第一偏心率
		i:纬度
		j:经度
		k=rk:标准纬线的纬圈半径
		r:投影点的纬圈半径
		********************************************/
		double e=sqrt((ae*ae-be*be)/(ae*ae));
		double u=(tan(45*pi/180+(m_B*pi/180)/2))/pow(tan(45*pi/180+asin(e*sin(m_B*pi/180))/2),e);
		double k=ae*cos(m_Bk*pi/180)/sqrt(1-e*e*sin(m_Bk*pi/180)*sin(m_Bk*pi/180));
		double r=ae*cos(m_B*pi/180)/sqrt(1-e*e*sin(m_B*pi/180)*sin(m_B*pi/180));
		x=100*k*log(u)/m_M;
		y=100*k*(m_L*pi/180)/m_M;
		m=k/r;
		p=m*m;
		//转化成字符串		
		CString buf[7];
		buf[0].Format("%d",++tagp);
		buf[1].Format("%d",m_B);
		buf[2].Format("%d",m_L);
		buf[3].Format("%lf",x);
		buf[4].Format("%lf",y);
		buf[5].Format("%lf",m);
		buf[6].Format("%lf",p);
		//输出一行
		int ln;
		ln=this->m_List.InsertItem(tagp,buf[0]);
		for(int col=0;col<7;col++)
			m_List.SetItemText(ln,col,buf[col]);
	}
	else
	{
		if(m_Bk<0||m_Bk>=90)
			::MessageBox(NULL,"您输入的中心纬度越界!","错误",MB_ICONHAND);
		else
		{
			if(m_B<0||m_B>90||m_L<0||m_L>180)
				::MessageBox(NULL,"您输入的经纬度越界!","错误",MB_ICONHAND);
			else
			{
				if(m_M<=0)
					::MessageBox(NULL,"您输入比例尺有误,请检查!","错误",MB_ICONHAND);
			}
		}
	}
	this->m_marktag=false;
	
	// TODO: Add your control notification handler code here
	
}


void CMymappDlg::OnRadioPoint() 
{
	// TODO: Add your control notification handler code here
	//单选按纽的控制,控制可写与不可写
	this->m_BLargeC.EnableWindow(false);
	this->m_BSmallC.EnableWindow(false);
	this->m_LLargeC.EnableWindow(false);
	this->m_LSmallC.EnableWindow(false);
	this->m_dBC.EnableWindow(false);
	this->m_dLC.EnableWindow(false);
	this->m_AreaPC.EnableWindow(false);
	this->m_SaveC.EnableWindow(false);
	this->m_OpenC.EnableWindow(false);
	this->m_PointPC.EnableWindow(true);
	m_BC.EnableWindow(true);
	m_LC.EnableWindow(true);
	this->m_List.DeleteAllItems();
}

void CMymappDlg::OnRadioArea() 
{
	// TODO: Add your control notification handler code here
	//单选按纽的控制,控制可写与不可写
	m_BC.EnableWindow(false);
	m_LC.EnableWindow(false);
	this->m_PointPC.EnableWindow(false);
	this->m_AreaPC.EnableWindow(true);
	this->m_BLargeC.EnableWindow(true);
	this->m_BSmallC.EnableWindow(true);
	this->m_LLargeC.EnableWindow(true);
	this->m_LSmallC.EnableWindow(true);
	this->m_dBC.EnableWindow(true);
	this->m_dLC.EnableWindow(true);	
	this->m_SaveC.EnableWindow(true);
	this->m_OpenC.EnableWindow(true);
	this->m_List.DeleteAllItems();
}

void CMymappDlg::OnBUTTONSave() 
{
	if(mylist.empty())
	{
		::MessageBox(NULL,"表格中无数据!","错误",MB_ICONHAND);
		return;
	}
	taga=0;
	CString strCurrentPath,strMsg;
	GetCurrentDirectory(200,strCurrentPath.GetBuffer(200));
	strCurrentPath.ReleaseBuffer();	
	CFileDialog   dlg(FALSE,   TEXT("TXT"),   NULL,   OFN_HIDEREADONLY   |   OFN_OVERWRITEPROMPT,    TEXT("文本文件(*.txt)|*.txt|所有文件(*.*)|*.*||"),   this);   
	dlg.m_ofn.lpstrInitialDir=strCurrentPath; //这里就设置了对话框的默认目录为strCurrentPath
	if ( dlg.DoModal()!=IDOK )
		return;
	//获取文件的绝对路径
	CString sFileName=dlg.GetPathName();
	m_filename=(char*)(LPCTSTR)sFileName;
	m_file.open(m_filename,std::ios::out);
	m_file << "编号NO" << std::setw(15)<< "纬度B/角度" << std::setw(15)<<"经度L/角度" 
		<<std::setw(15)<< "横坐标x/cm" <<std::setw(15)<< "纵坐标y/cm" <<std::setw(15)
		<< "长度比m=n" <<std::setw(15)<< "面积比p" <<std::setw(15)<< endl;
	std::list<double>::iterator lstitr = mylist.begin();
	std::list<double>::iterator lstend = mylist.end();
	//写入一行
	int listln;
	for(int listcol=0;lstitr != lstend;listcol++)
	{
		m_file <<std::setw(2)<< ++taga;
		for (listln=0;listln<6; lstitr++,listln++)
			m_file << std::setw(15) << *lstitr ;
		m_file <<endl;
	}
	// TODO: Add your control notification handler code here
	m_file.close();
}

void CMymappDlg::OnBUTTONOpen() 
{
	CString strCurrentPath,strMsg;
	GetCurrentDirectory(200,strCurrentPath.GetBuffer(200));
	strCurrentPath.ReleaseBuffer();
	CFileDialog   dlg(TRUE,   TEXT("TXT"),   NULL,   OFN_HIDEREADONLY   |   OFN_OVERWRITEPROMPT,    TEXT("文本文件(*.txt)|*.txt|所有文件(*.*)|*.*||"),   this);   
	dlg.m_ofn.lpstrInitialDir=strCurrentPath; //这里就设置了对话框的默认目录为strCurrentPath
	if ( dlg.DoModal()!=IDOK )
		return;
	//获取文件的绝对路径
	CString sFileName=dlg.GetPathName();
	string str;
	ifstream infile(sFileName,ios::binary);
	//去掉第一行
	char tm[1024];
	infile.getline(tm,1024);
	//读取数据,放入数组
	double number[65536] = {0};
	infile>>str;
	int i=0;
	while(1)
	{
		number[i++] = atof(str.c_str());
		infile>>str;
		if( str.empty() ) break;
	} 
	//清空list control
	this->m_List.DeleteAllItems();
	//格式转换,转换成字符串
	CString buf[7];
	for(int listln=0;listln<i;listln=listln+7)
	{
		buf[0].Format("%d",int(number[listln]));
		buf[1].Format("%d",int(number[listln+1]));
		buf[2].Format("%d",int(number[listln+2]));
		buf[3].Format("%lf",number[listln+3]);
		buf[4].Format("%lf",number[listln+4]);
		buf[5].Format("%lf",number[listln+5]);
		buf[6].Format("%lf",number[listln+6]);
		//输出一行
		int ln;
		ln=this->m_List.InsertItem(int(number[listln]),buf[0]);
		for(int col=0;col<7;col++)
			m_List.SetItemText(ln,col,buf[col]);
	}
		// TODO: Add your control notification handler code here
				
}

⌨️ 快捷键说明

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