[每日一码] 不通过事件获得鼠标光标的坐标
AutoCAD API 提供了 AcEdInputPointManager。输入点监视器(Inputpointmonitor )能够监视用户的任何输入,包括鼠标。API还能够监视WINDOWS的消息,有时你需要不通过事件来获取鼠标的位置,下面代码是一个示例,获得当前鼠标光标的位置并转换到AutoCAD的坐标系(考虑了UCS).static void getMousePosition(void)
{
//get cursor position by Windows API
POINT CursorPos;
GetCursorPos(&CursorPos);
acedGetAcadDwgView()->ScreenToClient(&CursorPos);
//Returns the viewport number based on
// Windows client coordinates.
int vpNum = acedGetWinNum(CursorPos.x, CursorPos.y);
//Converts coordinates from AutoCAD
// drawing window
//to current active viewport's coordinates
acedDwgPoint acPt, newPt;
acedCoordFromPixelToWorld(vpNum,
CursorPos,
acPt);
double worldPoint;
acedCoordFromPixelToWorld(vpNum,
CPoint(CursorPos.x,
CursorPos.y) ,
worldPoint);
acutPrintf(
L"\nModel Position (no UCS): [%f, %f, %f]\n",
worldPoint,
worldPoint,
worldPoint);
//Take UCS translation in consideration
AcGeMatrix3d mat;
acedGetCurrentUCS(mat);
AcGePoint3d ptUcs(worldPoint,
worldPoint,
worldPoint);
ptUcs.transformBy(mat.inverse());
resbuf wcs;
wcs.restype = RTSHORT;
wcs.resval.rint = 0;
resbuf dcs;
dcs.restype = RTSHORT;
dcs.resval.rint = 2;
//translate the WCS coordinate to UCS
double result;
acedTrans(asDblArray(ptUcs),
&wcs,
&dcs,
0,
result);
acutPrintf(
L"\nModel Position (with UCS): [%f, %f, %f]\n",
result, result, result);
}
页:
[1]