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

📄 newfieldsdlg.cpp

📁 C++ MapX开发源码
💻 CPP
字号:
// newFieldsDlg.cpp : implementation file
//

#include "stdafx.h"
#include "newFields.h"
#include "newFieldsDlg.h"
#include "MAPX.H"

#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif

/////////////////////////////////////////////////////////////////////////////
// CNewFieldsDlg dialog

CNewFieldsDlg::CNewFieldsDlg(CWnd* pParent /*=NULL*/)
	: CDialog(CNewFieldsDlg::IDD, pParent)
{
	//{{AFX_DATA_INIT(CNewFieldsDlg)
		// NOTE: the ClassWizard will add member initialization here
	//}}AFX_DATA_INIT
	// Note that LoadIcon does not require a subsequent DestroyIcon in Win32
	m_hIcon = AfxGetApp()->LoadIcon(IDR_MAINFRAME);
}

void CNewFieldsDlg::DoDataExchange(CDataExchange* pDX)
{
	CDialog::DoDataExchange(pDX);
	//{{AFX_DATA_MAP(CNewFieldsDlg)
		// NOTE: the ClassWizard will add DDX and DDV calls here
	//}}AFX_DATA_MAP
	DDX_Control(pDX,IDC_MAP1,m_map);
}

BEGIN_MESSAGE_MAP(CNewFieldsDlg, CDialog)
	//{{AFX_MSG_MAP(CNewFieldsDlg)
	ON_WM_PAINT()
	ON_WM_QUERYDRAGICON()
	ON_BN_CLICKED(IDC_ZoomIn, OnZoomIn)
	ON_BN_CLICKED(IDC_ADDSPECLAYER, OnAddspeclayer)
	//}}AFX_MSG_MAP
END_MESSAGE_MAP()

/////////////////////////////////////////////////////////////////////////////
// CNewFieldsDlg message handlers

BOOL CNewFieldsDlg::OnInitDialog()
{
	CDialog::OnInitDialog();

	// 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
}

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

void CNewFieldsDlg::OnOK() 
{
	// TODO: Add extra validation here
	MessageBox("Help, Something went wrong.", "Error", MB_ICONERROR | MB_OK);

	CDialog::OnOK();
}

BEGIN_EVENTSINK_MAP(CNewFieldsDlg, CDialog)
    //{{AFX_EVENTSINK_MAP(CNewFieldsDlg)
	ON_EVENT(CNewFieldsDlg, IDC_MAP1, -600 /* Click */, OnClickMap1, VTS_NONE)
	ON_EVENT(CNewFieldsDlg, IDC_MAP1, 3 /* ToolUsed */, OnToolUsedMap1, VTS_I2 VTS_R8 VTS_R8 VTS_R8 VTS_R8 VTS_R8 VTS_BOOL VTS_BOOL VTS_PBOOL)
	//}}AFX_EVENTSINK_MAP
END_EVENTSINK_MAP()

void CNewFieldsDlg::OnClickMap1() 
{
	// TODO: Add your control notification handler code here
	
}

void CNewFieldsDlg::OnToolUsedMap1(short ToolNum, double X1, double Y1, double X2, double Y2, double Distance, BOOL Shift, BOOL Ctrl, BOOL FAR* EnableDefault) 
{
	// TODO: Add your control notification handler code here
}

void CNewFieldsDlg::OnZoomIn() 
{
	// TODO: Add your control notification handler code here
	m_map.SetCurrentTool(miZoomInTool);
	
}

void CNewFieldsDlg::OnAddspeclayer() 
{
	// TODO: Add your control notification handler code here
	/*MessageBox("my test");
	
	CMapXLayers layers = m_ctrlMapX.GetLayers();
	CMapXLayer  mylayer ; 
	CMapXLayerInfo  layerInfo;
	layerInfo.CreateDispatch(layerInfo.GetClsid());
	layerInfo.SetType(miLayerInfoTypeNewTable); 
	
    CString ConnectStr = "SRVR=map.ecfounder.com;UID=sys;PWD=sys";
	layerInfo.AddParameter("connectstring",COleVariant(ConnectStr));
	layerInfo.AddParameter("name",COleVariant("ocilayer"));
	layerInfo.AddParameter("toolkit",COleVariant("ORAINET"));
	layerInfo.AddParameter("query",COleVariant("Select * from states1"));
	*/

    try  
     {
		//CMapXLayer lyr;
		//lyr=m_ctrlMapX.GetLayers().CreateLayer("tempAnimate","e:\\temp\\lytest.TAB",1);

		
          CMapXFields Flds;
		  
          if(!Flds.CreateDispatch(Flds.GetClsid ()))
               //return FALSE;
			   MessageBox("Create Field error!");

         VARIANT FieldName;                     //字段名称 
         FieldName.vt = VT_BSTR;

//注:字段名为英文或者数字可以正确执行
//	  如果字段名为中文则会出现“参数不正确”的错误,是MapX5.02的一个bug;add by James 2003/9/15

         CString csTmp;         //中文字段名称
		 //csTmp.Format("%s","你好");
		 //csTmp = _T("中文");
		 csTmp = _T("testField");
		 //csTmp=(LPCTSTR)csTmp;
		  LPCTSTR lcsTmp = (LPCTSTR)csTmp;
         //FieldName.bstrVal=csTmp.AllocSysString();
		 // FieldName.bstrVal = csTmp.AllocSysString();
		  //FieldName.pbstrVal == csTmp.Format("%s","你好");

          VARIANT FieldLength;                  //字段长度
          FieldLength.vt=VT_I2;
          FieldLength.iVal =30;
		  long iwidth = 30;
          Flds.AddStringField(lcsTmp,iwidth,false); 
		  //Flds.AddIntegerField(lcsTmp,false); 

         //csTmp=_T("e:\\temp\\lytest.TAB");
		 CString csLyrName = _T("lytest");

         //Create a variant that points to the fields collection just created
           VARIANT vFlds;
           vFlds.vt = VT_DISPATCH;
           vFlds.pdispVal = Flds.m_lpDispatch;

           //Create a new LayerInfo Object
           CMapXLayerInfo Linfo;
           Linfo.CreateDispatch(Linfo.GetClsid());

           //Set the Layer Info type to type: New Table
           Linfo.SetType(miLayerInfoTypeNewTable);
  
           //Add the parameters for the new table
           Linfo.AddParameter("FileSpec", COleVariant("e:\\temp\\lytest.TAB")); //Tab file
           Linfo.AddParameter("Name", COleVariant("lytest")); //Layer name
 
           Linfo.AddParameter("Fields", vFlds); //Fields
           Linfo.AddParameter("OverwriteFile", COleVariant("1")); 
           //Add the new layer to the map
           CMapXLayer lyr=m_map.GetLayers().Add(Linfo.m_lpDispatch); //如果是中文出错
		   MessageBox("Create Layer correctly,e:\\temp\\lytest.tab!");
		   

	 } catch(COleDispatchException* e) {
	  e->ReportError();
	  e->Delete();
	 } catch(COleException* e) {
	  e->ReportError();
	  e->Delete();
	 }
	
}

⌨️ 快捷键说明

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