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

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

自己用SDK中pretranslate的例子写了一个移动视图的程序,挺简单的
附上工程中唯一的CPP文件,用它来替代SDK下pretranslate中的CPP文件再编译即可
//////////////////////////////////////////////////////////////
//
// Includes
//
//////////////////////////////////////////////////////////////
#define _AFX_NOFORCE_LIBS // we do not want to link to MFC DLLs or libs
#ifdef _DEBUG
#define WAS_DEBUG
#undef _DEBUG
#endif
#include "afxwin.h"// need this because rxmfcapi.h needs windows header.
#ifdef WAS_DEBUG
#undef WAS_DEBUG
#define _DEBUG
#endif
#include "aced.h"
#include "adslib.h"
#include "rxmfcapi.h"
#include
#include //acedCommand
#include //acedSetVar
#include
#include //resbuf
#include
#include //AcDbViewTableRecord
#include //AcGePoint3d
#include //acdbHostApplicationServices
#include //AcGePoint2d
//////////////////////////////////////////////////////////////
//
// Standard C Test function
//
//////////////////////////////////////////////////////////////
void snapTAB();                   // ARX callbacks
//void zoomExtents();
//void zoomExtents();
void moveview();
BOOL filterTAB(MSG *pMsg);      // hook function for capsing.
// preventing from inserting the same hook twice.
static BOOL TABDone = FALSE;
static long px=0;
static long py=0;
/*static struct resbuf wcs, ucs;*/ // 转换坐标时使用的坐标系统标记
//////////////////////////////////////////////////////////////
//
// Rx interface
//
//////////////////////////////////////////////////////////////
void initApp()
{
////snapTAB();
acedRegCmds->addCommand( "MKEvents",      // Group name
                           "caps",      // Global function name
                           "caps",          // Local function name
                           ACRX_CMD_MODAL,    // Type
                           &snapTAB );         // Function pointer

//acutPrintf( ".OK!\n" );
}
void unloadApp()
{

if (TABDone == TRUE)
      acedRemoveFilterWinMsg(filterTAB);
}
//////////////////////////////////////////////////////////////
//
// Entry point
//
//////////////////////////////////////////////////////////////
extern "C" AcRx::AppRetCode acrxEntryPoint( AcRx::AppMsgCode msg, void* pkt)
{
switch( msg )
{
    case AcRx::kInitAppMsg:
      //initApp();
snapTAB();
acrxUnlockApplication(pkt);
acrxDynamicLinker->registerAppMDIAware(pkt);
acutPrintf( ".OK!\n" );
      break;
    case AcRx::kUnloadAppMsg:
      unloadApp();
      break;
    default:
      break;
}
return AcRx::kRetOK;
}
//////////////////////////////////////////////////////////////
BOOL filterTAB(MSG *pMsg)
{   
    // Change All lowercase to caps!!
    if (pMsg->message == WM_CHAR && pMsg->wParam == 9)//TAB键
{
moveview();
}else if (pMsg->message == WM_MOUSEMOVE || pMsg->message == WM_LBUTTONDOWN
|| pMsg->message == WM_LBUTTONUP){
   px=LOWORD(pMsg->lParam);
   py=HIWORD(pMsg->lParam);
}
    return FALSE; // continue
}
void snapTAB()
{
    if (TABDone == TRUE) // already has the hook??
      return;
    acutPrintf( "Capsing...\n" );
    if (acedRegisterFilterWinMsg(filterTAB) == FALSE)
      acutPrintf("Can't register Windows Msg hook - Lower->upper\n");
    else
      TABDone = TRUE;
}
void moveview()
{
//acutPrintf("移动视口!\n");
//本函数用来移动视口
struct resbuf wcs, ucs; // 转换坐标时使用的坐标系统标记
wcs.restype = RTSHORT; wcs.resval.rint = 0;
ucs.restype = RTSHORT; ucs.resval.rint = 1;
double screenx,screeny,vscal;// 1/2 屏幕 宽高 比例:像素/图形单位
struct resbuf viewctr1 ;
double vhight,vwidth;
ads_pointptCurrent;
AcGePoint2d center_2d,ocenter_2d;//前一个为待移动的中心点 后一个为当前中心点
acedGetVar("screensize",&viewctr1);//二维点 以像素为单位存储当前视口的大小
screenx=viewctr1.resval.rpoint/2;// 1/2 屏幕 宽
screeny=viewctr1.resval.rpoint/2;// 1/2 屏幕 高

acedGetVar("viewsize",&viewctr1);//类型:实数 按图形单位存储当前视口的高度。
vhight=viewctr1.resval.rreal;//当前视口的高度 类型:实数
vscal=screeny/vhight*2;//比例:像素/图形单位
vwidth= screenx/vscal ;//当前视口的宽度 类型:实数
//*********************************************************************
acedGetVar("viewctr",&viewctr1);
//类型:三维点 存储当前视口中视图的中心点。该值用 UCS 坐标表示。
ocenter_2d=viewctr1.resval.rpoint;
ocenter_2d=viewctr1.resval.rpoint;
//*************************************************************
ptCurrent=(px-screenx)/vscal+ocenter_2d;
ptCurrent=(screeny-py)/vscal+ocenter_2d;
acedTrans(ptCurrent,&ucs, &wcs, 0, ptCurrent);
center_2d=ptCurrent;
center_2d=ptCurrent;
AcDbViewTableRecord view ;// view2;
view.setCenterPoint (center_2d);
view.setHeight(vhight);//设定图形单位高
view.setWidth(vwidth);//设定图形单位宽

//acutPrintf("调用!x:%lf Y:%lf\n" ,vwidth,vhight);
acedSetCurrentView (&view, NULL);//NULL
acdbHostApplicationServices()->workingDatabase()->updateExt(TRUE);//TRUE
}

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

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

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


这是工程文件

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

看到下面的文字吗?
附上工程中唯一的CPP文件,用它来替代SDK下pretranslate中的CPP文件再编译即可

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

问题出在引入的库文件上面,可能是有些库文件没引用,我用的的SDK2006,没法调试,我看了一下,你的调试版本和发布版本引入的库不一样。
你用下面的试试
acad.librxapi.libacedapi.libacrx15.libacutil15.lib
acdb15.lib
                                       

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

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

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

acge15.lib
这个呢?
页: [1]
查看完整版本: [原创]用TAB键移动视图的程序