VC中custom symbol的方法(For MO)[转自ESRI]

本文详细介绍了创建并实现自定义COM对象的步骤,包括新建项目、选择项目类型、插入ATL对象、实现接口、添加成员变量和代码等,最后进行构建生成dll,以便在应用程序中使用该COM对象。
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

转载于:https://www.cnblogs.com/bgming/archive/2005/10/09/250953.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值