?? serialsampleview.cpp
字號:
// SerialSampleView.cpp : implementation of the CSerialSampleView class
//
/* This sample application and corresponding sample code is provided
* for example purposes only. It has not undergone rigorous testing
* and as such should not be shipped as part of a final application
* without extensive testing on the part of the organization releasing
* the end-user product.
*/
#include "stdafx.h"
#include "SerialSample.h"
#include "SerialSampleDoc.h"
#include "SerialSampleView.h"
#include "ChooseListDialog.h"
#include "AddThemeDialog.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
/////////////////////////////////////////////////////////////////////////////
// CSerialSampleView
IMPLEMENT_DYNCREATE(CSerialSampleView, CView)
BEGIN_MESSAGE_MAP(CSerialSampleView, CView)
//{{AFX_MSG_MAP(CSerialSampleView)
ON_WM_SIZE()
ON_WM_SETFOCUS()
ON_COMMAND(ID_ARROW_TOOL, OnArrowTool)
ON_UPDATE_COMMAND_UI(ID_ARROW_TOOL, OnUpdateArrowTool)
ON_COMMAND(ID_ZOOMIN_TOOL, OnZoominTool)
ON_UPDATE_COMMAND_UI(ID_ZOOMIN_TOOL, OnUpdateZoominTool)
ON_COMMAND(ID_ZOOMOUT_TOOL, OnZoomoutTool)
ON_UPDATE_COMMAND_UI(ID_ZOOMOUT_TOOL, OnUpdateZoomoutTool)
ON_COMMAND(ID_ADD_DATA, OnAddData)
ON_COMMAND(ID_ADD_THEME, OnAddTheme)
ON_UPDATE_COMMAND_UI(ID_ADD_THEME, OnUpdateAddTheme)
ON_COMMAND(ID_LAYER_CONTROLS, OnLayerControls)
//}}AFX_MSG_MAP
// Standard printing commands
ON_COMMAND(ID_FILE_PRINT, CView::OnFilePrint)
ON_COMMAND(ID_FILE_PRINT_DIRECT, CView::OnFilePrint)
ON_COMMAND(ID_FILE_PRINT_PREVIEW, CView::OnFilePrintPreview)
END_MESSAGE_MAP()
BEGIN_EVENTSINK_MAP(CSerialSampleView, CView)
ON_EVENT(CSerialSampleView, IDC_MAP, MAPX_DISPID_THEMEMODIFYREQUESTED, OnMapThemeModifyRequested, VTS_DISPATCH)
END_EVENTSINK_MAP()
/////////////////////////////////////////////////////////////////////////////
// CSerialSampleView construction/destruction
CSerialSampleView::CSerialSampleView()
{
// TODO: add construction code here
}
CSerialSampleView::~CSerialSampleView()
{
}
BOOL CSerialSampleView::PreCreateWindow(CREATESTRUCT& cs)
{
// TODO: Modify the Window class or styles here by modifying
// the CREATESTRUCT cs
return CView::PreCreateWindow(cs);
}
/////////////////////////////////////////////////////////////////////////////
// CSerialSampleView drawing
void CSerialSampleView::OnDraw(CDC* pDC)
{
CSerialSampleDoc* pDoc = GetDocument();
ASSERT_VALID(pDoc);
// TODO: add draw code for native data here
}
/////////////////////////////////////////////////////////////////////////////
// CSerialSampleView printing
BOOL CSerialSampleView::OnPreparePrinting(CPrintInfo* pInfo)
{
// default preparation
return DoPreparePrinting(pInfo);
}
void CSerialSampleView::OnBeginPrinting(CDC* /*pDC*/, CPrintInfo* /*pInfo*/)
{
// TODO: add extra initialization before printing
}
void CSerialSampleView::OnEndPrinting(CDC* /*pDC*/, CPrintInfo* /*pInfo*/)
{
// TODO: add cleanup after printing
}
/////////////////////////////////////////////////////////////////////////////
// CSerialSampleView diagnostics
#ifdef _DEBUG
void CSerialSampleView::AssertValid() const
{
CView::AssertValid();
}
void CSerialSampleView::Dump(CDumpContext& dc) const
{
CView::Dump(dc);
}
CSerialSampleDoc* CSerialSampleView::GetDocument() // non-debug version is inline
{
ASSERT(m_pDocument->IsKindOf(RUNTIME_CLASS(CSerialSampleDoc)));
return (CSerialSampleDoc*)m_pDocument;
}
#endif //_DEBUG
/////////////////////////////////////////////////////////////////////////////
// CSerialSampleView message handlers
void CSerialSampleView::OnSize(UINT nType, int cx, int cy)
{
CView::OnSize(nType, cx, cy);
CMapX* map = GetDocument()->GetMap();
if(map != NULL)
map->MoveWindow(0,0,cx,cy);
}
void CSerialSampleView::OnSetFocus(CWnd* pOldWnd)
{
CView::OnSetFocus(pOldWnd);
CMapX* map = GetDocument()->GetMap();
if(map != NULL)
map->SetFocus();
}
void CSerialSampleView::OnArrowTool()
{
try {
CMapX* map = GetDocument()->GetMap();
if(map != NULL)
map->SetCurrentTool(miArrowTool);
} catch(COleDispatchException* e) {
e->ReportError();
e->Delete();
} catch(COleException* e) {
e->ReportError();
e->Delete();
}
}
void CSerialSampleView::OnUpdateArrowTool(CCmdUI* pCmdUI)
{
try {
CMapX* map = GetDocument()->GetMap();
if(map != NULL) {
pCmdUI->Enable(TRUE);
pCmdUI->SetCheck(map->GetCurrentTool() == miArrowTool);
} else
pCmdUI->Enable(FALSE);
} catch(COleDispatchException* e) {
e->ReportError();
e->Delete();
} catch(COleException* e) {
e->ReportError();
e->Delete();
}
}
void CSerialSampleView::OnZoominTool()
{
try {
CMapX* map = GetDocument()->GetMap();
if(map != NULL)
map->SetCurrentTool(miZoomInTool);
} catch(COleDispatchException* e) {
e->ReportError();
e->Delete();
} catch(COleException* e) {
e->ReportError();
e->Delete();
}
}
void CSerialSampleView::OnUpdateZoominTool(CCmdUI* pCmdUI)
{
try {
CMapX* map = GetDocument()->GetMap();
if(map != NULL) {
pCmdUI->Enable(TRUE);
pCmdUI->SetCheck(map->GetCurrentTool() == miZoomInTool);
} else
pCmdUI->Enable(FALSE);
} catch(COleDispatchException* e) {
e->ReportError();
e->Delete();
} catch(COleException* e) {
e->ReportError();
e->Delete();
}
}
void CSerialSampleView::OnZoomoutTool()
{
try {
CMapX* map = GetDocument()->GetMap();
if(map != NULL)
map->SetCurrentTool(miZoomOutTool);
} catch(COleDispatchException* e) {
e->ReportError();
e->Delete();
} catch(COleException* e) {
e->ReportError();
e->Delete();
}
}
void CSerialSampleView::OnUpdateZoomoutTool(CCmdUI* pCmdUI)
{
try {
CMapX* map = GetDocument()->GetMap();
if(map != NULL) {
pCmdUI->Enable(TRUE);
pCmdUI->SetCheck(map->GetCurrentTool() == miZoomOutTool);
} else
pCmdUI->Enable(FALSE);
} catch(COleDispatchException* e) {
e->ReportError();
e->Delete();
} catch(COleException* e) {
e->ReportError();
e->Delete();
}
}
void CSerialSampleView::OnMapThemeModifyRequested(LPDISPATCH theme) {
CMapXTheme themeObj;
COptionalVariant optVt;
themeObj.AttachDispatch(theme, FALSE);
// This function shows the Theme Modification dialog when the Legend
// for the theme is double clicked upon.
// If the control key is being held down, however, the Legend modification
// dialog is shown instead.
// The optional paraemters specify the help file (we don't have one).
try {
if(GetAsyncKeyState(VK_CONTROL)) {
themeObj.GetLegend().LegendDlg(optVt, optVt);
} else {
themeObj.ThemeDlg(optVt, optVt);
}
} catch (COleDispatchException *e) {
e->ReportError();
e->Delete();
} catch (COleException *e) {
e->ReportError();
e->Delete();
}
}
void CSerialSampleView::OnAddData()
{
CStringList tables;
CDaoDatabase* db = GetDocument()->GetDB();
if(db == NULL) {
CString msg;
try {
msg.Format("Could not open database %s", GetDocument()->GetDBPath());
} catch(CString s) {
msg = s; // GetDBPath will throw an appropriate error if it can't find the database.
}
AfxMessageBox(msg);
return;
}
int nCount = db->GetTableDefCount();
CDaoTableDefInfo info;
for(int i = 0; i < nCount; i++) {
db->GetTableDefInfo(i, info);
// Add all non system tables to the list
if(!(info.m_lAttributes & dbSystemObject) && !(info.m_lAttributes & dbHiddenObject))
tables.AddTail(info.m_strName);
}
CMapX* map = GetDocument()->GetMap();
if(map == NULL) {
AfxMessageBox("Add Data called without a Map control");
return;
}
// Then, remove all the tables which we've already added as datasets.
CMapXDatasets datasets = map->GetDatasets();
nCount = datasets.GetCount();
for(i = 1; i <= nCount; i++) {
POSITION pos = tables.Find(datasets.Item(i).GetName());
if(pos != NULL)
tables.RemoveAt(pos);
}
if(tables.GetCount() == 0) {
AfxMessageBox("No tables left to add");
return;
}
// Now, ask the user to pick a dataset to add
CChooseListDialog choiceDlg("Please choose a table to add:", tables, 0, this);
CString choice;
try {
choice = choiceDlg.GetChoice();
} catch(CString) {
return; // Do nothing if the user doesn't pick anything
}
// And add the chosen table.
GetDocument()->AddDataset(choice);
}
void CSerialSampleView::OnAddTheme()
{
CMapX* map = GetDocument()->GetMap();
if(map != NULL) {
CAddThemeDialog dlg(map);
dlg.DoModal();
}
}
void CSerialSampleView::OnUpdateAddTheme(CCmdUI* pCmdUI)
{
pCmdUI->Enable(GetDocument()->GetMap() != NULL && GetDocument()->GetMap()->GetDatasets().GetCount() > 0);
}
void CSerialSampleView::OnLayerControls()
{
try {
CMapX* map = GetDocument()->GetMap();
COptionalVariant optVt;
if(map != NULL)
// The optional parameters can be used to specify a help file
map->GetLayers().LayersDlg(optVt, optVt);
} catch(COleDispatchException* e) {
e->ReportError();
e->Delete();
} catch(COleException* e) {
e->ReportError();
e->Delete();
}
}
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -