明经CAD社区

 找回密码
 注册

QQ登录

只需一步,快速开始

搜索
查看: 1919|回复: 1

[图形系统] 怎样获取CAD绘图区域左上角的屏幕坐标(代码篇)

  [复制链接]
发表于 2016-2-4 17:54:14 | 显示全部楼层 |阅读模式
  1. <DllImport("user32.dll")> _
  2.     Public Shared Function GetWindowRect(ByVal hWnd As IntPtr, ByRef lpRect As RECT) As Boolean

  3.     End Function

  4.    
  5.     <StructLayout(LayoutKind.Sequential)> _
  6.     Public Structure RECT
  7.         Public Left As Integer
  8.         Public Top As Integer
  9.         Public Right As Integer
  10.         Public Bottom As Integer
  11.     End Structure



  12.     <DllImport("user32.DLL", EntryPoint:="GetTopWindow", SetLastError:=True, CharSet:=CharSet.Unicode, ExactSpelling:=True, CallingConvention:=CallingConvention.StdCall)> _
  13.     Public Shared Function GetTopWindow(ByVal hWnd As IntPtr) As IntPtr

  14.     End Function


  15.     <DllImport("user32.dll", SetLastError:=True, CharSet:=CharSet.Auto)> _
  16.     Public Shared Function GetWindow(ByVal hWnd As IntPtr, ByVal uCmd As UInt32) As IntPtr
  17.     End Function



  18.     Public Shared Function GetChildWindows(ByVal ParentWindowsHandle As IntPtr) As List(Of IntPtr)
  19.         Dim rtn As New List(Of IntPtr)
  20.         Try
  21.             Dim Handle As IntPtr = GetTopWindow(ParentWindowsHandle)
  22.             While Handle <> 0
  23.                 rtn.Add(Handle)
  24.                 Handle = GetWindow(Handle, 2)
  25.             End While
  26.         Catch ex As Exception

  27.         End Try
  28.         Return rtn
  29.     End Function

  30.     <CommandMethod("T1")> _
  31.     Sub T1()
  32.         Dim doc As Document = Autodesk.AutoCAD.ApplicationServices.Application.DocumentManager.MdiActiveDocument
  33.    
  34.         Dim HandleList As List(Of IntPtr) = GetChildWindows(doc.Window.Handle)
  35.         Dim Rect As New RECT() With {.Bottom = 0, .Left = 0, .Right = 0, .Top = 0}
  36.         GetWindowRect(HandleList(1), Rect) 'HandleList里有3个句柄,第2个为绘图区域的句柄
  37.         doc.Editor.WriteMessage(String.Format("绘图区域左上角屏幕坐标为:x={0},y={1},宽度为:{2},高度为:{3}", Rect.Left, Rect.Top, Rect.Right - Rect.Left, Rect.Bottom - Rect.Top))

  38.     End Sub
发表于 2016-2-5 08:23:08 | 显示全部楼层
同步学习一下………………谢谢
您需要登录后才可以回帖 登录 | 注册

本版积分规则

小黑屋|手机版|CAD论坛|CAD教程|CAD下载|联系我们|关于明经|明经通道 ( 粤ICP备05003914号 )  
©2000-2023 明经通道 版权所有 本站代码,在未取得本站及作者授权的情况下,不得用于商业用途

GMT+8, 2024-11-22 21:45 , Processed in 0.169018 second(s), 22 queries , Gzip On.

Powered by Discuz! X3.4

Copyright © 2001-2021, Tencent Cloud.

快速回复 返回顶部 返回列表