怎样获取CAD绘图区域左上角的屏幕坐标
通过 PointToScreen 只能获取某点相对于绘图区域 左上角屏幕坐标,要想获取此点在屏幕上的绝对坐标,还必须获取左上角的屏幕坐标。using System;
using System.Runtime.InteropServices;
using System.Windows.Forms;
using Application = Autodesk.AutoCAD.ApplicationServices.Core.Application;
namespace 取得CAD绘图区域屏幕坐标
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
[DllImport("user32.DLL", EntryPoint = "GetTopWindow", SetLastError = true, CharSet = CharSet.Unicode,
ExactSpelling = true, CallingConvention = CallingConvention.StdCall)]
public static extern IntPtr GetTopWindow(IntPtr hWnd);
public static extern IntPtr GetWindow(IntPtr hWnd, UInt32 uCmd);
static extern bool GetWindowRect(IntPtr hWnd, ref Rect lpRect);
public struct Rect
{
public int Left; //最左坐标
public int Top; //最上坐标
public int Right; //最右坐标
public int Bottom; //最下坐标
}
private void button1_Click(object sender, EventArgs e)
{
Rect rect = new Rect();
IntPtr intPtr1 = GetTopWindow(Application.DocumentManager.MdiActiveDocument.Window.Handle);
textBox1.Text = intPtr1.ToString();
IntPtr intPtr2 = GetWindow(intPtr1, 2);
GetWindowRect(intPtr2, ref rect);
textBox2.Text = rect.Left.ToString();
textBox3.Text = rect.Top.ToString();
textBox4.Text = (rect.Right - rect.Left).ToString();
textBox5.Text = (rect.Bottom - rect.Top).ToString();
}
}
}
解决我一个难题,CAD截图
读取系统变量"VIEWSIZE" "SCREENSIZE" "VIEWCTR"计算 此方法不行 同步学习中…………谢谢
CPoint pt(0,0);
acedDwgPoint ptOut;
acedCoordFromPixelToWorld(pt,ptOut);
不好意思 ,我在.net 中没有找到此方法呢acedCoordFromPixelToWorld,能说详细点不?谢谢!!
private static extern bool acedCoordFromWorldToPixel(int viewportNumber, ref Point3d worldPt, out Point pixel);
经查证,acedCoordFromPixelToWorld 与 Editor.PointToScreen 方法得到的结果一样。 复制代码
页:
[1]
2