Imports Microsoft
Imports System.Windows.Forms
Imports System.Drawing
Imports System.Drawing.Text
Imports System.Drawing.Drawing2D
Imports SolidWorks.Interop
Imports SolidWorks.Interop.swconst
Imports SwDocumentMgr.SwDmDocumentType
Imports SwDocumentMgr.SwDmDocumentOpenError
Imports System
Imports System.IO
Imports System.Text
Imports System.IO.File


Public Class Mainform
    'swXxxx declared in SWX.VB

    Public FormTitle As String = "SWX-Anwendung"
    Public Const Pi = 3.1415926535898



    Sub GetActiveSWXDocument()
        If Not ConnectToSW(swApp) Then End
        If Not ConnectToModelDoc(swModel, swApp) Then End
    End Sub

    Private Sub RotateText(ByVal lbl As Control, _
      ByVal e As System.Windows.Forms.PaintEventArgs, _
      ByVal clr As Color)
        Try
            Dim fnt As New Font(lbl.Font, FontStyle.Bold)
            Dim sf As New StringFormat

            sf.FormatFlags = StringFormatFlags.DirectionVertical
            With e
                .Graphics.TextRenderingHint = TextRenderingHint.AntiAlias
                .Graphics.FillRectangle(New SolidBrush(lbl.BackColor), lbl.DisplayRectangle)
                .Graphics.DrawString(lbl.Text, fnt, New SolidBrush(clr), 1, 10, sf)
            End With
            fnt = Nothing
            sf = Nothing

        Catch ex As Exception
            'ExceptionMessage(ex)
        End Try
    End Sub

    Private Sub lblVersion_Paint1(ByVal sender As Object, ByVal e As System.Windows.Forms.PaintEventArgs) Handles lblVersion.Paint
        Call RotateText(lblVersion, e, Color.Green)
    End Sub

    Private Sub Mainform_KeyUp(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyEventArgs) Handles Me.KeyUp
        If e.Control And e.KeyCode = Keys.S Then
            'Steuerung-S gedrückt
        Else
            Select Case e.KeyCode.ToString
                Case "F1"
                Case "F5"
                Case "Return"
                    myBtnOk_Click(Me, e)
                Case "Escape"
                    myBtnExit_Click(Me, e)
                Case Else
                    'Keine Aktion
            End Select
        End If
    End Sub

    Sub Getregistry()

    End Sub

    Private Sub Mainform_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        Dim UIculture As String = My.Application.UICulture.Name
        Dim culture As String = My.Application.Culture.Name
        Me.Text = "AL-KO: " & FormTitle & _
                  " - Version " & System.Reflection.Assembly.GetExecutingAssembly().GetName().Version.ToString
        Getregistry()

        'GetActiveSWXDocument()
        If Not ConnectToSW(swApp) Then End
        If Not ConnectToModelDoc(swModel, swApp) Then End

        MsgBox("Hallo")
        lblPartname.Text = swPartname
        lblDrawingname.Text = swDrwname
        lblViewname.Text = swViewname

        ' Einblenden
        FensAnim(Me, FensAnimArt.EINBLENDEN, FensAnimEffekt.DIMMEN, FensAnimRichtung.W, 200)
    End Sub

#Region "FensAnim"

    ' zunächst die benötigten API-Deklarationen
    Private Declare Function AnimateWindow Lib "user32" ( _
      ByVal hwnd As Integer, _
      ByVal Time As Integer, _
      ByVal Flags As Integer) As Integer

    Private Const AW_ACTIVATE = &H20000
    Private Const AW_BLEND = &H80000
    Private Const AW_CENTER = &H10
    Private Const AW_SLIDE = &H40000
    Private Const AW_HIDE = &H10000
    Private Const AW_HOR_POSITIVE = &H1
    Private Const AW_HOR_NEGATIVE = &H2
    Private Const AW_VER_POSITIVE = &H4
    Private Const AW_VER_NEGATIVE = &H8
    Private Const WM_PAINT = &HF

    Enum FensAnimArt As Integer
        EINBLENDEN
        AUSBLENDEN
    End Enum

    Enum FensAnimEffekt As Integer
        DIMMEN
        ROLLEN_SEITE
        ROLLEN_MITTE
        SCHIEBEN
    End Enum

    Enum FensAnimRichtung As Integer
        N
        NO
        O
        SO
        S
        SW
        W
        NW
    End Enum

    Private Sub FensAnim( _
      ByVal Fenster As Form, _
      ByVal Art As FensAnimArt, _
      ByVal Effekt As FensAnimEffekt, _
      ByVal Richtung As FensAnimRichtung, _
      ByVal Dauer_ms As Integer)

        ' Fehlerbehandlung aktivieren       
        Try
            Dim Flags As Integer = 0

            ' Flag Ein/Ausblenden
            Select Case Art
                Case FensAnimArt.EINBLENDEN
                    Flags += AW_ACTIVATE
                Case FensAnimArt.AUSBLENDEN
                    Flags += AW_HIDE
            End Select

            ' Effect-Flag addieren
            Select Case Effekt
                Case FensAnimEffekt.ROLLEN_SEITE
                    Flags += 0
                Case FensAnimEffekt.ROLLEN_MITTE
                    Flags += AW_CENTER
                Case FensAnimEffekt.SCHIEBEN
                    Flags += AW_SLIDE
                Case FensAnimEffekt.DIMMEN
                    Flags += AW_BLEND
            End Select

            ' Richtungs-Flags addieren
            Select Case Richtung
                Case FensAnimRichtung.N
                    Flags += AW_VER_NEGATIVE
                Case FensAnimRichtung.NO
                    Flags += AW_VER_NEGATIVE + AW_HOR_POSITIVE
                Case FensAnimRichtung.O
                    Flags += AW_HOR_POSITIVE
                Case FensAnimRichtung.SO
                    Flags += AW_VER_POSITIVE + AW_HOR_POSITIVE
                Case FensAnimRichtung.S
                    Flags += AW_VER_POSITIVE
                Case FensAnimRichtung.SW
                    Flags += AW_VER_POSITIVE + AW_HOR_NEGATIVE
                Case FensAnimRichtung.W
                    Flags += AW_HOR_NEGATIVE
                Case FensAnimRichtung.NW
                    Flags += AW_VER_NEGATIVE + AW_HOR_NEGATIVE
            End Select

            ' Animation ausführen
            ' (Programm/Thread ist solange pausiert)
            AnimateWindow(Fenster.Handle.ToInt32, Dauer_ms, Flags)
        Catch : End Try

        ' sicherheits Fenster anzeigen/verstecken
        ' (falls Animation fehlschlägt!)
        Select Case Art
            Case FensAnimArt.EINBLENDEN
                Fenster.Show()
            Case FensAnimArt.AUSBLENDEN
                Fenster.Hide()
        End Select

        ' sicherheitshalber Neuzeichnen
        ' (um Grafikfehler zu vermeiden)
        Fenster.Refresh()
    End Sub

#End Region

    Private Sub myBtnOk_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles myBtnOk.Click

    End Sub

    Private Sub myBtnExit_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles myBtnExit.Click
        FensAnim(Me, FensAnimArt.AUSBLENDEN, FensAnimEffekt.DIMMEN, FensAnimRichtung.W, 200)
        End
    End Sub

    Private Sub Label4_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Label4.Click

    End Sub
End Class
