zhang007 发表于 2007-7-3 09:45:00

[原创]用TAB键移动视图的程序

<p>自己用SDK中pretranslate的例子写了一个移动视图的程序,挺简单的</p><p>附上工程中唯一的CPP文件,用它来替代SDK下pretranslate中的CPP文件再编译即可</p><p>//////////////////////////////////////////////////////////////<br/>//<br/>// Includes<br/>//<br/>//////////////////////////////////////////////////////////////<br/>#define _AFX_NOFORCE_LIBS // we do not want to link to MFC DLLs or libs<br/>#ifdef _DEBUG<br/>#define WAS_DEBUG<br/>#undef _DEBUG<br/>#endif</p><p>#include "afxwin.h"&nbsp; // need this because rxmfcapi.h needs windows header. </p><p>#ifdef WAS_DEBUG<br/>#undef WAS_DEBUG<br/>#define _DEBUG<br/>#endif</p><p>#include "aced.h"<br/>#include "adslib.h"<br/>#include "rxmfcapi.h"<br/>#include &lt;windef.h&gt;<br/>#include&lt;accmd.h&gt; //acedCommand<br/>#include&lt;acedads.h&gt; //acedSetVar<br/>#include&lt;adscodes.h&gt;<br/>#include&lt;adsdef.h&gt; //resbuf<br/>#include &lt;rxmfcapi.h&gt;<br/>#include&lt;dbsymtb.h&gt; //AcDbViewTableRecord<br/>#include&lt;gepnt3d.h&gt; //AcGePoint3d<br/>#include&lt;dbapserv.h&gt; //acdbHostApplicationServices<br/>#include&lt;gepnt2d.h&gt; //AcGePoint2d</p><p><br/>//////////////////////////////////////////////////////////////<br/>//<br/>// Standard C Test function<br/>//<br/>//////////////////////////////////////////////////////////////</p><p>void snapTAB();&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; // ARX callbacks <br/>//void zoomExtents();<br/>//void zoomExtents();<br/>void moveview();<br/>BOOL filterTAB(MSG *pMsg);&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; // hook function for capsing.</p><p><br/>// preventing from inserting the same hook twice.<br/>static BOOL TABDone = FALSE;<br/>static long px=0;<br/>static long py=0;</p><p>/*static struct resbuf wcs, ucs;*/ // 转换坐标时使用的坐标系统标记<br/>//////////////////////////////////////////////////////////////<br/>//<br/>// Rx interface<br/>//<br/>//////////////////////////////////////////////////////////////</p><p><br/>void initApp()<br/>{<br/>////snapTAB();<br/>&nbsp; acedRegCmds-&gt;addCommand( "MKEvents",&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; // Group name <br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; "caps",&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; // Global function name<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; "caps",&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; // Local function name<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; ACRX_CMD_MODAL,&nbsp;&nbsp;&nbsp; // Type<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &amp;snapTAB );&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; // Function pointer<br/>&nbsp; <br/>&nbsp; //acutPrintf( ".OK!\n" );</p><p>}</p><p>void unloadApp()<br/>{<br/>&nbsp; <br/>&nbsp; if (TABDone == TRUE)<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; acedRemoveFilterWinMsg(filterTAB); </p><p><br/>}</p><p><br/>//////////////////////////////////////////////////////////////<br/>//<br/>// Entry point<br/>//<br/>//////////////////////////////////////////////////////////////</p><p>extern "C" AcRx::AppRetCode acrxEntryPoint( AcRx::AppMsgCode msg, void* pkt)<br/>{<br/>&nbsp; switch( msg ) <br/>&nbsp; {<br/>&nbsp;&nbsp;&nbsp; case AcRx::kInitAppMsg: <br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; //initApp();<br/>&nbsp;&nbsp;snapTAB();<br/>&nbsp;&nbsp;acrxUnlockApplication(pkt);<br/>&nbsp;&nbsp;acrxDynamicLinker-&gt;registerAppMDIAware(pkt);<br/>&nbsp;&nbsp;acutPrintf( ".OK!\n" );<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; break;<br/>&nbsp;&nbsp;&nbsp; case AcRx::kUnloadAppMsg: <br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; unloadApp(); <br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; break;<br/>&nbsp;&nbsp;&nbsp; default:<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; break;<br/>&nbsp; }<br/>&nbsp; return AcRx::kRetOK; <br/>}</p><p></p><p>//////////////////////////////////////////////////////////////</p><p>BOOL filterTAB(MSG *pMsg)<br/>{&nbsp;&nbsp;&nbsp; <br/>&nbsp;&nbsp;&nbsp; // Change All lowercase to caps!!<br/>&nbsp;&nbsp;&nbsp; if (pMsg-&gt;message == WM_CHAR &amp;&amp; pMsg-&gt;wParam == 9)//TAB键<br/>&nbsp;{ </p><p>&nbsp;moveview();</p><p>&nbsp;}else if (pMsg-&gt;message == WM_MOUSEMOVE || pMsg-&gt;message == WM_LBUTTONDOWN<br/>&nbsp;&nbsp;|| pMsg-&gt;message == WM_LBUTTONUP){<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;px=LOWORD(pMsg-&gt;lParam);<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;py=HIWORD(pMsg-&gt;lParam);<br/>&nbsp;&nbsp;}<br/>&nbsp;&nbsp;&nbsp; return FALSE; // continue<br/>}</p><p></p><p><br/>void snapTAB()<br/>{<br/>&nbsp;&nbsp;&nbsp; if (TABDone == TRUE) // already has the hook??<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; return;<br/>&nbsp;&nbsp;&nbsp; acutPrintf( "Capsing...\n" );<br/>&nbsp;&nbsp;&nbsp; if (acedRegisterFilterWinMsg(filterTAB) == FALSE)<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; acutPrintf("Can't register Windows Msg hook - Lower-&gt;upper\n");<br/>&nbsp;&nbsp;&nbsp; else<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; TABDone = TRUE;<br/>}</p><p>void moveview()<br/>{<br/>//acutPrintf("移动视口!\n");<br/>//本函数用来移动视口<br/>&nbsp;struct resbuf wcs, ucs; // 转换坐标时使用的坐标系统标记<br/>&nbsp;wcs.restype = RTSHORT; wcs.resval.rint = 0; <br/>&nbsp;ucs.restype = RTSHORT; ucs.resval.rint = 1; <br/>&nbsp;double screenx,screeny,vscal;// 1/2 屏幕 宽高 比例:像素/图形单位<br/>&nbsp;struct resbuf viewctr1 ;<br/>&nbsp;double vhight,vwidth;<br/>&nbsp;ads_point&nbsp; ptCurrent;</p><p>&nbsp;AcGePoint2d center_2d,ocenter_2d;//前一个为待移动的中心点 后一个为当前中心点<br/>&nbsp;acedGetVar("screensize",&amp;viewctr1);//二维点 以像素为单位存储当前视口的大小<br/>&nbsp;screenx=viewctr1.resval.rpoint/2;// 1/2 屏幕 宽<br/>&nbsp;screeny=viewctr1.resval.rpoint/2;// 1/2 屏幕 高<br/>&nbsp;<br/>&nbsp;acedGetVar("viewsize",&amp;viewctr1);//类型:实数 按图形单位存储当前视口的高度。<br/>&nbsp;vhight=viewctr1.resval.rreal;//当前视口的高度 类型:实数<br/>&nbsp;vscal=screeny/vhight*2;//比例:像素/图形单位<br/>&nbsp;vwidth= screenx/vscal ;//当前视口的宽度 类型:实数</p><p>&nbsp;//*********************************************************************<br/>&nbsp;acedGetVar("viewctr",&amp;viewctr1);<br/>&nbsp;//类型:三维点 存储当前视口中视图的中心点。该值用 UCS 坐标表示。<br/>&nbsp;ocenter_2d=viewctr1.resval.rpoint;<br/>&nbsp;ocenter_2d=viewctr1.resval.rpoint;<br/>&nbsp;//*************************************************************<br/>&nbsp;ptCurrent=(px-screenx)/vscal+ocenter_2d;<br/>&nbsp;ptCurrent=(screeny-py)/vscal+ocenter_2d;<br/>&nbsp;acedTrans(ptCurrent,&nbsp; &amp;ucs, &amp;wcs, 0, ptCurrent);<br/>&nbsp;center_2d=ptCurrent;<br/>&nbsp;center_2d=ptCurrent;</p><p>&nbsp;AcDbViewTableRecord view ;// view2;<br/>&nbsp;view.setCenterPoint (center_2d);</p><p>&nbsp;view.setHeight(vhight);//设定图形单位高<br/>&nbsp;view.setWidth(vwidth);//设定图形单位宽<br/>&nbsp;<br/>&nbsp;//acutPrintf("调用!x:%lf Y:%lf\n" ,vwidth,vhight);<br/>&nbsp;acedSetCurrentView (&amp;view, NULL);//NULL</p><p>&nbsp;acdbHostApplicationServices()-&gt;workingDatabase()-&gt;updateExt(TRUE);//TRUE<br/>}</p>

cnks 发表于 2008-5-12 18:29:00

<p>我这里出现很多错误</p><p>--------------------Configuration: pretranslate - Win32 Debug--------------------<br/>Linking...<br/>&nbsp;&nbsp; Creating library .\Debug/pretranslate.lib and object .\Debug/pretranslate.exp<br/>LINK : warning LNK4098: defaultlib "msvcrt.lib" conflicts with use of other libs; use /NODEFAULTLIB:library<br/>rxtemplt.obj : error LNK2001: unresolved external symbol "public: virtual __thiscall AcDbViewTableRecord::~AcDbViewTableRecord(void)" (<a href="mailto:??1AcDbViewTableRecord@@UAE@XZ">??1AcDbViewTableRecord@@UAE@XZ</a>)<br/>rxtemplt.obj : error LNK2001: unresolved external symbol "public: enum Acad::ErrorStatus __thiscall AcDbDatabase::updateExt(bool)" (<a href="mailto:?updateExt@AcDbDatabase@@QAE?AW4ErrorStatus@Acad@@_N@Z">?updateExt@AcDbDatabase@@QAE?AW4ErrorStatus@Acad@@_N@Z</a>)<br/>rxtemplt.obj : error LNK2001: unresolved external symbol "public: void __thiscall AcDbAbstractViewTableRecord::setWidth(double)" (<a href="mailto:?setWidth@AcDbAbstractViewTableRecord@@QAEXN@Z">?setWidth@AcDbAbstractViewTableRecord@@QAEXN@Z</a>)<br/>rxtemplt.obj : error LNK2001: unresolved external symbol "public: void __thiscall AcDbAbstractViewTableRecord::setHeight(double)" (<a href="mailto:?setHeight@AcDbAbstractViewTableRecord@@QAEXN@Z">?setHeight@AcDbAbstractViewTableRecord@@QAEXN@Z</a>)<br/>rxtemplt.obj : error LNK2001: unresolved external symbol "public: void __thiscall AcDbAbstractViewTableRecord::setCenterPoint(class AcGePoint2d const &amp;)" (<a href="mailto:?setCenterPoint@AcDbAbstractViewTableRecord@@QAEXABVAcGePoint2d@@@Z">?setCenterPoint@AcDbAbstractViewTableRecord@@QAEXABVAcGePoint2d@@@Z</a>)<br/>rxtemplt.obj : error LNK2001: unresolved external symbol "public: __thiscall AcDbViewTableRecord::AcDbViewTableRecord(void)" (<a href="mailto:??0AcDbViewTableRecord@@QAE@XZ">??0AcDbViewTableRecord@@QAE@XZ</a>)<br/>.\pretranslate.arx : fatal error LNK1120: 6 unresolved externals<br/>Error executing link.exe.</p><p>pretranslate.arx - 7 error(s), 1 warning(s)</p>

cnks 发表于 2008-5-12 18:30:00

<p></p><p>这是工程文件</p>

zhang007 发表于 2008-5-13 08:51:00

<p><font style="BACKGROUND-COLOR: #eeee11;"><strong>看到下面的文字吗?</strong></font></p><p><font style="BACKGROUND-COLOR: #eeee11;"><strong>附上工程中唯一的CPP文件,用它来替代SDK下pretranslate中的CPP文件再编译即可</strong></font></p>

zhang007 发表于 2008-5-13 09:28:00

<p>问题出在引入的库文件上面,可能是有些库文件没引用,我用的的SDK2006,没法调试,我看了一下,你的调试版本和发布版本引入的库不一样。</p><p>你用下面的试试 </p><p><table cellspacing="0" cellpadding="0" width="72" border="0" style="WIDTH: 54pt; BORDER-COLLAPSE: collapse;"><colgroup><col width="72" style="WIDTH: 54pt;"></col></colgroup><tbody><tr height="19" style="HEIGHT: 14.25pt;"><td width="72" height="19" style="BORDER-RIGHT: #ece9d8; BORDER-TOP: #ece9d8; BORDER-LEFT: #ece9d8; WIDTH: 54pt; BORDER-BOTTOM: #ece9d8; HEIGHT: 14.25pt; BACKGROUND-COLOR: transparent;">acad.lib</td></tr><tr height="19" style="HEIGHT: 14.25pt;"><td height="19" style="BORDER-RIGHT: #ece9d8; BORDER-TOP: #ece9d8; BORDER-LEFT: #ece9d8; BORDER-BOTTOM: #ece9d8; HEIGHT: 14.25pt; BACKGROUND-COLOR: transparent;">rxapi.lib</td></tr><tr height="19" style="HEIGHT: 14.25pt;"><td height="19" style="BORDER-RIGHT: #ece9d8; BORDER-TOP: #ece9d8; BORDER-LEFT: #ece9d8; BORDER-BOTTOM: #ece9d8; HEIGHT: 14.25pt; BACKGROUND-COLOR: transparent;">acedapi.lib</td></tr><tr height="19" style="HEIGHT: 14.25pt;"><td height="19" style="BORDER-RIGHT: #ece9d8; BORDER-TOP: #ece9d8; BORDER-LEFT: #ece9d8; BORDER-BOTTOM: #ece9d8; HEIGHT: 14.25pt; BACKGROUND-COLOR: transparent;">acrx15.lib</td></tr><tr height="19" style="HEIGHT: 14.25pt;"><td height="19" style="BORDER-RIGHT: #ece9d8; BORDER-TOP: #ece9d8; BORDER-LEFT: #ece9d8; BORDER-BOTTOM: #ece9d8; HEIGHT: 14.25pt; BACKGROUND-COLOR: transparent;">acutil15.lib<br/><font color="#ff0000">acdb15.lib</font>
                                        </td></tr></tbody></table></p>

cnks 发表于 2008-5-13 09:54:00

<p>还是有很多错误:</p><p>--------------------Configuration: pretranslate - Win32 Debug--------------------<br/>Linking...<br/>&nbsp;&nbsp; Creating library .\Debug/pretranslate.lib and object .\Debug/pretranslate.exp<br/>rxtemplt.obj : error LNK2001: unresolved external symbol "__declspec(dllimport) public: double &amp; __thiscall AcGePoint2d::operator[](unsigned int)" (<a href="mailto:__imp_??AAcGePoint2d@@QAEAANI@Z">__imp_??AAcGePoint2d@@QAEAANI@Z</a>)<br/>rxtemplt.obj : error LNK2001: unresolved external symbol "__declspec(dllimport) public: __thiscall AcGePoint2d::AcGePoint2d(void)" (<a href="mailto:__imp_??0AcGePoint2d@@QAE@XZ">__imp_??0AcGePoint2d@@QAE@XZ</a>)<br/>.\pretranslate.arx : fatal error LNK1120: 2 unresolved externals<br/>Error executing link.exe.</p>

zhang007 发表于 2008-5-13 16:33:00

<p><font color="#ff0000">acge15.lib</font><br/>这个呢?</p>
页: [1]
查看完整版本: [原创]用TAB键移动视图的程序