阅读:1255回复:1
谁帮我看一下这个MoveLayer用的对不对~~
<P>想根据图层名得到图层序号,然后根据序号把图层上移/下移一层,可这个函数移出来的结果却乱七八糟的~完全不是想象的样子,是不是我什么地方弄错了?希望有好心人可以给我指正一下</P>
<P>BOOL CPrj5_24View::MyMoveLayer(CString LayerName, BOOL bMoveFlag)<BR>{<BR> ILayerPtr pLayer;<BR> IActiveViewPtr pActiveView(m_ipMap);<BR> long count;<BR> HRESULT hr;<BR> BSTR str;<BR> int i;<BR> //得到层数<BR> m_ipMap->get_LayerCount(;count);<BR> if(count<0)<BR> return FALSE;<BR> else<BR> for(i=0; i < count; i++)<BR> {<BR> //遍历各层,寻找名称为LayerName的图层,i为计数器,用来保存图层的序号<BR> hr=m_ipMap->get_Layer(i,;pLayer);<BR> if(FAILED(hr))<BR> return FALSE;<BR> pLayer->get_Name(;str);<BR> if((CString)str == LayerName)<BR> break;<BR> }<BR> //循环结束时,i值为名称为LayerName的图层序号<BR> m_ipMap->get_Layer(i,;pLayer);<BR> //如果bMoveFlag为true,即上移图层,否则下移</P> <P> if(bMoveFlag)<BR> {<BR> m_ipMap->MoveLayer(pLayer,i+1);<BR> <BR> }<BR> else<BR> {<BR> m_ipMap->MoveLayer(pLayer,i-1);<BR> }<BR> //刷新显示<BR> pActiveView->Refresh();</P> <P> return TRUE;<BR>}</P><img src="images/post/smile/dvbbs/em12.gif" /><img src="images/post/smile/dvbbs/em12.gif" /> |
|
1楼#
发布于:2006-06-07 09:05
<P>找到错在那儿了~get_Layer(index,)中的index~~~</P>
<P>最后添加的图层index最小而不是最大~~把下面的i+1和i-1互换就好了</P> |
|