guohq 发表于 2016-1-22 15:02:00

怎样获取CAD绘图区域左上角的屏幕坐标

通过 PointToScreen 只能获取某点相对于绘图区域 左上角屏幕坐标,要想获取此点在屏幕上的绝对坐标,还必须获取左上角的屏幕坐标。



xgr 发表于 2019-5-30 13:54:00


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();
}
}
}

wz0406 发表于 2018-7-30 20:37:00

解决我一个难题,CAD截图

kozmosovia 发表于 2016-1-22 21:24:00

读取系统变量"VIEWSIZE" "SCREENSIZE" "VIEWCTR"计算

guohq 发表于 2016-1-22 21:39:00

此方法不行

知行ooo李肖坪 发表于 2016-1-23 07:28:00

同步学习中…………谢谢

ivde 发表于 2016-1-23 21:56:00


CPoint pt(0,0);
acedDwgPoint ptOut;
acedCoordFromPixelToWorld(pt,ptOut);

guohq 发表于 2016-1-24 22:43:00


不好意思 ,我在.net 中没有找到此方法呢acedCoordFromPixelToWorld,能说详细点不?谢谢!!

guohq 发表于 2016-1-24 23:32:00


private static extern bool acedCoordFromWorldToPixel(int viewportNumber, ref Point3d worldPt, out Point pixel);
经查证,acedCoordFromPixelToWorld   与 Editor.PointToScreen 方法得到的结果一样。

鱼与熊掌 发表于 2016-1-25 14:39:00

复制代码
页: [1] 2
查看完整版本: 怎样获取CAD绘图区域左上角的屏幕坐标