www.pudn.com > MapDB.rar > ResultDlg.cpp


// ResultDlg.cpp : implementation file 
// 
 
#include "stdafx.h" 
#include "MapDB.h" 
#include "ResultDlg.h" 
#include "math.h" 
 
#ifdef _DEBUG 
#define new DEBUG_NEW 
#undef THIS_FILE 
static char THIS_FILE[] = __FILE__; 
#endif 
 
///////////////////////////////////////////////////////////////////////////// 
// CResultDlg dialog 
 
 
CResultDlg::CResultDlg(CMapDBDoc * pDoc,CWnd* pParent /*=NULL*/) 
	: CDialog(CResultDlg::IDD, pParent) 
{ 
	//{{AFX_DATA_INIT(CResultDlg) 
		// NOTE: the ClassWizard will add member initialization here 
	//}}AFX_DATA_INIT 
	m_pDoc = pDoc; 
	m_pWnd = pParent; 
} 
 
 
void CResultDlg::DoDataExchange(CDataExchange* pDX) 
{ 
	CDialog::DoDataExchange(pDX); 
	//{{AFX_DATA_MAP(CResultDlg) 
	DDX_Control(pDX, IDC_OBJSELECT_LIST, m_list); 
	//}}AFX_DATA_MAP 
} 
 
 
BEGIN_MESSAGE_MAP(CResultDlg, CDialog) 
	//{{AFX_MSG_MAP(CResultDlg) 
	ON_LBN_SELCHANGE(IDC_OBJSELECT_LIST, OnSelchangeObjselectList) 
	//}}AFX_MSG_MAP 
END_MESSAGE_MAP() 
 
///////////////////////////////////////////////////////////////////////////// 
// CResultDlg message handlers 
 
BOOL CResultDlg::OnInitDialog()  
{ 
	CDialog::OnInitDialog(); 
 
	Update(); 
 
	SetPosition(); 
 
	return TRUE;  // return TRUE unless you set the focus to a control 
	              // EXCEPTION: OCX Property Pages should return FALSE 
} 
 
void CResultDlg::PostNcDestroy()  
{ 
	delete this;	 
	CDialog::PostNcDestroy(); 
} 
 
void CResultDlg::Update() 
{ 
	m_list.ResetContent(); 
  
 	if ( m_pDoc ) 
 	{ 
 		m_list.SetRedraw(false); 
  
 		CString idformat; 
 		idformat.Format("%c0%dld",'%',(int)log10(m_pDoc->m_mapobjs.GetSize()) + 1); 
  
 		for (int count = 0;count < m_pDoc->m_objsel.GetSize();count ++ ) 
 		{ 
 			for (int bitcount = 0;bitcount < 8;bitcount ++) 
 			{ 
 				if ( m_pDoc->m_objsel[count][bitcount] ) 
 				{ 
 					CMapObject * obj = m_pDoc->m_mapobjs[count * 8 + bitcount]; 
 					CString objid; 
 					objid.Format(idformat,obj->ID); 
 					m_list.AddString(objid); 
 				} 
 			} 
 		} 
  
 		if ( m_list.GetCount() ) 
 		{ 
 			CClientDC dc(this); 
 			CString texfile; 
 			CSize size; 
 			m_list.GetText(0,texfile); 
 			size = dc.GetTextExtent(texfile); 
 			m_list.SetColumnWidth(size.cx + 15); 
 		} 
  
 		m_list.SetRedraw(true); 
 	} 
} 
 
void CResultDlg::OnSelchangeObjselectList()  
{ 
	int nSel = m_list.GetCurSel(); 
	if ( nSel == LB_ERR ) 
		return; 
	CString text; 
	m_list.GetText(nSel,text); 
	if ( m_pDoc ) 
	{ 
		DWORD id,index; 
		id = atol(text); 
		if ( m_pDoc->m_mapobjids.Lookup(id,index) ) 
		{ 
			CPoint pt; 
			CMapObject * obj = m_pDoc->m_mapobjs[index]; 
			if ( obj->GetCenter(pt) ) 
			{ 
				m_pDoc->SetCenter(pt); 
				m_pDoc->UpdateAllViews(NULL); 
			} 
		} 
	}	 
} 
 
void CResultDlg::SetPosition() 
{ 
	if ( m_pWnd ) 
	{ 
		CRect rect; 
		GetWindowRect(&rect); 
		CPoint pt(0,0); 
		m_pWnd->ClientToScreen(&pt); 
		rect.OffsetRect(CPoint(pt.x - rect.left,pt.y - rect.top)); 
		MoveWindow(&rect); 
	} 
}