allenwong
路人甲
路人甲
  • 注册日期2005-05-19
  • 发帖数23
  • QQ
  • 铜币249枚
  • 威望0点
  • 贡献值0点
  • 银元0个
阅读:1679回复:4

ESRI网站上给出的使用ATLCOM做的CustomSymbol真的是很好用啊

楼主#
更多 发布于:2005-07-07 11:09
<P>ESRI网站上给出的使用ATLCOM做的CustomSymbol真的是很好用啊!!<img src="images/post/smile/dvbbs/em03.gif" /></P>
<P >Create a custom point symbol server in Visual Studio 6.0. <p></p></P>
<P >1. File->New...<BR>   a) Select Projects tab<BR>   c) Enter project name, for example, CustomSymbol<BR>   d) Press OK<p></p></P>
<P >2) ATL COM AppWizard - Step 1 of 1<BR>   a) Select Dynamic Link Library radio button<BR>   b) Check MFC support.<BR>   c) Press Finish<p></p></P>
<P >3) New Project Information<BR>   a) Press OK<p></p></P>
<P >4) Insert->New ATL Object...<BR>   a) Select "Objects" in list of Categories<BR>   b) Select "Simple Object" in list of Objects<BR>   c) Press Next<p></p></P>
<P >5) ATL Object Wizard Properties<BR>   a) Select Names tab<BR>   b) Enter the name of your point symbol class in Short Name, for example <BR>MyPointSymbol<BR>   c) No change is necessary to anything on the Attributes tab<BR>   d) Press OK<p></p></P>
<P >6) Workspace window, ClassView tab<BR>   a) Expand the list of classes in your project<BR>   b) You will see a class name starting with a "C", like CMyPointSymbol.<BR>   c) Right-click on this class, and choose Implement Interface...<BR>   d) Press OK in the warning dialog, this is telling you that you need an ‘<BR>idl’ file.<p></p></P>
<P >7) Browse Type Libraries<BR>   a) Press Browse...<BR>   b) Find AFCust20.tlb and select it. This is typically in ‘..\Common <BR>Files\ESRI\’<BR>   c) Press Open<p></p></P>
<P >8) Implement Interface<BR>   a) You will see a list of the interfaces supported by AFCustom20.<BR>   b) To implement the point symbol interface, check the box next to <BR>ICustomMarker.<BR>   c) Press OK<p></p></P>
<P >9) Workspace window, ClassView tab<BR>   a) Double-click on the CMyPointSymbol class<BR>   b) This will open the file MyPointSymbol.h in a window.<p></p></P>
<P >10) MyPointSymbol.h<BR>   a) Locate the implementations of SetupDC, ResetDC, and Draw. <p></p></P>
<P >These will look like this:<p></p></P>
<P >STDMETHOD(SetupDC)(LONG hDC, DOUBLE dpi, IDispatch * pBaseSym)<BR>{<BR>return E_NOTIMPL;<BR>}<BR>STDMETHOD(ResetDC)(LONG hDC)<BR>{<BR>return E_NOTIMPL;<BR>}<BR>STDMETHOD(Draw)(LONG hDC, LONG x, LONG y)<BR>{<BR>return E_NOTIMPL;<BR>}<p></p></P>
<P >   b) Add a private member variable. In the workspace window, ClassView Tab, <BR>highlight the CMyPointSymbol class. Right click on the mouse and select ‘Add <BR>member variable’. Enter type as CPen* and name as m_oldPen. This will be use <BR>to hold your old pen <BR>object that is returned from CDC::SelectStockObject<p></p></P>
<P >   c) Add your code to implement your custom point symbol. The following <BR>example is very basic – it simply draws each point symbol as three <BR>concentric squares.<BR>STDMETHOD(SetupDC)(LONG hDC, DOUBLE dpi, IDispatch * pBaseSym)<p></p></P>
<P >{<BR>CDC* pcdc = CDC::FromHandle((HDC)hDC);<BR>m_oldPen =<BR>CPen*)pcdc->SelectStockObject(BLACK_PEN);<BR>return S_OK;<BR>}<BR>STDMETHOD(ResetDC)(LONG hDC)<BR>{<BR>CDC* pcdc = CDC::FromHandle((HDC)hDC);<BR>CPen* temp = pcdc->SelectObject(m_oldPen);<BR>temp->DeleteObject();<BR>return S_OK;<BR>}<BR>STDMETHOD(Draw)(LONG hDC, LONG x, LONG y)<BR>{<BR>CDC* pcdc;<BR>pcdc =<BR>::CDC::FromHandle((HDC)hDC);<BR>CPoint pt;<BR>for (int i= 0; i<10; i+=2)<BR>{<BR>pt.x = x-i;<BR>pt.y = y-i;<BR>pcdc->MoveTo(pt);<BR>pcdc->LineTo(pt.x+(2*i),pt.y);<BR>pcdc->LineTo(pt.x+(2*i),pt.y+(2*i));<BR>pcdc->LineTo(pt.x,pt.y+(2*i));<BR>pcdc->LineTo(pt);<BR>}<BR>return S_OK;<BR>} <BR>11) Build->Set Active Configuration<BR>   a) Select Win32 Release MinDependency<p></p></P>
<P >12) Build->Rebuild All<BR>   b) Build your dll.<p></p></P>
<P>13) You can now use your new COM object within your application</P>
<P>顺便说一句:如果你使用这个自定义组件来显示同一图层下的不同符号,代码还要改一下,加个接口函数,增加几种不同符号的形状。</P>
<P>在界面开发时记住,要显示几种符号,就必须定义几个自定义的CustomSymbol对象。</P><img src="images/post/smile/dvbbs/em08.gif" />
喜欢0 评分0
vivin
路人甲
路人甲
  • 注册日期2005-07-08
  • 发帖数21
  • QQ
  • 铜币219枚
  • 威望0点
  • 贡献值0点
  • 银元0个
1楼#
发布于:2005-08-09 15:05
<P>什么形状的符号都能显示吗?比如英文字母?</P>
举报 回复(0) 喜欢(0)     评分
gis_fnc
路人甲
路人甲
  • 注册日期2004-10-04
  • 发帖数38
  • QQ
  • 铜币268枚
  • 威望0点
  • 贡献值0点
  • 银元0个
2楼#
发布于:2005-09-17 17:44
<P>可以实现任意符号,只要你想得到!</P>
别人笑我太疯癫,我笑他人看不穿,不见五陵豪杰墓,无花无酒锄做田。
举报 回复(0) 喜欢(0)     评分
lewition
路人甲
路人甲
  • 注册日期2004-06-04
  • 发帖数15
  • QQ44842042
  • 铜币145枚
  • 威望0点
  • 贡献值0点
  • 银元0个
3楼#
发布于:2005-09-18 21:22
<P>MO自带的文档里面就有。</P>
<P>偶自己也写过n多回了</P>
举报 回复(0) 喜欢(0)     评分
lewition
路人甲
路人甲
  • 注册日期2004-06-04
  • 发帖数15
  • QQ44842042
  • 铜币145枚
  • 威望0点
  • 贡献值0点
  • 银元0个
4楼#
发布于:2005-09-18 21:25
<DIV class=quote><B>以下是引用<I>vivin</I>在2005-8-9 15:05:22的发言:</B><BR>
<P>什么形状的符号都能显示吗?比如英文字母?</P></DIV>
<P>其实就像是用CDC对象在CView上面画图,
<P>你想画什么,就画什么。</P>
举报 回复(0) 喜欢(0)     评分
游客

返回顶部