Create a MapX custom tool-ranging Tool

Source: Internet
Author: User
Tags gety

Creating a custom tool is a very important part of MapX programming. The steps are relatively simple, but many people can easily ignore some of the steps, making this function difficult to implement. You can perform the following steps. It takes a lot of time to do this function, because most articles about this function ignore the third step, making it difficult for beginners to implement it successfully.

Therefore, the steps are further detailed based on the previous improvements. Other custom tools can follow similar steps.

// 1. Define Constants
# Define mytool_distance 100 // 1 ~ 999

// 2. Create a tool
M_ctrlmap.createcustomtool (mytool_distance, mitooltypepoly, microsscursor );

// 3. Create an event slot
In view. H, add a line of code under the declare_message_map () Row: declare_eventsink_map ()
In view. cpp, add
Begin_eventsink_map (cpatrolcheckview, cview)
On_event (cpatrolcheckview, idc_map, 11/* mapx_dispid_polytoolused */, onpolytoolusedmap,

Vts_i2 vts_i4 vts_dispatch vts_bool vts_pbool)
End_eventsink_map ()

 
// 4. Respond to the event
Add void onpolytoolusedmap (short toolnum, long flags, lpdispatch points, bool in view. h.

Bshift, bool bctrl, bool far * enabledefault );
Add the implementation code to view. cpp.
Void cmapxsampleview: onpolytoolusedmap (short toolnum, long flags, lpdispatch points,
Bool bshift, bool bctrl, bool far * enabledefault)
{
// Calculate the distance
If (flags = mipolympus toolinprogress) {// This sentence is optional
If (toolnum = mytool_distance)
{
Cmapxpoints PTS;
Long N;
Long I;
Try {
PTS. attachdispatch (points, false); // get points object
Double dddistancetot = 0.0;
N = pts. getcount ();
M_ctrlmapx.setmapunit (miunitkilometer );
For (I = 1; I <n; I ++)
{
Cmapxpoint pt1 = pts. item (I );
Cmapxpoint pt2 = pts. Item (I + 1 );
Double D = m_ctrlmapx.distance (pt1.getx (), pt1.gety (), pt2.getx (),
Pt2.gety ());
Ddistancetot + = D;
}
Cstring STR;
Str. Format ("total distance: % F", ddistancetot );
// Output distance in the status bar
(Cmainframe *) afxgetmainwnd ()-> m_wndstatusbar.setpanetext (0, STR); // set m_wndstatusbar first

Public
}
Catch (coledispatchexception * E ){
E-> reporterror ();
E-> Delete ();
}
Catch (coleexception * E ){
E-> reporterror ();
E-> Delete ();
}
}
} // If (flags = mipolympus toolinprogress)
}

// 5. Call the tool
Void cmapxsampleview: onmaptooldistancetool ()
{
M_ctrlmapx.setcurrenttool (mytool_distance );//

}

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.