- 积分
- 10755
- 明经币
- 个
- 注册时间
- 2005-6-8
- 在线时间
- 小时
- 威望
-
- 金钱
- 个
- 贡献
-
- 激情
-
|
- <DllImport("user32.dll")> _
- Public Shared Function GetWindowRect(ByVal hWnd As IntPtr, ByRef lpRect As RECT) As Boolean
- End Function
-
- <StructLayout(LayoutKind.Sequential)> _
- Public Structure RECT
- Public Left As Integer
- Public Top As Integer
- Public Right As Integer
- Public Bottom As Integer
- End Structure
-
- <DllImport("user32.DLL", EntryPoint:="GetTopWindow", SetLastError:=True, CharSet:=CharSet.Unicode, ExactSpelling:=True, CallingConvention:=CallingConvention.StdCall)> _
- Public Shared Function GetTopWindow(ByVal hWnd As IntPtr) As IntPtr
- End Function
-
- <DllImport("user32.dll", SetLastError:=True, CharSet:=CharSet.Auto)> _
- Public Shared Function GetWindow(ByVal hWnd As IntPtr, ByVal uCmd As UInt32) As IntPtr
- End Function
- Public Shared Function GetChildWindows(ByVal ParentWindowsHandle As IntPtr) As List(Of IntPtr)
- Dim rtn As New List(Of IntPtr)
- Try
- Dim Handle As IntPtr = GetTopWindow(ParentWindowsHandle)
- While Handle <> 0
- rtn.Add(Handle)
- Handle = GetWindow(Handle, 2)
- End While
- Catch ex As Exception
- End Try
- Return rtn
- End Function
- <CommandMethod("T1")> _
- Sub T1()
- Dim doc As Document = Autodesk.AutoCAD.ApplicationServices.Application.DocumentManager.MdiActiveDocument
-
- Dim HandleList As List(Of IntPtr) = GetChildWindows(doc.Window.Handle)
- Dim Rect As New RECT() With {.Bottom = 0, .Left = 0, .Right = 0, .Top = 0}
- GetWindowRect(HandleList(1), Rect) 'HandleList里有3个句柄,第2个为绘图区域的句柄
- doc.Editor.WriteMessage(String.Format("绘图区域左上角屏幕坐标为:x={0},y={1},宽度为:{2},高度为:{3}", Rect.Left, Rect.Top, Rect.Right - Rect.Left, Rect.Bottom - Rect.Top))
- End Sub
|
|