Mapwingis C + + MFC changes the cursor state to zoom in and out of the translation effect

Source: Internet
Author: User

Mapwingis is a free open source plugin, and most of the tutorials on the official web are in C #. Recently done a project is the use of MFC, how to call his interface, the online data is relatively small, most of the only talk about how to display the vector or image data is over, but so, an open picture of the default state of the cursor is magnified, the left mouse button click is when the big, right button is reduced, Drag is selected to enlarge, how to achieve like he gave the demo in the Click to zoom in, or zoom out, the pan button to switch the mouse state to complete the corresponding operation, Mapwingis these operations are encapsulated, but the C + + call interface is not detailed (or maybe I did not find on the official website ...) , there is a version of the problem, said the lower version has to provide interface modification, I installed a few of the lower version of the change, or can not change. It is OK to record how to use the Mapwingis plugin in MFC, and finally say how to change the cursor state.

1, in the official website Download Mapwingis installation program http://mapwingis.codeplex.com/releases/view/541892, download the direct default installation, finally do not change the installation path, I did not test the situation after the change. The default installation will appear on the C disk in this directory C:\dev\MapWinGIS, remember this directory, will be used later.


2, with vs2012 (other version should also be possible) to create a single document or a multi-document program, and then click on this location to create a new class


Then select the class to add the ActiveX control to in this location




3. The StdAfx.h file is added

#import "C:\dev\MapWinGIS\MapWinGIS.ocx" Rename_namespace ("Mapwindow") Rename ("GetObject", "Gisgetobject")
Add in Resource.h

#define Idc_map140
Only ensure that the ID is not duplicated

4. Add a variable to the view class

Cdmap M_map; This cdmap class is generated when the ActiveX class was previously imported. I am directly using the public variables, unsafe? I haven't met you for the moment.

5, Add the WM_CREATE message response function of the view class, dynamically create the map window, the code is as follows:

int cxxview::oncreate (lpcreatestruct lpcreatestruct) {if (cview::oncreate (lpcreatestruct) = =-1) return-1;//TODO:  Add your dedicated create code CRect rect here; GetClientRect (&rect); M_map.create (Null,ws_child | ws_visible | WS_BORDER,RECT,THIS,IDC_MAP); return 0;}

6.Add a response function for the wm_size message of the view class, adding the following code to make the map control fill the entire view:

void Cxxview::onsize (UINT nType, int cx, int cy) {cview::onsize (NType, CX, CY);//TODO: Add Message Handler code here if (M_map.m_hwnd = = NUL L) return;if (IsWindow (M_map.m_hwnd)) {CRect rect; GetClientRect (&rect); M_map.movewindow (Rect,false); M_map.zoomtoprev ();}}
7, Next is to show that you can use the default Serialize function in the Doc class to get the file path, for example:

#pragma warning (disable:4996) //Call strlwr function, it will make an error without this sentence.

void Csexxdoc::serialize (carchive& ar) {if (AR. IsStoring ()) {//TODO: Add storage code here}else{//TODO: Add the load code cfile *p_file = ar here. GetFile (); CString Filepathtem = M_filepath; CString Fileexttem = M_fileext;m_filepath = P_file->getfilepath (); char * Nametem = M_filepath.getbuffer (); char * ext = STRLWR (STRRCHR (Nametem, '. ') + 1); m_fileext = ext; CMainFrame *pframe = (CMainFrame *) AfxGetMainWnd (); Cxxview * PView = (Cxxview *) Pframe->getactiveview (); if (M_fileext = = "tif") {pview->drawimage (M_filepath);} else if (M_fileext = = "shp") {pview->drawshp (M_filepath);} Else{afxmessagebox (_t ("temporarily only supports *.tif *.shp"); return;}}}


M_filepath can be declared as a common member variable of doc

Then in the view class to implement the corresponding display operation can be

8. Display TIF

void Cxxview::D rawimage (CString filePath) {//Create Image interface Open image add Map m_map.removealllayers (); Mapwindow::iimageptr pimage; Pimage.createinstance (__uuidof (mapwindow::image));p Image->open (_bstr_t (FilePath), Mapwindow::use_file_ Extension,true,null); M_map.addlayer (pimage,true); Invalidate ();}
9. Show SHP

void Cxxview::D rawshp (CString filePath) {//Create SHP interface open SHP file add Map m_map.removealllayers (); mapwindow::ishapefileptr Pshapefilebound;pshapefilebound.createinstance (__uuidof (mapwindow::shapefile));p Shapefilebound->open (_bstr_ T (FilePath), false); M_map.addlayer (pshapefilebound,true); Invalidate ();}

This completes the display operation, how to implement other operations such as roaming.

Search on the internet for a long time, did not find the answer, finally in a foreigner's post found the solution, but also looked at a long time to understand what he said.

Read about roaming on the web, zooming in and out of the C # code is like this

Basic map operation magnification: Axmap1.cursormode = MapWinGIS.tkCursorMode.cmZoomIn; Zoom Out: Axmap1.cursormode = MapWinGIS.tkCursorMode.cmZoomOut; roaming: Axmap1.cursormode = MapWinGIS.tkCursorMode.cmPan; Full width: axmap1.zoomtomaxextents ( );

So the C + + code should also be similar to this,

There is said to write, as if Baidu space is a post, do not remember the link, directly excerpt some of the Foreigner's post code

Map. Setcursormode (Mapwingis::tkcursormode::cmpan);
But I added the code for a long time did not setcursormode this method, how to set, this post foreigner in the discussion method, it seems to be directly to the control to add a variable what, do not know where to add, and search for some, There is also a way to use Mapwingis, which is to add the Mapwingis control in a dialog box, but there is no control on my toolbox. Finally found that the original is to be added manually. Specific Add method is also in the foreigner's that forum saw, link temporarily can't find, there are two ways to add

One is directly on the dialog box left-click and then choose Add ActiveX Control, the second is the Tools menu under the Choose Toolbox Menu after selecting the COM component to find the Map Control 1.0, and then you can see that the property of this control does have this setting mode, and it is also valid later



Then add a class for this dialog box, add a variable to the Mapwingis control, associate it to the previous CDmap.h and CDmap.cpp, and find a big push error: But it doesn't matter, here I found out how to add Setcursormode this interface method.

void Setcursormode (Long propval) {SetProperty (0x3, VT_I4, propval);}

The other useless directly deleted on it, that is, as long as the CDmap.h in the interface to add in it.

That's where it's going to be called in the back.

M_map.setcursormode (mapwindow::tkcursormode::cmzoomout);
This tkcursormode has so many enumerations that it can be called on demand.

enum{    cmzoomin = 0,    cmzoomout = 1,    Cmpan = 2,    cmselection = 3,    cmnone = 4,    cmmeasure = 5,    Cmad DShape = 6,    Cmeditshape = 8,    cmsplitbypolyline = 9,    cmidentify = ten,    cmmoveshapes = one,    Cmrotateshapes =    Cmselectbypolygon =,    Cmerasebypolygon = +,    Cmsplitbypolygon =    Cmclipbypolygon = 16}tkcursormode;



Mapwingis C + + MFC changes the cursor state to zoom in and out of the translation effect

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.