本帖最后由 作者 于 2003-10-11 21:06:30 编辑
- Option Explicit
- Private Declare Function SetParent Lib "user32" (ByVal hWndChild As Long, ByVal hWndNewParent As Long) As Long
- Private Declare Function GetParent Lib "user32" (ByVal hwnd As Long) As Long
- Private lHwnd As Long
- Private Sub Form_Load()
-
- On Error GoTo ErrTrap
- Dim acadApp As Object
- Set acadApp = CreateObject("AutoCAD.Application")
- acadApp.Visible = True
- lHwnd = GetParent(GetParent(acadApp.Activedocument.hwnd))
- If lHwnd = 0 Then Exit Sub
- SetParent lHwnd, Form1.hwnd
- Exit Sub
-
- ErrTrap:
- On Error GoTo 0
- End Sub
- Private Sub Form_Unload(Cancel As Integer)
- If lHwnd = 0 Then Exit Sub
- SetParent lHwnd, 0
- End Sub
SetParent第一个参数是子窗口的句柄,现在设为ACAD的句柄了,第二个参数是父窗口的句柄,现在设为VB窗体的句柄。
恢复设置父窗口的句柄为0。也就是重新指定屏幕为其的父窗口。 |