|
自己用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_point ptCurrent;
AcGePoint2d center_2d,ocenter_2d;//前一个为待移动的中心点 后一个为当前中心点
acedGetVar("screensize",&viewctr1);//二维点 以像素为单位存储当前视口的大小
screenx=viewctr1.resval.rpoint[X]/2;// 1/2 屏幕 宽
screeny=viewctr1.resval.rpoint[Y]/2;// 1/2 屏幕 高
acedGetVar("viewsize",&viewctr1);//类型:实数 按图形单位存储当前视口的高度。
vhight=viewctr1.resval.rreal;//当前视口的高度 类型:实数
vscal=screeny/vhight*2;//比例:像素/图形单位
vwidth= screenx/vscal ;//当前视口的宽度 类型:实数
//*********************************************************************
acedGetVar("viewctr",&viewctr1);
//类型:三维点 存储当前视口中视图的中心点。该值用 UCS 坐标表示。
ocenter_2d[X]=viewctr1.resval.rpoint[X];
ocenter_2d[Y]=viewctr1.resval.rpoint[Y];
//*************************************************************
ptCurrent[X]=(px-screenx)/vscal+ocenter_2d[X];
ptCurrent[Y]=(screeny-py)/vscal+ocenter_2d[Y];
acedTrans(ptCurrent, &ucs, &wcs, 0, ptCurrent);
center_2d[X]=ptCurrent[X];
center_2d[Y]=ptCurrent[Y];
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
}
|
|