求助!cad嵌入vb问题!
<P>求助!我看了伊凡版主以前的一个帖子,是关于怎样把cad窗体嵌入vb程序中,我也照着做了一个,实现了嵌入,并且cad窗体能随着vb窗体的拖动改变大小。但是问题是嵌入后无法用vb控制cad画图,不知道问题在哪,希望高手帮帮忙,十分感谢!</P><P>这是关于上面问题的一个程序段,是想在嵌入后画条直线,但是不行:</P>
<P>Private Declare Function SetParent Lib "user32" (ByVal hWndChild As Long, ByVal hWndNewParent As Long) As Long<BR>Private Declare Function GetParent Lib "user32" (ByVal hwnd As Long) As Long<BR>Private Declare Function GetWindowRect Lib "user32" (ByVal hwnd As Long, lpRect As RECT) As Long<BR>Private Declare Function SetWindowPos Lib "user32" (ByVal hwnd As Long, ByVal hWndInsertAfter As Long, ByVal x As Long, ByVal y As Long, ByVal cx As Long, ByVal cy As Long, ByVal wFlags As Long) As Long</P>
<P>Private Type RECT<BR> Left As Long<BR> Top As Long<BR> Right As Long<BR> Bottom As Long<BR>End Type</P>
<P>Public acadApp As Object 'The AutoCAD application object<BR>Public acadDoc As Object 'The AutoCAD document (drawing) object<BR>Public moSpace As Object 'The model space object collection<BR>Public paSpace As Object 'The paper space object collection<BR>Public AppLayer As Object '应用程序使用的层<BR>Public acadDocname As String<BR>Private acadApp As Object<BR>Private lHwnd As Long '保存ACAD应用程序的窗口句柄<BR>Private lState As Long '保存ACAD的初始窗口状态<BR>Private r As RECT '保存ACAD的初始窗口位置</P>
<P>Private Sub Form_Load()<BR> On Error GoTo ErrTrap<BR> Set acadApp = GetObject(, "AutoCAD.Application")<BR> acadApp.Visible = True<BR> lHwnd = GetParent(GetParent(acadApp.Activedocument.hwnd))<BR> If lHwnd = 0 Then Exit Sub<BR> lState = acadApp.WindowState<BR> acadApp.WindowState = 1 '设置ACAD的窗口状态为默认,用于保存窗口位置。<BR> GetWindowRect lHwnd, r<BR> SetParent lHwnd, Form1.hwnd<BR> Form1.ScaleMode = vbPixels '将VB窗体默认的缇单位改为以像素为单位。<BR> SetWindowPos lHwnd, 0, Form1.ScaleLeft, Form1.ScaleTop, Form1.ScaleWidth, Form1.ScaleHeight, 0<BR> Exit Sub<BR>ErrTrap:<BR> On Error GoTo 0<BR>End Sub</P>
<P>Private Sub Form_Resize()<BR> SetWindowPos lHwnd, 0, Form1.ScaleLeft + 100, Form1.ScaleTop, Form1.ScaleWidth - 100, Form1.ScaleHeight, 0<BR>End Sub</P>
<P>Private Sub Form_Unload(Cancel As Integer)<BR> If lHwnd = 0 Then Exit Sub<BR> SetParent lHwnd, 0<BR> SetWindowPos lHwnd, 0, r.Left, r.Top, r.Right - r.Left, r.Bottom - r.Top, 0<BR> acadApp.WindowState = lState<BR> Set acadApp = Nothing<BR>End Sub</P>
<P>Private Sub Command1_Click()<BR>Call lin<BR>End Sub</P>
<P>Private Sub lin()<BR>Dim lineObj As Object<BR> Dim startPoint(0 To 2) As Double<BR> Dim endPoint(0 To 2) As Double<BR> ' Define the start and end points for the line<BR> startPoint(0) = 1#: startPoint(1) = 1#: startPoint(2) = 0#<BR> endPoint(0) = 500#: endPoint(1) = 500#: endPoint(2) = 0#<BR> ' Create the line in model space<BR> Set lineObj = moSpace.AddLine(startPoint, endPoint)<BR>acadDoc.Application.ZoomAll<BR>End Sub</P>
<P>谢谢!</P>
页:
[1]