📄 getwptdlg.cpp
字号:
// GetWptDlg.cpp : implementation file
//
#include "stdafx.h"
#include "GetWpt.h"
#include "GetWptDlg.h"
#include <math.h>
//#include <stdlib.h>
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
#define MESS_TITLE_ERR "错误"
#define MESS_TITLE_TELL "提示"
/////////////////////////////////////////////////////////////////////////////
// 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()
/////////////////////////////////////////////////////////////////////////////
// CGetWptDlg dialog
CGetWptDlg::CGetWptDlg(CWnd* pParent /*=NULL*/)
: CDialog(CGetWptDlg::IDD, pParent)
{
//{{AFX_DATA_INIT(CGetWptDlg)
m_Message = _T("");
//}}AFX_DATA_INIT
// Note that LoadIcon does not require a subsequent DestroyIcon in Win32
m_hIcon = AfxGetApp()->LoadIcon(IDR_MAINFRAME);
m_Default_FileName = _T("");
}
void CGetWptDlg::DoDataExchange(CDataExchange* pDX)
{
CDialog::DoDataExchange(pDX);
//{{AFX_DATA_MAP(CGetWptDlg)
DDX_Control(pDX, IDC_LONG_MIN_M_EDIT, m_Long_M_Min_Ctl);
DDX_Control(pDX, IDC_LONG_MAX_M_EDIT, m_Long_M_Max_Ctl);
DDX_Control(pDX, IDC_LAT_MIN_M_EDIT, m_Lat_M_Min_Ctl);
DDX_Control(pDX, IDC_LAT_MAX_M_EDIT, m_Lat_M_Max_Ctl);
DDX_Control(pDX, IDC_LIST_FILTER_DATA, m_Filter_Disp);
DDX_Control(pDX, IDC_LAT_MAX_EDIT, m_Lat_Max_Ctl);
DDX_Control(pDX, IDC_LAT_MIN_EDIT, m_Lat_Min_Ctl);
DDX_Control(pDX, IDC_LONG_MAX_EDIT, m_Long_Max_Ctl);
DDX_Control(pDX, IDC_LONG_MIN_EDIT, m_Long_Min_Ctl);
DDX_Text(pDX, IDC_MESSAGE, m_Message);
//}}AFX_DATA_MAP
}
BEGIN_MESSAGE_MAP(CGetWptDlg, CDialog)
//{{AFX_MSG_MAP(CGetWptDlg)
ON_WM_SYSCOMMAND()
ON_WM_PAINT()
ON_WM_QUERYDRAGICON()
ON_BN_CLICKED(ID_FILE_SAVE_AS, OnFileSaveAs)
ON_BN_CLICKED(ID_FILTER_DATA, OnFilterData)
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// CGetWptDlg message handlers
BOOL CGetWptDlg::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
return TRUE; // return TRUE unless you set the focus to a control
}
void CGetWptDlg::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 CGetWptDlg::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 CGetWptDlg::OnQueryDragIcon()
{
return (HCURSOR) m_hIcon;
}
void CGetWptDlg::OnFileSaveAs()
{
// TODO: Add your control notification handler code here
char szFilter[128], szType[128], *p;
CString strName;
sprintf(szFilter,"OZI文件(*.wpt)|*.wpt||");
sprintf(szType,".wpt||");
CFileDialog dlgSaveFile (FALSE,szType, NULL, OFN_HIDEREADONLY | OFN_OVERWRITEPROMPT, szFilter);
dlgSaveFile.m_ofn.lpstrInitialDir = m_OutDirectory;
if (IDOK != dlgSaveFile.DoModal ())
{
MessageBox("没有保存!",MESS_TITLE_ERR, MB_OK | MB_ICONERROR);
return;
}
strName = dlgSaveFile.GetPathName ();
if(strName==m_Default_FileName)
{
MessageBox("不能覆盖文件!",MESS_TITLE_ERR, MB_OK | MB_ICONERROR);
return;
}
CString strFileName = dlgSaveFile.GetFileName ();
m_OutDirectory = strName.Left (strName.GetLength () - strFileName.GetLength ());
char buf[512];
FILE *fp, *fp1;
fp = fopen(m_Default_FileName, "r");
if(fp==NULL)
{
MessageBox("错误,无法过滤!",MESS_TITLE_ERR, MB_OK | MB_ICONERROR);
return;
}
fp1 = fopen (strName, "w+");
while(!feof(fp))
{
p = fgets(buf, 128, fp);
if(p==NULL)
break;
fputs(buf, fp1);
}
fclose(fp);
fclose(fp1);
MessageBox ("备份成功!", MESS_TITLE_TELL, MB_OK | MB_ICONINFORMATION);
}
void CGetWptDlg::OnFilterData()
{
// TODO: Add your control notification handler code here
char WayPoint_Head[][80]=
{"OziExplorer Waypoint File Version 1.1\r\n",
"WGS 84\r\n",
"Altitude is in Feet\r\n",
"Reserved 2\r\n",
"garmin\r\n",
""};
struct WAYPOINT waydata;
char buf[512], *p, *p1;;
FILE *fp, *fp1;
double longi,lati;
long line=0;
int num = 1, ret, len, l;
CWnd* pMess = GetDlgItem(IDC_MESSAGE);
CWnd* pDisp = GetDlgItem(IDC_LIST_FILTER_DATA);
// 获取经度范围
m_Long_Min_Ctl.GetLine(0, buf, 32); // 取度
m_long_range[0] = atof(buf);
m_Long_M_Min_Ctl.GetLine(0, buf, 32); // 取分
m_long_range[0] += atof(buf)/60;
m_Long_Max_Ctl.GetLine(0, buf, 32);
m_long_range[1] = atof(buf);
m_Long_M_Max_Ctl.GetLine(0, buf, 32);
m_long_range[1] += atof(buf)/60;
if(m_long_range[0]>m_long_range[1])
{
double a;
a = m_long_range[0];
m_long_range[0] = m_long_range[1]; m_long_range[1] = a;
}
// 获取纬度范围
m_Lat_Min_Ctl.GetLine(0, buf, 32);
m_lat_range[0] = atof(buf);
m_Lat_M_Min_Ctl.GetLine(0, buf, 32);
m_lat_range[0] += atof(buf)/60;
m_Lat_Max_Ctl.GetLine(0, buf, 32);
m_lat_range[1] = atof(buf);
m_Lat_M_Max_Ctl.GetLine(0, buf, 32);
m_lat_range[1] += atof(buf)/60;
if(m_lat_range[0]>m_lat_range[1])
{
double a;
a = m_lat_range[0];
m_lat_range[0] = m_lat_range[1]; m_lat_range[1] = a;
}
sprintf(buf, "%s中国地名.Lib", m_FileDirectory);
fp = fopen(buf,"r");
if(fp==NULL)
{
MessageBox("没有发现“中国地名.Lib”,无法过滤!",MESS_TITLE_ERR, MB_OK | MB_ICONERROR);
return;
}
sprintf(buf, "%sout.tmp", m_FileDirectory);
m_Default_FileName = buf;
fp1 = fopen(buf,"wb+");
if(fp1==NULL)
{
MessageBox("无法保存临时结果!",MESS_TITLE_ERR, MB_OK | MB_ICONERROR);
//return;
}
// 变量初始化
waydata.latitude = 0;
waydata.longitude = 0;
waydata.time = 0;
waydata.waypoint_symbol = 0;
waydata.not = 1;
waydata.display_format = 3;
waydata.fore_color = 0;
waydata.back_color = 65535;
waydata.description[0]= 0;
waydata.pointer_direction = 0;
waydata.Garmin_display = 0;
waydata.proximity_distance = 0;
waydata.altitude = -777; //feet
waydata.size = 9;
waydata.bold = 0;
waydata.symbol_size = 17;
for(l=0;WayPoint_Head[l][0]>0;l++)
{
fwrite((char*)&WayPoint_Head[l][0],strlen(WayPoint_Head[l]),1,fp1);
}
while(!feof(fp))
{
line++;
if((line & 0x3ff)==0L)
{
sprintf(buf, "过滤:%d 符合:%d ", line, num);
pMess->SetWindowText(buf);
pMess->UpdateWindow();
}
p = fgets(buf, 64, fp);
if(p==NULL)
break;
p1 = strchr(p, 0x9);
if(p1==NULL)
continue;
*p1 = 0;
longi = atof(p);
p = p1+1;
p1 = strchr(p, 0x9);
if(p1==NULL)
continue;
*p1 = 0;
lati = atof(p);
p = p1+1;
if(m_long_range[0]<=longi && longi<=m_long_range[1])
{
if(m_lat_range[0]<=lati && lati<=m_lat_range[1])
{ // 坐标符合
waydata.longitude = longi;
waydata.latitude = lati;
;
if((p1 = strchr(p, 0x0d))!=NULL)
{
*p1 = 0;
}
else if((p1 = strchr(p, 0x0a))!=NULL)
{
*p1 = 0;
}
strcpy(waydata.name, p);
sprintf(buf, "%10.5f %10.5f %s",waydata.latitude,waydata.longitude,waydata.name);
m_Filter_Disp.AddString(buf);
pDisp->UpdateWindow();
// 写该点
sprintf(buf,"%d,%s,%10.5f,%10.5f,%ld,%ld,%ld,%ld,%ld,%ld,%s,%ld,%ld,%ld,%ld,%ld,%ld,%ld\r\n",num,waydata.name,
waydata.latitude,waydata.longitude,waydata.time,
waydata.waypoint_symbol,waydata.not,waydata.display_format,waydata.fore_color,waydata.back_color,
waydata.description,waydata.pointer_direction,waydata.Garmin_display,waydata.proximity_distance,
waydata.altitude,waydata.size,waydata.bold,waydata.symbol_size);
num++;
len = strlen(buf);
ret = fwrite(buf,len,1,fp1);
}
}
}
fclose(fp);
fclose(fp1);
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -