Create a custom point symbol server in Visual Studio 6.0.

1. File->New...
   a) Select Projects tab
   c) Enter project name, for example, CustomSymbol
   d) Press OK

2) ATL COM AppWizard - Step 1 of 1
   a) Select Dynamic Link Library radio button
   b) Check MFC support.
   c) Press Finish

3) New Project Information
   a) Press OK

4) Insert->New ATL Object...
   a) Select "Objects" in list of Categories
   b) Select "Simple Object" in list of Objects
   c) Press Next

5) ATL Object Wizard Properties
   a) Select Names tab
   b) Enter the name of your point symbol class in Short Name, for example
MyPointSymbol
   c) No change is necessary to anything on the Attributes tab
   d) Press OK

6) Workspace window, ClassView tab
   a) Expand the list of classes in your project
   b) You will see a class name starting with a "C", like CMyPointSymbol.
   c) Right-click on this class, and choose Implement Interface...
   d) Press OK in the warning dialog, this is telling you that you need an ‘
idl’ file.

7) Browse Type Libraries
   a) Press Browse...
   b) Find AFCust20.tlb and select it. This is typically in ‘..\Common
Files\ESRI\’
   c) Press Open

8) Implement Interface
   a) You will see a list of the interfaces supported by AFCustom20.
   b) To implement the point symbol interface, check the box next to
ICustomMarker.
   c) Press OK

9) Workspace window, ClassView tab
   a) Double-click on the CMyPointSymbol class
   b) This will open the file MyPointSymbol.h in a window.

10) MyPointSymbol.h
   a) Locate the implementations of SetupDC, ResetDC, and Draw.

These will look like this:

STDMETHOD(SetupDC)(LONG hDC, DOUBLE dpi, IDispatch * pBaseSym)
{
return E_NOTIMPL;
}
STDMETHOD(ResetDC)(LONG hDC)
{
return E_NOTIMPL;
}
STDMETHOD(Draw)(LONG hDC, LONG x, LONG y)
{
return E_NOTIMPL;
}

   b) Add a private member variable. In the workspace window, ClassView Tab,
highlight the CMyPointSymbol class. Right click on the mouse and select ‘Add
member variable’. Enter type as CPen* and name as m_oldPen. This will be use
to hold your old pen
object that is returned from CDC::SelectStockObject

   c) Add your code to implement your custom point symbol. The following
example is very basic – it simply draws each point symbol as three
concentric squares.
STDMETHOD(SetupDC)(LONG hDC, DOUBLE dpi, IDispatch * pBaseSym)

{
CDC* pcdc = CDC::FromHandle((HDC)hDC);
m_oldPen =
CPen*)pcdc->SelectStockObject(BLACK_PEN);
return S_OK;
}
STDMETHOD(ResetDC)(LONG hDC)
{
CDC* pcdc = CDC::FromHandle((HDC)hDC);
CPen* temp = pcdc->SelectObject(m_oldPen);
temp->DeleteObject();
return S_OK;
}
STDMETHOD(Draw)(LONG hDC, LONG x, LONG y)
{
CDC* pcdc;
pcdc =
::CDC::FromHandle((HDC)hDC);
CPoint pt;
for (int i= 0; i<10; i+=2)
{
pt.x = x-i;
pt.y = y-i;
pcdc->MoveTo(pt);
pcdc->LineTo(pt.x+(2*i),pt.y);
pcdc->LineTo(pt.x+(2*i),pt.y+(2*i));
pcdc->LineTo(pt.x,pt.y+(2*i));
pcdc->LineTo(pt);
}
return S_OK;
}
11) Build->Set Active Configuration
   a) Select Win32 Release MinDependency

12) Build->Rebuild All
   b) Build your dll.

13) You can now use your new COM object within your application

posted on 2005-10-09 15:13  刘民  阅读(783)  评论(0编辑  收藏  举报