翻译稿 联系客服

发布时间 : 星期四 文章翻译稿更新完毕开始阅读68d0e5d726fff705cc170afd

Getting Started with MapObjects Version 2.x in Visual C++

2. Implement OnMapFullExtent.

17

实施FullExtent按钮

在本节的内容中,你将如何实施充分的按钮。

1。使用ClassWizard添加一个ID_MAP_FULLEXTENT处理器来CEasyMapView命令。OnMapFullExtent称呼它。

2。实施OnMapFullExtent。

void CEasyMapView::OnMapFullExtent() { CMoRectangle r(m_map.GetFullExtent()); m_map.SetExtent(r);

}

The map has two extent properties: the FullExtent property is the full extent of the map; the Extent property keeps track of the current visible extent of the map. Setting the visible extent to the full extent results in the whole map being shown.

The remaining tools will be implemented later.

地图上有两个程度的性质:FullExtent财产的全部范围;程度地图财产跟踪当前可见范围的地图。可见程度设置在最大程度上导致整个地图表现。

剩下的工具将实施以后。

Test your changes

1. Build the application. 2. Run the application.

3. Drag a rectangle on the map to zoom in. 4. Click the zoom out button. 5. Click the map to zoom out. 6. Click the pan button.

7. Click and drag somewhere on the map to pan.

8. Click the full extent button (the globe) to draw the map at its full extent.

测试你的改变

1。建立应用程序。 2。运行的应用。

3。拖动矩形在地图上放大。 4。点击缩的按钮。 5。点击地图缩放。 6。点击“潘”按钮。

7。单击并拖动某处在地图上的平底锅。

8。在最大程度上点击按钮(全球)画地图,它的全部的程度。

Getting Started with MapObjects Version 2.x in Visual C++ 18

Getting Started with MapObjects Version 2.x in Visual C++ 19

Step Four: Creating a search tool

In this section you will add additional controls to your application to implement a simple function for locating a State by name. A new toolbar will contain a text edit field and a button that can be used to search for map features by attribute value. 步骤四:创造一个搜索工具

在本节的内容中,你会增加你的应用程序和控制,以实现一个简单的功能定位一个州的名字。一个新的工具栏将包含一个文本编辑栏和一个按钮,可以用来寻找地图特征属性值的重复。

Add Search Dialog Bar

1. Use the Components and Controls Gallery to add a new Dialog Bar. Title the new bar

“Search”. Look for the Dialog control in the Visual C++ Components folder.

2. In the method CMainFrame::OnCreate() in mainfrm.cpp, complete the implementation of the

dialog bar. Look for and follow the TODO instructions just preceding “m_wndSearch.Create(…)” with regard to adding the Search menu item.

3. Edit the dialog form for the bar (CG_IDD_SEARCH). Add a button and set the button?s ID to

IDC _SEARCH and it?s caption to “Search”. Click the Styles tab and make it the default button.

4. Add a text edit control and set its ID to IDC_SEARCHEDIT. The dialog should look similar to

the following:

Getting Started with MapObjects Version 2.x in Visual C++

20

5. The IDC_SEARCH handler will need to get the text from the dialog bar. Add a new public

member function to CMainFrame that retreives the search text. Again, click on the ClassView tab in the Workspace window, and highlighting the CmainFrame class, click on the right mouse button to bring up the appropriate menu that allows you to ?Add Member Function?. 加入搜索的对话框条

1。使用元件和控制画廊,以增加一个新的对话框条。新酒吧夺冠的“搜索”。寻找对话框控件在Visual C + +元件文件夹。

2。该方法在CMainFrame:OnCreate(),完成实施mainfrm.cpp对话框的酒吧。寻找并遵循指令前“m_wndSearch.Create待办事项,只是?)(“关于增加搜索菜单项目。

3。编辑对话框的形式(CG_IDD_SEARCH酒吧)。添加一个按钮,按钮设置的ID,IDC _SEARCH标题“搜索”。点击“风格”选项卡并把它设置为默认按钮。

4。添加一个文本编辑控件IDC_SEARCHEDIT并设置其身份证。这个对话框应该看起来相似如下:

5。IDC_SEARCH处理的需要获得课文对话框条。添加一个新的公共成员函数来

CMainFrame,retreives搜索文本。再次,点击ClassView标签与工作空间,突出的CmainFrame窗口类,点击鼠标右键来适当的菜单,让你的“添加成员函数”。

CString CMainFrame::GetSearchText() { CEdit* pEdit = (CEdit*)m_wndSearch.GetDlgItem(IDC_SEARCHEDIT); ASSERT_VALID(pEdit); CString text; pEdit->GetWindowText(text); return text; }

6. Use Class Wizard to add an event handler for the BN_CLICKED event for the IDC_SEARCH.

Open the Class Wizard, select the CEasyMapView class. From the list of Object Ids, select IDC_SEARCH. From the list of available Messages, select BN_CLICKED. Click the Add Function button and call it OnMapSearch.

6。使用类向导添加一个事件处理器的活动,要IDC_SEARCH BN_CLICKED。打开类向导,选择CEasyMapView班。从列表中选择的对象,IDC_SEARCH入侵检测系统(Ids)。从名单上可用的信息,选择BN_CLICKED。点击“附加功能,称之为OnMapSearch按钮。

Alternatively, you can manually add a public member function in CEasyMapView to handle the IDC_SEARCH event and in the Message Map for CEasyMapView (found in EastMapView.cpp) add the following line:

ON_COMMAND(IDC_SEARCH, OnMapSearch)

7. Implement OnMapSearch. Don?t forget to #include “MainFrm.h” at the top of

EasyMapView.cpp: 7。实施OnMapSearch。别忘了#包括“MainFrm.h“顶部的EasyMapView.cpp:

void CEasyMapView::OnMapSearch() {

//

// Build a search expression from the text in IDC_SEARCHEDIT //

CMainFrame* pMainFrame = (CMainFrame*)AfxGetMainWnd(); ASSERT_VALID(pMainFrame);

CString searchText = pMainFrame->GetSearchText();

CString expression;

expression.Format(\

//

// Get the states layer and search //

CMoLayers layers(m_map.GetLayers());

CMoMapLayer states(layers.Item(COleVariant(TEXT(\