SHP2VCTDlg.cpp
上传用户:bjslfz
上传日期:2022-07-25
资源大小:4430k
文件大小:8k
- // SHP2VCTDlg.cpp : implementation file
- //
- #include "stdafx.h"
- #include "SHP2VCT.h"
- #include "SHP2VCTDlg.h"
- #include <stdio.h>
- #include "Transfer.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()
- /////////////////////////////////////////////////////////////////////////////
- // CSHP2VCTDlg dialog
- CSHP2VCTDlg::CSHP2VCTDlg(CWnd* pParent /*=NULL*/)
- : CDialog(CSHP2VCTDlg::IDD, pParent)
- {
- //{{AFX_DATA_INIT(CSHP2VCTDlg)
- m_OutputData = _T("");
- m_InputData = _T("");
- //}}AFX_DATA_INIT
- // Note that LoadIcon does not require a subsequent DestroyIcon in Win32
- m_hIcon = AfxGetApp()->LoadIcon(IDR_MAINFRAME);
- }
- void CSHP2VCTDlg::DoDataExchange(CDataExchange* pDX)
- {
- CDialog::DoDataExchange(pDX);
- //{{AFX_DATA_MAP(CSHP2VCTDlg)
- DDX_Control(pDX, IDC_COMBO_SOURCE, m_ComboSource);
- DDX_Control(pDX, IDC_COMBO_TARGET, m_ComboTarget);
- DDX_Text(pDX, IDC_EDIT_TARGET, m_OutputData);
- DDX_Text(pDX, IDC_EDIT_SOURCE, m_InputData);
- //}}AFX_DATA_MAP
- }
- BEGIN_MESSAGE_MAP(CSHP2VCTDlg, CDialog)
- //{{AFX_MSG_MAP(CSHP2VCTDlg)
- ON_WM_SYSCOMMAND()
- ON_WM_PAINT()
- ON_WM_QUERYDRAGICON()
- ON_BN_CLICKED(IDC_BUTTON_CANCEL, OnButtonCancel)
- ON_BN_CLICKED(IDC_BUTTON_INPUT, OnButtonInput)
- ON_BN_CLICKED(IDC_BUTTON_OUTPUT, OnButtonOutput)
- ON_BN_CLICKED(IDC_BUTTON_THRANSFER, OnButtonThransfer)
- ON_BN_CLICKED(IDC_ABOUT, OnAbout)
- //}}AFX_MSG_MAP
- END_MESSAGE_MAP()
- /////////////////////////////////////////////////////////////////////////////
- // CSHP2VCTDlg message handlers
- BOOL CSHP2VCTDlg::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);
- //HICON hlcon = AfxGetApp()->LoadIcon(IDB_BITMAP_OPEN); //加载按钮图标
- //GetDlgItem(IDC_BUTTON_THRANSFER)->SetIcon(hlcon,TRUE);
- 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
-
- // TODO: Add extra initialization here
- //初始化数据源组合框中的数据
- m_Source=m_ComboSource.AddString("所有文件(*.*)");
- m_ComboSource.AddString("地球数据标准格式 (*.vct)");
- // m_ComboSource.AddString("ESRI Shape 格式(*.shp)");
- m_ComboSource.SelectString(0,"ESRI Shape 格式(*.shp)");
- m_ComboSource.SetCurSel(m_Source);
- //初始化目标数据组合框中的数据
- m_Target=m_ComboTarget.AddString("所有文件(*.*)");
- m_ComboTarget.AddString("MapInfo 格式 (*.mif)");
- //m_ComboTarget.AddString("ESRI Shape 格式(*.shp)");
- m_ComboTarget.SelectString(0,"地球数据标准格式 (*.vct)");
- m_ComboTarget.SetCurSel(m_Target);
-
- return TRUE; // return TRUE unless you set the focus to a control
- }
- void CSHP2VCTDlg::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 CSHP2VCTDlg::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 CSHP2VCTDlg::OnQueryDragIcon()
- {
- return (HCURSOR) m_hIcon;
- }
- void CSHP2VCTDlg::OnButtonCancel()
- {
- // TODO: Add your control notification handler code here
- OnCancel();
- }
- /************************************************************************/
- /* modify by xiejing 2008-5-6-5 */
- /************************************************************************/
- void CSHP2VCTDlg::OnButtonInput()
- {
- // TODO: Add your control notification handler code here
- CString filter; //定义文件过滤器字符串
- m_Source=m_ComboSource.GetCurSel(); //获取当前选中组合框的索引值
- m_ComboSource.GetLBText(m_Source,filter); //获取指定索引值的字符串,放入filter中
- CString link; //定义辅助字符串变量link
- link=filter.Right(6); //取出filter中后六位字符赋给link,即为“*.vct)”
- link=link.Left(5); //取出link中的前五位字符,即为“*.vct”
- filter+='|'; //在filter后面添加字符'|'
- link+="||"; //在link后面添加字符串“||”
- filter+=link; //将filter与link链接为一个字符串,这样字符串filter就是一个文件过滤器”地球数据标准格式 (*.vct)|*.vct||“的格式
- CFileDialog opendlg(TRUE,NULL,NULL,OFN_HIDEREADONLY,filter); //定义打开对话框
- if(opendlg.DoModal()==IDOK)
- {
- CString str;
- str=opendlg.GetPathName(); //获取打开对话框当前定位文件的路径并赋给str
- m_InputData=str; //将路径显示在文本框中
- csSourseFileName = m_InputData; /*将源文件名保存在变量csSourseFileName中*/
- UpdateData(FALSE); //更新视图
- }
-
- }
- void CSHP2VCTDlg::OnButtonOutput()
- {
- // TODO: Add your control notification handler code here
- CString filter; //定义文件过滤器字符串
- m_Target=m_ComboTarget.GetCurSel(); //获取当前选中组合框的索引值
- m_ComboTarget.GetLBText(m_Target,filter); //获取指定索引值的字符串,放入filter中
-
- CString link,suffix; //同上
- suffix=filter.Right(5);
- suffix=suffix.Left(4);
- link=filter.Right(6);
- link=link.Left(5);
- filter+='|';
- link+="||";
- filter+=link;
-
- CFileDialog savedlg(FALSE,NULL,NULL,OFN_FILEMUSTEXIST| OFN_HIDEREADONLY,filter); //定义另存为对话框
- if(savedlg.DoModal()==IDOK)
- {
- CString str;
- str=savedlg.GetPathName(); //获取另存为对话框当前定位文件的路径并赋给str
- m_OutputData=str+suffix; //将路径显示在文本框中
- UpdateData(FALSE);
- }
- }
- void CSHP2VCTDlg::OnButtonThransfer()
- {
- // TODO: Add your control notification handler code here
- if(m_InputData =="")
- {
- MessageBoxA("请选择输入文件!");
- return ;
- }
- if(m_OutputData =="")
- {
- MessageBoxA("请选择输出文件名!");
- return;
- }
- new CTransfer(m_InputData,m_OutputData);
- m_InputData = "";
- m_OutputData = "";
- UpdateData(FALSE);
- // OnOK();
- }
- void CSHP2VCTDlg::OnAbout()
- {
- // TODO: Add your control notification handler code here
- CAboutDlg dlg;
- dlg.DoModal();
- }