Click here to Skip to main content
14,147,016 members
Click here to Skip to main content
Add your own
alternative version


35 bookmarked
Posted 3 Mar 2000

CMapPin - A Map Pin Implementation

, 3 Mar 2000
Rate this:
Please Sign up or sign in to vote.
A Freeware MFC class to implement Map pins.
  • Download source files - 286 Kb
  • Introduction

    Welcome to CMapPin, a freeware MFC classes to provide map pins useful in GIS applications. If you have Microsoft AutoRoute Express (I think it's called AutoMap in the US) installed, you will probably have seem what I am talking about.

    Here's a small sample of what the map pins look like when overlaid on a bitmap map:

    Sample Image

    API Reference
    Planned Enhancements
    Contacting the Author


    • Standard CWnd derived class which can be used just like any other MFC control classes (e.g. CStatic) which are derived from CWnd.
    • Support for tooltips, drag / drop and context menus is built in.
    • For further customization, you can derive a class from it.
    • The class is fully Unicode compliant and includes Unicode built options in the workspace file.


    • To use the class in your code simply include mappin.cpp in your project and #include mappin.h in which ever of your modules needs to make calls to the class.
    • Attach an icon to the map pin using SetIcon() and then call Create() to actually create the map pin. That's it. You should now see the map pin on your window.
    • You should also have a look at the demo program to see exact details of how to use the map pins.


    V1.0 (13th May 1998)
    • Initial public release.

    V1.01 (12th September 1998)

    • Fixed a small redraw glitch in SetIcon().

    API Reference

    The API consists of the the public member functions of the class CMapPin:




    Standard C++ constructor. Just initializes internal variables to a default value.



    Standard C++ destructor. Internally it will free any resources used by this instance.


    BOOL Create(LPCTSTR lpszTooltipText, DWORD dwStyle, const CPoint& p, CWnd* pParent, UINT nID);

    Return Value:
    Nonzero if successful; otherwise 0.


    • lpszTooltipText -- Specifies the tooltip text to use for the control. If NULL, no text will be visible.
    • dwStyle -- Specifies the control's window style. Normally this will just be WS_CHILD and WS_VISIBLE.
    • p -- Specifies the position of the control. The size will be taken from the attached icon.
    • pParentWnd -- Specifies the control's parent window, usually your CView derived class. It must not be NULL.
    • nID -- Specifies the control's control ID.

    Construct a CMapPin object in three steps. First call the constructor, then SetIcon() and then call Create(), which creates the Windows control and attaches it to the CMapPin object.

    Apply the following window styles to a map pin control:

    • WS_CHILD: Always
    • WS_VISIBLE: Usually
    • WS_DISABLED: Rarely


    BOOL SetIcon(HINSTANCE hModule, LPCTSTR lpszResourceName, BOOL bSmallIcon);
    BOOL SetIcon(HINSTANCE hModule, UINT nIDResource, BOOL bSmallIcon);

    Return Value:
    Nonzero if successful; otherwise 0.


    • hModule -- Handle to an instance of the module whose executable file contains the icon to be loaded.
    • lpszResourceName -- Pointer to a null-terminated string that contains the name of the icon resource to be loaded.
    • nIDResource -- The resource identifier of the icon resource to be loaded.
    • bSmallIcon -- Specifies whether a small (16 * 16) icon is being loaded, FALSE indicates that a standard 32 * 32 icon is being loaded.

    Modifies the icon to be displayed on the map pin.


    HICON GetIcon() const;

    Return Value:
    Returns the handle of the icon currently being used by this map pin instance.


    void SetPopupMenu(LPCTSTR pszResourceName);
    void SetPopupMenu(UINT nIDResource);


    • lpszResourceName -- Pointer to a null-terminated string that contains the name of the icon resource to be used.
    • nIDResource -- The resource identifier of the icon resource to be used.

    Sets which menu resource will be used in context menus for this map pin instance.


    void SetAllowDrag(BOOL bAllowDrag);


    • bAllowDrag -- TRUE if you want to allow the map pin be dragable, FALSE will disallow dragging.

    Changes whether or not the map pin can be dragged around.


    BOOL GetAllowDrag() const;

    Return Value:
    TRUE if the instance allows dragging, otherwise FALSE.

    Planned Enhancements

    • If you have any other suggested improvements, please let me know so that I can incorporate them into the next release.

    Contacting the Author

    PJ Naughter
    12th September 1998


    This article has no explicit license attached to it but may contain usage terms in the article text or the download files themselves. If in doubt please contact the author via the discussion board below.

    A list of licenses authors might use can be found here


    About the Author

    PJ Naughter
    United States United States
    No Biography provided

    You may also be interested in...

    Comments and Discussions

    Generalthanks,it is useful,but.... Pin
    batsword21-Dec-10 15:26
    memberbatsword21-Dec-10 15:26 
    Answeryour codes are very useful Pin
    dujiangyan4-May-09 2:23
    memberdujiangyan4-May-09 2:23 
    GeneralGood, Thanks Pin
    Lancelot Yuan14-Jul-05 19:48
    memberLancelot Yuan14-Jul-05 19:48 
    GeneralThey DO consume too many memory! Pin
    Kevin Bao25-May-05 23:27
    memberKevin Bao25-May-05 23:27 
    GeneralRe: They DO consume too many memory! Pin
    pjnaughter25-May-05 23:44
    memberpjnaughter25-May-05 23:44 
    GeneralThanks to your replay, I think I need to optimize my code. Pin
    Kevin Bao26-May-05 0:15
    memberKevin Bao26-May-05 0:15 
    Generalcompiling error Pin
    Anonymous17-Jan-05 22:33
    memberAnonymous17-Jan-05 22:33 
    GeneralRe: compiling error Pin
    pjnaughter18-Jan-05 11:10
    memberpjnaughter18-Jan-05 11:10 
    GeneralRe: compiling error Pin
    wzh1983122129-Nov-06 18:28
    memberwzh1983122129-Nov-06 18:28 
    GeneralRe: compiling error Pin
    pjnaughter30-Nov-06 1:11
    memberpjnaughter30-Nov-06 1:11 
    Generalbeautiful work!!! Pin
    momomi20-Oct-04 14:56
    membermomomi20-Oct-04 14:56 
    GeneralGood work. Thanks a lot. Pin
    Kevin Bao17-May-04 16:38
    memberKevin Bao17-May-04 16:38 
    GeneralOn_command from popmenu Pin
    Thierry Lebrun28-Jan-04 13:30
    memberThierry Lebrun28-Jan-04 13:30 
    GeneralGIS sample code Pin
    Jongmin Park26-Sep-00 6:19
    memberJongmin Park26-Sep-00 6:19 
    GeneralRe: GIS sample code Pin
    Anonymous4-Jun-03 23:01
    memberAnonymous4-Jun-03 23:01 
    GeneralRe: GIS sample code Pin
    pjnaughter4-Jun-03 23:29
    memberpjnaughter4-Jun-03 23:29 
    QuestionCreate with WS_THICKFRAME,How to MoveWindow? Pin
    Min Huasong8-Aug-00 4:48
    sussMin Huasong8-Aug-00 4:48 
    AnswerRe: Create with WS_THICKFRAME,How to MoveWindow? Pin
    Juan Carlos Cobas22-Aug-01 5:13
    memberJuan Carlos Cobas22-Aug-01 5:13 
    GeneralRe: Create with WS_THICKFRAME,How to MoveWindow? Pin
    Juan Carlos Cobas22-Aug-01 5:14
    memberJuan Carlos Cobas22-Aug-01 5:14 
    QuestionExecution is windows 98, 2000? Pin
    kweon.30-Mar-00 15:16
    susskweon.30-Mar-00 15:16 
    AnswerRe: Execution is windows 98, 2000? Pin
    PJ Naughter30-Mar-00 22:34
    memberPJ Naughter30-Mar-00 22:34 
    Generalvery useful Pin
    Huang Wei15-Mar-00 13:20
    memberHuang Wei15-Mar-00 13:20 

    General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

    Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.

    Permalink | Advertise | Privacy | Cookies | Terms of Use | Mobile
    Web06 | 2.8.190518.1 | Last Updated 4 Mar 2000
    Article Copyright 2000 by PJ Naughter
    Everything else Copyright © CodeProject, 1999-2019
    Layout: fixed | fluid