Minggu, 04 Maret 2012

Membuat Pesan(massagebox) Animasi dengan Microsoft Agent VB.NET

PREVIEW :



















Untuk mengetahui Ms Agent terlebih dahulu silahkan baca disini : MSDN

 DOWNLOAD CONTOH PROJECT





CLASS :

Public Class clsAnimation
    Dim App As New AppPath()
    Private Shared Characther As AgentObjects.IAgentCtlCharacter
    Private Shared agentController As New AgentObjects.Agent()
    Public a As String
    'Public bas As Boolean
    Public Sub loadAgent()
        On Error GoTo ErrMsg
        a = "merlin.acs"

        Dim iChar As String = ""

        iChar = App.GetPath + a

        With agentController
            .Connected = True
            .Characters.Load(a, iChar)
            Characther = .Characters(a)
        End With

        Characther.Show()

        Exit Sub
ErrMsg:
        MsgBox(Err.Description)
    End Sub

    Public Sub playAgent(ByVal Action As String)
        With Characther

            .Play(Action)
        End With
    End Sub

    Public Sub speakAgent(ByVal Sound As String)
        With Characther
            .Speak(Sound)
            .SoundEffectsOn = True
        End With
    End Sub

    Public Sub stopPlay()
        With Characther
            .Stop()

        End With
    End Sub

End Class

FORM :


Public Class Form1
    Inherits System.Windows.Forms.Form
    Public bas As Boolean

#Region " Windows Form Designer generated code "

    Public Sub New()
        MyBase.New()

        'This call is required by the Windows Form Designer.
        InitializeComponent()

        'Add any initialization after the InitializeComponent() call

    End Sub

    'Form overrides dispose to clean up the component list.
    Protected Overloads Overrides Sub Dispose(ByVal disposing As Boolean)
        If disposing Then
            If Not (components Is Nothing) Then
                components.Dispose()
            End If
        End If
        MyBase.Dispose(disposing)
    End Sub

    'Required by the Windows Form Designer
    Private components As System.ComponentModel.IContainer

    'NOTE: The following procedure is required by the Windows Form Designer
    'It can be modified using the Windows Form Designer. 
    'Do not modify it using the code editor.
    Friend WithEvents cboanimation As System.Windows.Forms.ComboBox
    Friend WithEvents Label1 As System.Windows.Forms.Label
    Friend WithEvents Label2 As System.Windows.Forms.Label
    Friend WithEvents cboloopanimation As System.Windows.Forms.ComboBox
    Friend WithEvents Label3 As System.Windows.Forms.Label
    Friend WithEvents txtspeech As System.Windows.Forms.TextBox
    Friend WithEvents btnanimation As System.Windows.Forms.Button
    Friend WithEvents btnloopanimation As System.Windows.Forms.Button
    Friend WithEvents btnspeech As System.Windows.Forms.Button
    Friend WithEvents Button1 As System.Windows.Forms.Button
    <System.Diagnostics.DebuggerStepThrough()> Private Sub InitializeComponent()
        Me.cboanimation = New System.Windows.Forms.ComboBox()
        Me.Label1 = New System.Windows.Forms.Label()
        Me.Label2 = New System.Windows.Forms.Label()
        Me.cboloopanimation = New System.Windows.Forms.ComboBox()
        Me.Label3 = New System.Windows.Forms.Label()
        Me.txtspeech = New System.Windows.Forms.TextBox()
        Me.btnanimation = New System.Windows.Forms.Button()
        Me.btnloopanimation = New System.Windows.Forms.Button()
        Me.btnspeech = New System.Windows.Forms.Button()
        Me.Button1 = New System.Windows.Forms.Button()
        Me.SuspendLayout()
        '
        'cboanimation
        '
        Me.cboanimation.Items.AddRange(New Object() {"Acknowledge", "Alert", "Announce", "Blink", "Confused", "Congratulate", "Congratulate_2", "Decline", "DoMagic1", "DoMagic2", "DontRecognize", "Explain", "GestureDown", "GestureLeft", "GestureRight", "GestureUp", "GetAttention", "GetAttentionContinued", "GetAttentionReturn", "Greet", "Hide", "Idle1_1", "Idle1_2", "Idle1_3", "Idle1_4", "Idle2_1", "Idle2_2", "Idle3_1", "LookDown", "LookDownBlink", "LookDownReturn", "LookLeft", "LookLeftBlink", "LookLeftReturn", "LookRight", "LookRightBlink", "LookRightReturn", "LookUp", "LookUpBlink", "LookUpReturn", "MoveDown", "MoveLeft", "MoveRight", "MoveUp", "Pleased", "Process", "Read", "ReadContinued", "ReadReturn", "RestPose", "Sad", "Search", "Show", "StartListening", "StopListening", "Suggest", "Surprised", "Think", "Uncertain", "Wave", "Write", "WriteContinued", "WriteReturn"})
        Me.cboanimation.Location = New System.Drawing.Point(88, 8)
        Me.cboanimation.Name = "cboanimation"
        Me.cboanimation.Size = New System.Drawing.Size(121, 21)
        Me.cboanimation.TabIndex = 0
        '
        'Label1
        '
        Me.Label1.AutoSize = True
        Me.Label1.Location = New System.Drawing.Point(0, 8)
        Me.Label1.Name = "Label1"
        Me.Label1.Size = New System.Drawing.Size(55, 13)
        Me.Label1.TabIndex = 1
        Me.Label1.Text = "Animation"
        '
        'Label2
        '
        Me.Label2.AutoSize = True
        Me.Label2.Location = New System.Drawing.Point(0, 40)
        Me.Label2.Name = "Label2"
        Me.Label2.Size = New System.Drawing.Size(83, 13)
        Me.Label2.TabIndex = 2
        Me.Label2.Text = "Loop Animation"
        '
        'cboloopanimation
        '
        Me.cboloopanimation.Items.AddRange(New Object() {"Hearing_1", "Hearing_2", "Hearing_3", "Hearing_4", "Idle3_2", "Processing", "Reading", "Searching", "Thinking", "Writing"})
        Me.cboloopanimation.Location = New System.Drawing.Point(88, 40)
        Me.cboloopanimation.Name = "cboloopanimation"
        Me.cboloopanimation.Size = New System.Drawing.Size(121, 21)
        Me.cboloopanimation.TabIndex = 3
        '
        'Label3
        '
        Me.Label3.AutoSize = True
        Me.Label3.Location = New System.Drawing.Point(0, 72)
        Me.Label3.Name = "Label3"
        Me.Label3.Size = New System.Drawing.Size(43, 13)
        Me.Label3.TabIndex = 4
        Me.Label3.Text = "Speech"
        '
        'txtspeech
        '
        Me.txtspeech.Location = New System.Drawing.Point(88, 72)
        Me.txtspeech.Name = "txtspeech"
        Me.txtspeech.Size = New System.Drawing.Size(120, 20)
        Me.txtspeech.TabIndex = 5
        Me.txtspeech.Text = ""
        '
        'btnanimation
        '
        Me.btnanimation.Location = New System.Drawing.Point(216, 8)
        Me.btnanimation.Name = "btnanimation"
        Me.btnanimation.TabIndex = 6
        Me.btnanimation.Text = "Do"
        '
        'btnloopanimation
        '
        Me.btnloopanimation.Location = New System.Drawing.Point(216, 40)
        Me.btnloopanimation.Name = "btnloopanimation"
        Me.btnloopanimation.TabIndex = 7
        Me.btnloopanimation.Text = "Do"
        '
        'btnspeech
        '
        Me.btnspeech.Location = New System.Drawing.Point(216, 72)
        Me.btnspeech.Name = "btnspeech"
        Me.btnspeech.TabIndex = 8
        Me.btnspeech.Text = "Speak"
        '
        'Button1
        '
        Me.Button1.Location = New System.Drawing.Point(216, 104)
        Me.Button1.Name = "Button1"
        Me.Button1.TabIndex = 9
        Me.Button1.Text = "Stop"
        '
        'Form1
        '
        Me.AutoScaleBaseSize = New System.Drawing.Size(5, 13)
        Me.ClientSize = New System.Drawing.Size(304, 142)
        Me.Controls.AddRange(New System.Windows.Forms.Control() {Me.Button1, Me.btnspeech, Me.btnloopanimation, Me.btnanimation, Me.txtspeech, Me.Label3, Me.cboloopanimation, Me.Label2, Me.Label1, Me.cboanimation})
        Me.FormBorderStyle = System.Windows.Forms.FormBorderStyle.FixedToolWindow
        Me.Name = "Form1"
        Me.Text = "Bring Happiness to u."
        Me.ResumeLayout(False)

    End Sub

#End Region
    Dim App As New AppPath()
    Dim ANI As New clsAnimation()
    Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        cboanimation.SelectedIndex = 0
        cboloopanimation.SelectedIndex = 0
        ANI.loadAgent()
        ANI.playAgent("GetAttentionContinued")
        ANI.speakAgent("i love indonesia")
    End Sub

    Private Sub btnanimation_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnanimation.Click
        ANI.playAgent(cboanimation.Text)
    End Sub

    Private Sub btnloopanimation_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnloopanimation.Click
        ANI.stopPlay()

        cboanimation.SelectedIndex = 1
        cboloopanimation.SelectedIndex = 1
        bas = True
        ANI.loadAgent()
        ANI.playAgent(cboanimation.Text)
        'ANI.speakAgent(cboloopanimation.Text)


    End Sub

    Private Sub btnspeech_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnspeech.Click
        ANI.speakAgent(txtspeech.Text)
    End Sub

    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
        ANI.stopPlay()
    End Sub

End Class






Tidak ada komentar:

Posting Komentar