VERSION 5.00
Object = "{F9043C88-F6F2-101A-A3C9-08002B2F49FB}#1.2#0"; "COMDLG32.OCX"
Begin VB.Form Form1 
   Caption         =   "Test Graphic Interface"
   ClientHeight    =   6075
   ClientLeft      =   60
   ClientTop       =   330
   ClientWidth     =   4710
   LinkTopic       =   "Form1"
   ScaleHeight     =   6075
   ScaleWidth      =   4710
   StartUpPosition =   3  'Windows Default
   Begin VB.CommandButton Command14 
      Caption         =   " "
      Height          =   375
      Left            =   240
      TabIndex        =   13
      Top             =   5640
      Width           =   4215
   End
   Begin VB.CommandButton Command13 
      Caption         =   "GetActive"
      Height          =   375
      Left            =   240
      TabIndex        =   12
      Top             =   720
      Width           =   4215
   End
   Begin VB.CommandButton Command12 
      Caption         =   "Unload Graphic"
      Height          =   375
      Left            =   240
      TabIndex        =   11
      Top             =   4080
      Width           =   4215
   End
   Begin VB.CommandButton Command11 
      Caption         =   " "
      Height          =   375
      Left            =   240
      TabIndex        =   10
      Top             =   5160
      Width           =   4215
   End
   Begin VB.CommandButton Command10 
      Caption         =   "Run Library Command"
      Height          =   375
      Left            =   240
      TabIndex        =   9
      Top             =   2160
      Width           =   4215
   End
   Begin MSComDlg.CommonDialog CommonDialog1 
      Left            =   4560
      Top             =   240
      _ExtentX        =   847
      _ExtentY        =   847
      _Version        =   393216
   End
   Begin VB.CommandButton Command9 
      Caption         =   "Unload Library"
      Height          =   375
      Left            =   240
      TabIndex        =   8
      Top             =   2640
      Width           =   4215
   End
   Begin VB.CommandButton Command8 
      Caption         =   "LoadLibrary"
      Height          =   375
      Left            =   240
      TabIndex        =   7
      Top             =   1680
      Width           =   4215
   End
   Begin VB.CommandButton Command7 
      Caption         =   "Close File"
      Height          =   375
      Left            =   240
      TabIndex        =   6
      Top             =   3600
      Width           =   4215
   End
   Begin VB.CommandButton Command6 
      Caption         =   "Save File"
      Height          =   375
      Left            =   240
      TabIndex        =   5
      Top             =   3120
      Width           =   4215
   End
   Begin VB.CommandButton Command5 
      Caption         =   "New File"
      Height          =   375
      Left            =   2400
      TabIndex        =   4
      Top             =   1200
      Width           =   2055
   End
   Begin VB.CommandButton Command4 
      Caption         =   "Load File"
      Height          =   375
      Left            =   240
      TabIndex        =   3
      Top             =   1200
      Width           =   1935
   End
   Begin VB.CommandButton Command3 
      Caption         =   "Quit W/O Unload"
      Height          =   375
      Left            =   240
      TabIndex        =   2
      Top             =   4680
      Width           =   1935
   End
   Begin VB.CommandButton Command2 
      Caption         =   "Quit && Unload "
      Height          =   375
      Left            =   2400
      TabIndex        =   1
      Top             =   4680
      Width           =   2055
   End
   Begin VB.CommandButton Command1 
      Caption         =   "Load Graphic"
      Height          =   375
      Left            =   240
      TabIndex        =   0
      Top             =   240
      Width           =   4215
   End
End
Attribute VB_Name = "Form1"
Attribute VB_GlobalNameSpace = False
Attribute VB_Creatable = False
Attribute VB_PredeclaredId = True
Attribute VB_Exposed = False
Option Explicit

Dim Kompas As Object
Dim documentId As Long ' HANDLE    
Dim libraryId As Long  ' HANDLE  

Private Sub Command1_Click()
  If Kompas Is Nothing Then
    '       
    Set Kompas = CreateObject("KOMPAS.Application.5")
    If Not Kompas Is Nothing Then
      Kompas.Visible = True
    End If
    '     IDispatch,         
  End If
End Sub

'  
Private Sub Command11_Click()
  If Not Kompas Is Nothing Then
    Dim ksDocument2D As Object
    Set ksDocument2D = Kompas.ActiveDocument2D
    If Not ksDocument2D Is Nothing Then
      ksDocument2D.ksCircle 50, 50, 20, 1
      ksDocument2D.ksCircle 50, 50, 50, 2
    End If
    Kompas.ksMessage ""
  End If
End Sub

Private Sub Command12_Click()
If Not Kompas Is Nothing Then
  '   
  Kompas.Quit
  Set Kompas = Nothing
  End If
End Sub

Private Sub Command13_Click()
If Kompas Is Nothing Then
    '       
    Set Kompas = GetObject(, "KOMPAS.Application.5")
    If Not Kompas Is Nothing Then
      Kompas.Visible = True
      Kompas.ActivateControllerAPI
    End If
  End If
End Sub

Private Sub Command2_Click()
  If Not Kompas Is Nothing Then
    '   
    Kompas.Quit
    Set Kompas = Nothing
  End If
  End '  
End Sub

Private Sub Command3_Click()
  If Not Kompas Is Nothing Then
    '   ,    
    '      
    Set Kompas = Nothing
  End If
  End '  
End Sub

Private Sub Command4_Click()
  If Not Kompas Is Nothing Then
    With CommonDialog1
      .DialogTitle = "Open file name"
      .Filter = "(*.frw)|*.frw|(*.cdw)|*.cdw|(*.m3d)|*.m3d|(*.a3d)|*.a3d"
      .InitDir = CurDir
      .FileName = ""
      .Flags = cdlOFNExplorer Or cdlOFNFileMustExist Or cdlOFNPathMustExist
      .ShowOpen
      If .FileName <> "" Then
        '    
        '   -   
        '        " . ?"   
        '   -   IDispatch,         
        ' -  HANDLE  
        ' documentId = Kompas.OpenAutoDocument(.FileName, True, Me)
        Dim docType As Integer
        docType = Kompas.ksGetDocumentTypeByName(.FileName)
        Select Case docType
          Case lt_DocPart3D, lt_DocAssemble3D
            Dim ksDocument3D As Object
            Set ksDocument3D = Kompas.Document3D
            ksDocument3D.Open .FileName, 0
          Case lt_DocSheetStandart, lt_DocFragment
            Dim ksDocument2D As Object
            Set ksDocument2D = Kompas.Document2D
            ksDocument2D.ksOpenDocument .FileName, False
          Case lt_DocSpc, lt_DocSpcUser
            Dim ksSpcDocument As Object
            Set ksSpcDocument = Kompas.SpcDocument
            ksSpcDocument.ksOpenDocument .FileName, False
          Case lt_DocTxtStandart
            Dim ksDocumentTxt As Object
            ksDocumentTxt = Kompas.DocumentTxt
            ksDocumentTxt.ksOpenDocument .FileName, False
        End Select
        Dim err As Integer
        err = Kompas.ksReturnResult
        If err Then
          Kompas.MassageBoxResult
          Kompas.ResultNULL
        End If
      End If
    End With
  End If
End Sub

Private Sub Command5_Click()
  If Not Kompas Is Nothing Then
    '   
    '   -   
    '   0 -  
    '   1 - 
    '   2 -  
    '   3 - 
    '   4 - 3D-
    '        " . ?"   
    '   -   IDispatch,         
    ' -  HANDLE  
    ' documentId = Kompas.NewAutoDocument(0, True, Me)
    Dim ksDocument2D As Object
    Set ksDocument2D = Kompas.Document2D
    If Not ksDocument2D Is Nothing Then
      Dim ksDocumentParam As Object
      Set ksDocumentParam = Kompas.GetParamStruct(ko_DocumentParam)
      If Not ksDocumentParam Is Nothing Then
        ksDocumentParam.Init
        ksDocumentParam.Type = lt_DocSheetStandart
        ksDocument2D.ksCreateDocument ksDocumentParam
      End If
    End If
  End If
End Sub

Private Sub Command6_Click()
  If Not Kompas Is Nothing Then
    '  ,   
    Dim ksDocument2D As Object
    Set ksDocument2D = Kompas.ActiveDocument2D
    If Not ksDocument2D Is Nothing Then
      ksDocument2D.ksSaveDocument ""
    End If
  End If
End Sub

Private Sub Command7_Click()
  If Not Kompas Is Nothing Then
    '  ,   
    Dim ksDocument2D As Object
    Set ksDocument2D = Kompas.ActiveDocument2D
    If Not ksDocument2D Is Nothing Then
      ksDocument2D.ksCloseDocument
    End If
  End If
End Sub

Private Sub Command8_Click()
  If Not Kompas Is Nothing Then
    With CommonDialog1
      .DialogTitle = "Open library name"
      .Filter = "(*.rtw)|*.rtw"
      .InitDir = CurDir
      .FileName = ""
      .Flags = cdlOFNExplorer Or cdlOFNFileMustExist Or cdlOFNPathMustExist
      .ShowOpen
      If .FileName <> "" Then
        '  
        ' -  HANDLE  
        libraryId = Kompas.ksAttachKompasLibrary(.FileName)
      End If
    End With
  End If
End Sub

Private Sub Command9_Click()
  If Not Kompas Is Nothing Then
    '  
    Kompas.ksDetachKompasLibrary libraryId
  End If
End Sub

Private Sub Command10_Click()
  If Not Kompas Is Nothing Then
    '     
    '   - HANDLE 
    '   -   
    Kompas.ksExecuteKompasLibraryCommand libraryId, 1
  End If
End Sub

