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

📄 convertpyforfielddlg.cpp

📁 Gis行业中常有数据需要由汉字转拼音的需求,本程序就是针对TAB数据进行字段中的汉字转换.mapinfo数据的处理是基于MAPX5.0,拼音提取是利用IMM直取微软拼音3.0的字库,有词组处理多音字处
💻 CPP
字号:
// ConvertPYForFieldDlg.cpp : implementation file
//

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

/////////////////////////////////////////////////////////////////////////////
// CConvertPYForFieldDlg dialog

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

void CConvertPYForFieldDlg::DoDataExchange(CDataExchange* pDX)
{
	CDialog::DoDataExchange(pDX);
	//{{AFX_DATA_MAP(CConvertPYForFieldDlg)
	DDX_Control(pDX, IDC_LIST_TO_FIELDNAME, m_CtlListToFieldName);
	DDX_Control(pDX, IDC_LIST_FIELDNAME, m_CtlListFieldName);
	DDX_Text(pDX, IDC_EDIT_PATH, m_strFullPath);
	//}}AFX_DATA_MAP
}

BEGIN_MESSAGE_MAP(CConvertPYForFieldDlg, CDialog)
	//{{AFX_MSG_MAP(CConvertPYForFieldDlg)
	ON_WM_SYSCOMMAND()
	ON_WM_PAINT()
	ON_WM_QUERYDRAGICON()
	ON_BN_CLICKED(IDC_BT_OPENTAB, OnBtOpentab)
	ON_BN_CLICKED(IDC_BT_CONVERT, OnBtConvert)
	ON_WM_CREATE()
	//}}AFX_MSG_MAP
END_MESSAGE_MAP()

/////////////////////////////////////////////////////////////////////////////
// CConvertPYForFieldDlg message handlers

BOOL CConvertPYForFieldDlg::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


	//初始LISTBOX
	InitCltList();	
	return TRUE;  // return TRUE  unless you set the focus to a control
}

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

void CConvertPYForFieldDlg::OnBtOpentab() 
{
    CFileDialog dlgFile(TRUE, _T("*.tab"), NULL, 0, _T("MapInfo Map Files (*.tab)|*.tab|All Files (*.*)|*.*||"), this);
	dlgFile.m_ofn.lpstrTitle = _T("打开 MapInfo Tab 文件");
	if (dlgFile.DoModal() == IDCANCEL)
		return;
	

	POSITION pos = dlgFile.GetStartPosition();
	//CString strFullPath;
	CString strFileName;
	while (pos) 
	{
		m_strFullPath	= dlgFile.GetNextPathName(pos);
		strFileName		= dlgFile.GetFileName();
	}	

	m_Map.GetLayers().Add(m_strFullPath,1);
	m_MapCls.SetMapXPointer(&m_Map);
	m_MapCls.SetDataSet(&m_Map.GetLayers().Item(1));
	SetCltListValue();

	UpdateData(false);
	//const TCHAR* p = strFileName;
}

void CConvertPYForFieldDlg::InitCltList()
{
	DWORD dwStyle;
	dwStyle = m_CtlListFieldName.GetExtendedStyle();
	dwStyle |= LVS_EX_GRIDLINES | LVS_EX_FULLROWSELECT;

	//样式设置
	m_CtlListFieldName.SetExtendedStyle( dwStyle );
	m_CtlListToFieldName.SetExtendedStyle( dwStyle );

	//listctrl column 设置
	m_CtlListFieldName.InsertColumn( 0, _T("请选择[汉字]字段"), LVCFMT_CENTER, 150);
	m_CtlListToFieldName.InsertColumn( 0, _T("请选择[拼音]字段"), LVCFMT_CENTER, 150);

}

void CConvertPYForFieldDlg::SetCltListValue()
{
//获取字段名	
	//Add in the dataset for the Us_custg layer and call it "Us_custg Layer"
	CMapXDataset* pDataset; 
	pDataset		= m_MapCls.GetDataSetPointer();
	CMapXFields fds = pDataset->GetFields();
	int nFieldCount = fds.GetCount();
	CString strFieldName ;

	for( int n = 1;n < nFieldCount+1;n ++)
	{
		strFieldName	= fds.Item(n).GetName();
		m_CtlListFieldName.InsertItem(n,strFieldName);
		m_CtlListToFieldName.InsertItem(n,strFieldName);
	}


	//m_CtlListFieldName.InsertItem(0,"星期");

}

void CConvertPYForFieldDlg::OnBtConvert() 
{
	if ( !CheckRullErr() )
		return;
	//
	int nSel1			= m_CtlListFieldName.GetSelectionMark();
	int nSel2			= m_CtlListToFieldName.GetSelectionMark();
	CString strField1	= m_CtlListFieldName.GetItemText(nSel1,0);
	CString strField2	= m_CtlListToFieldName.GetItemText(nSel2,0);

	
}

int CConvertPYForFieldDlg::OnCreate(LPCREATESTRUCT lpCreateStruct) 
{
	if (CDialog::OnCreate(lpCreateStruct) == -1)
		return -1;
	
	//初始MAPX
	//WS_VISIBLE,WS_CHILD 
	if( m_Map.Create(NULL, WS_CHILD , CRect(0,0,300,300), this, IDC_MAP) == false)
		return -1;
	m_Map.GetLayers().RemoveAll();
	return 0;
}

BOOL CConvertPYForFieldDlg::CheckRullErr()
{
	if ( m_Map.GetLayers().GetCount() < 1 )
	{
		AfxMessageBox(_T("请加载图层后再做转换!"));
		return false;
	}
	if ( m_CtlListFieldName.GetSelectionMark() < 0 && 
		 m_CtlListToFieldName.GetSelectionMark() < 0 )
	{
		AfxMessageBox(_T("请加载图层后再做转换!"));
		return false;
	}
	return true;
}

⌨️ 快捷键说明

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