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

📄 controlattdlg.cpp

📁 实现mapgis下各种工作区(点,线,面,网)下的 属性及其属性记录操作
💻 CPP
📖 第 1 页 / 共 2 页
字号:
// ControlAttDlg.cpp : implementation file
//

#include "stdafx.h"
#include "ControlAtt.h"
#include "ControlAttDlg.h"
#include "AttSetting.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)
	//}}AFX_MSG_MAP
END_MESSAGE_MAP()

/////////////////////////////////////////////////////////////////////////////
// CControlAttDlg dialog

CControlAttDlg::CControlAttDlg(CWnd* pParent /*=NULL*/)
	: CDialog(CControlAttDlg::IDD, pParent)
{
	//{{AFX_DATA_INIT(CControlAttDlg)
		// 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 CControlAttDlg::DoDataExchange(CDataExchange* pDX)
{
	CDialog::DoDataExchange(pDX);
	//{{AFX_DATA_MAP(CControlAttDlg)
	DDX_Control(pDX, IDC_LIST1, m_AttStruct);
	//}}AFX_DATA_MAP
}

BEGIN_MESSAGE_MAP(CControlAttDlg, CDialog)
	//{{AFX_MSG_MAP(CControlAttDlg)
	ON_WM_SYSCOMMAND()
	ON_WM_PAINT()
	ON_WM_QUERYDRAGICON()
	ON_NOTIFY(NM_RCLICK, IDC_LIST1, OnRclickList1)
	ON_COMMAND(IDC_Menu_INSERT, OnMenuINSERT)
	ON_COMMAND(IDC_Menu_DELETE, OnMenuDELETE)
	ON_COMMAND(IDC_Menu_QUERY, OnMenuQUERY)
	ON_COMMAND(IDC_Menu_OpenLINats, OnMenuOpenLINats)
	ON_COMMAND(IDC_Menu_OpenLINatt, OnMenuOpenLINatt)
	ON_COMMAND(IDC_Menu_OpenPointats, OnMenuOpenPointats)
	ON_COMMAND(IDC_Menu_OpenPointatt, OnMenuOpenPointatt)
	ON_COMMAND(IDC_Menu_OpenREGats, OnMenuOpenREGats)
	ON_COMMAND(IDC_Menu_OpenREGatt, OnMenuOpenREGatt)
	ON_COMMAND(IDC_Menu_OpenTableatt, OnMenuOpenTableatt)
	ON_COMMAND(IDC_Menu_OpenTableats, OnMenuOpenTableats)
	ON_MESSAGE(WM_VALIDATE, OnEndLabelEditVariableCriteria)
	ON_MESSAGE(WM_SET_ITEMS, PopulateComboList)
	//}}AFX_MSG_MAP
END_MESSAGE_MAP()

/////////////////////////////////////////////////////////////////////////////
// CControlAttDlg message handlers

BOOL CControlAttDlg::OnInitDialog()
{
	CDialog::OnInitDialog(); 
	isAttstr=FALSE;
	m_AH=_InitWorkArea(NULL);

	m_AttStruct.InsertColumn(0,_T("字段序号"),LVCFMT_LEFT,60);
    m_AttStruct.InsertColumn(1,_T("字段名"),LVCFMT_LEFT,60);
	m_AttStruct.InsertColumn(2,_T("字段类型"),LVCFMT_LEFT,60);
	m_AttStruct.InsertColumn(3,_T("编辑标志"),LVCFMT_LEFT,60);
	m_AttStruct.InsertColumn(4,_T("字节长度"),LVCFMT_LEFT,60);
	m_AttStruct.InsertColumn(5,_T("字段偏移"),LVCFMT_LEFT,60);
	m_AttStruct.InsertColumn(6,_T("字符长度"),LVCFMT_LEFT,60);
	m_AttStruct.InsertColumn(7,_T("小数位数"),LVCFMT_LEFT,60);
	m_AttStruct.InsertColumn(8,_T("打印标注"),LVCFMT_LEFT,60);


CString filepath;//文件路径
CString filetype;//文件类型
CString AttOrAttstru;//要编辑的是属性还是属性结构


CStringArray decodestr;//用于存放分隔字符串



filepath=GetCommandLine();
if (filepath.Right(3)!="att")//没有参数的话
{
	filepath+=" e:\\sdb,45kjbdf32.wb att";//给个错误路径(容错)
}
  char   *temp;   
  temp=strtok(filepath.GetBuffer(filepath.GetLength())," ");   
  if(temp!=NULL)  decodestr.Add(temp);
  temp=strtok(NULL," ");   
  if(temp!=NULL)   decodestr.Add(temp);
  temp=strtok(NULL," ");   
  if(temp!=NULL)  decodestr.Add(temp);

filetype=decodestr[1].Right(2);  //取得文件类型


if (filetype=="wb"||filetype=="WB")
{
init(decodestr[1],TBL,decodestr[2]);//初始化的一此其它工作,如:打开工做区,加载文件..
TYPE=TBL;
}else if (filetype=="wt"||filetype=="WT")
{
init(decodestr[1],PNT,decodestr[2]);//初始化的一此其它工作,如:打开工做区,加载文件..
TYPE=PNT;
}else if (filetype=="wl"||filetype=="WL")
{
init(decodestr[1],LIN,decodestr[2]);//初始化的一此其它工作,如:打开工做区,加载文件..
TYPE=LIN;
}
else if (filetype=="wp"||filetype=="WP")
{
init(decodestr[1],REG,decodestr[2]);//初始化的一此其它工作,如:打开工做区,加载文件..
TYPE=REG;
}

	if(decodestr[2]=="ats")
	{
   	m_AttStruct.SetComboColumns(2,TRUE);
	isAttstr=TRUE;
	}

	CString strValidChars;//	
	if (isAttstr)
	{
	m_AttStruct.SetReadOnlyColumns(0);//read only
	m_AttStruct.SetReadOnlyColumns(3);//read only
	m_AttStruct.SetReadOnlyColumns(4);//read only
	m_AttStruct.SetReadOnlyColumns(5);//read only
	m_AttStruct.SetReadOnlyColumns(8);//read only
	}
	strValidChars = "";
	m_AttStruct.SetColumnValidEditCtrlCharacters(strValidChars,1);//none control edit 
	if (isAttstr)
	{
	strValidChars = "0123456789.";
	m_AttStruct.SetColumnValidEditCtrlCharacters(strValidChars,6);//digital only edit
	}

	m_AttStruct.EnableVScroll(); 			
	m_AttStruct.SetExtendedStyle(LVS_EX_FULLROWSELECT);
    m_AttStruct.SetExtendedStyle(m_AttStruct.GetExtendedStyle()|LVS_EX_GRIDLINES);

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

LRESULT CControlAttDlg::OnEndLabelEditVariableCriteria(WPARAM wParam, LPARAM lParam) 
{
	LV_DISPINFO* pDispInfo = (LV_DISPINFO*)lParam;
	// 编辑完成之后代码
	int i=pDispInfo->item.iItem;//取得当前编辑行
	int j=pDispInfo->item.iSubItem;//取得当前编辑的列
   if (isAttstr)//进行属性结构编辑
   {
	   	CATT_STRU *newstru;
				newstru=new CATT_STRU(stru);
				AttSetting myset;
	switch(j) 
	{
	case 0:
		break;
			case 1:
				lstrcpy(newstru->fldEntry[i].fieldname,m_AttStruct.GetItemText(i,1));
				_SetAttStru(m_Ai,TYPE,newstru);
				delete newstru;
		
		break;
					case 2:
					newstru->fldEntry[i].fieldtype=myset.GetAttstrufldType(m_AttStruct.GetItemText(i,2));
                       _SetAttStru(m_Ai,TYPE,newstru);
			        	delete newstru;
		break;
							case 3:
//newstru->fldEntry[i].edit_enable=myset.GetAttstrufldEdit_enable(m_AttStruct.GetItemText(i,3));
//_SetAttStru(m_Ai,TYPE,newstru);
//				delete newstru;
		break;
									case 4:
//									newstru->fldEntry[i].fieldlength=atoi(LPCSTR(m_AttStruct.GetItemText(i,4)));
//                       _SetAttStru(m_Ai,TYPE,newstru);
//			        	delete newstru;
						
		break;
											case 5:
//											newstru->fldEntry[i].fieldoffset=atol(LPCSTR(m_AttStruct.GetItemText(i,5)));
//                       _SetAttStru(m_Ai,TYPE,newstru);
//			        	delete newstru;
		break;
													case 6:
													newstru->fldEntry[i].msk_leng=atoi(LPCSTR(m_AttStruct.GetItemText(i,6)));
                       _SetAttStru(m_Ai,TYPE,newstru);
			        	delete newstru;
		break;
															case 7:
																//myhead.point_leng=
		break;
																	case 8:
																	//	myhead.pt_flg=
		break;
	default:
		break;
	}
	   _SaveAll(m_Ai);
   }
   else//进行属性记录编辑
   {
	char *ptAtt=NULL;
    char fldBuf[128];
   strcpy(fldBuf, m_AttStruct.GetItemText(pDispInfo->item.iItem,pDispInfo->item.iSubItem));
   _GetAtt(m_Ai,TYPE,pDispInfo->item.iItem+1,&stru,&ptAtt);//取要编辑的记录
   _SetFldOnNumbFromStr(ptAtt,stru,pDispInfo->item.iSubItem-1,fldBuf); //将字段值写入记录缓冲区
   _WriteAtt(m_Ai,TYPE,pDispInfo->item.iItem+1,stru,ptAtt);//将记录值写入工作区
   _SaveAll(m_AH);
   }
 return 1;
}
LRESULT CControlAttDlg::PopulateComboList(WPARAM wParam, LPARAM lParam)//创建下拉列表框
{
	// Get the Combobox window pointer
	CComboBox* pInPlaceCombo = static_cast<CComboBox*> (GetFocus());

	// Get the inplace combbox top left
	CRect obWindowRect;

	pInPlaceCombo->GetWindowRect(&obWindowRect);
	
	CPoint obInPlaceComboTopLeft(obWindowRect.TopLeft()); 
	
	// Get the active list
	// Get the control window rect
	// If the inplace combobox top left is in the rect then
	// The control is the active control
	m_AttStruct.GetWindowRect(&obWindowRect);
	
	int iColIndex = (int )wParam;
	
	CStringList* pComboList = reinterpret_cast<CStringList*>(lParam);
	pComboList->RemoveAll(); 
	
	if (obWindowRect.PtInRect(obInPlaceComboTopLeft)&&isAttstr) 
	{				
		if(iColIndex==2)
		{
            pComboList->AddTail("字符串");
			pComboList->AddTail("字节型");
			pComboList->AddTail("短整形");
			pComboList->AddTail("长整形");
			pComboList->AddTail("浮点型");
			pComboList->AddTail("双精度型");
			pComboList->AddTail("日期型");
			pComboList->AddTail("时间型");
			pComboList->AddTail("布尔型");
			pComboList->AddTail("文本");
			pComboList->AddTail("图像");
			pComboList->AddTail("地图");
			pComboList->AddTail("声音");
			pComboList->AddTail("动态图像");
			pComboList->AddTail("扩展型");
			pComboList->AddTail("二进制数据");
			pComboList->AddTail("邮戳");
			pComboList->AddTail("数字型");
			pComboList->AddTail("表格");

		}
	}
	return true;
}

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

void CControlAttDlg::OnRclickList1(NMHDR* pNMHDR, LRESULT* pResult) 
{
	// TODO: Add your control notification handler code here
		CPoint pt;
	::GetCursorPos(&pt);

	CMenu menu;
	if (isAttstr)
	{
		menu.LoadMenu(IDR_MENU1);
	}else
	{
        menu.LoadMenu(IDR_MENU2);
	}	
	CMenu* pMenu=menu.GetSubMenu(0);
	pMenu->TrackPopupMenu(TPM_RIGHTBUTTON,pt.x,pt.y,this,NULL);
	*pResult = 0;
}

void CControlAttDlg::OnMenuItemsClick(UINT id,CString attorats)
{

switch(id)
	{
	case 1:
		{
_CloseArea(m_Ai);
	if((m_Ai = _OpenArea(m_AH,PNT)) <= 0)	return ;
	//装入点文件
	if(_LoadFile(m_Ai) <= 0)			
	{	_CloseArea(m_Ai);	return;}

if (attorats=="ats")
{  GetAttstr(m_Ai,PNT);//取得工作区中点的属性或属性结构
}else if(attorats=="att"){GetAtt(m_Ai,PNT);}
	   
		break;
		}
	case 2:
		{
			_CloseArea(m_Ai);
			if((m_Ai = _OpenArea(m_AH,LIN)) <= 0)	return ;
	//装入线文件
	if(_LoadFile(m_Ai) <= 0)			
	{	_CloseArea(m_Ai);	return;}

	if (attorats=="ats")
	{	GetAttstr(m_Ai,LIN);//取得工作区中线的属性或属性结构
	}else if(attorats=="att"){GetAtt(m_Ai,LIN);}

		break;
		}
	case 3:
		{
			_CloseArea(m_Ai);
		if((m_Ai = _OpenArea(m_AH,REG)) <= 0)	return ;
	//装入面文件
	if(_LoadFile(m_Ai) <= 0)			
	{	_CloseArea(m_Ai);	return;}

	if (attorats=="ats")
	{GetAttstr(m_Ai,REG);//取得工作区中区的属性或属性结构
	}else if(attorats=="att"){
		GetAtt(m_Ai,REG);
	}

		break;
		}
	case 4:
		{
			_CloseArea(m_Ai);
			if((m_Ai = _OpenArea(m_AH,TBL)) <= 0)	return ;
	//装入表文件
	if(_LoadFile(m_Ai) <= 0)			
	{	_CloseArea(m_Ai);	return;}

	m_AttStruct.DeleteAllItems();//取得表的属性或属性结构
	if (attorats=="ats")
	{
		GetAttstr(m_Ai,TBL);
	}else if(attorats=="att"){GetAtt(m_Ai,TBL);}

		break;
		}

⌨️ 快捷键说明

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