65.9K
CodeProject 正在变化。 阅读更多。
Home

使用 Microsoft Agent Control 2.0 - Merlin

starIconstarIconstarIconstarIcon
emptyStarIcon
starIcon

4.55/5 (11投票s)

2004年6月22日

CPOL

3分钟阅读

viewsIcon

110274

downloadIcon

4569

展示 Microsoft Agent Control 2.0 的主要功能

引言

在本教程中,我将向您展示如何制作一个小程序,帮助您理解 Microsoft Agent 的某些方面。 在这个例子中,我们将使用 Merlin 模型,因为它随 Windows XP 一起提供。 如果您没有 Windows XP,请不要担心。 源代码下载包括模型和使用它所需的所有安装文件(2 个小的 1MB 左右的文件”),必须将这些文件与您的程序一起分发,以便它可以在其他机器上正常工作。 让我们开始吧。

首先,下载源文件并安装“INSTALL FIRST.exe”和“INSTALL SECOND.exe”。 完成后,将“MERLIN.ACS”放在与您的项目相同的文件夹中。 然后,让我们开始编码。

如果您尚未这样做,请启动一个新项目,并确保将其保存在与“MERLIN.ACS”相同的目录中。 转到您的窗体,右键单击工具箱并按“组件…”您将看到一个与此类似的屏幕

Components

如您所见,我已经选择了 Microsoft Agent Control 2.0。 因此,除非已经完成,否则勾选该框,然后按“确定”。

现在您将在工具箱中看到 Agent Control(秘密特工)。 转到您的窗体设计视图,然后单击 Agent Control,并在窗体中的任意位置绘制它(对用户不可见)。

接下来,在窗体顶部的中心附近绘制一个ComboBox,并将其命名为Animation,并将文本设置为无。 现在,在ComboBox下方绘制一个TextBox,并将其命名为Speech,将其文本设置为无。 之后,在底部中心绘制一个CommandButton,并将其命名为“btnDoIt”,并将其标题设置为“Do It!”。 现在只需在Animation ComboBox旁边添加一个Label,并将其标题设置为“Animation:”。 在 Speech TextBox旁边添加另一个Label,并将其标题设置为“Speak:”。

您的窗体应该看起来像这样

Form

现在,开始编写代码。 选择 Form, Load,您将看到...

Private Sub Form_Load()
End Sub

... 出现在代码中。 在“Private Sub Form_Load()”和“End Sub”之间,键入

Dim CharPath As String

' Activate Merlin
CharPath = "" ' The path is the root directory for your project

' Load the characters specified in path
ctlAgent.Characters.Load "Merlin", CharPath & "merlin.acs"
Set Merlin = ctlAgent.Characters("Merlin")

' Display Merlin on the screen
Merlin.Show

' Add the Character Animations to the ComboBox
Animation.AddItem ("Acknowledge")
Animation.AddItem ("Announce")
Animation.AddItem ("Blink")
Animation.AddItem ("Congratulate")
Animation.AddItem ("DoMagic1")
Animation.AddItem ("DoMagic2")
Animation.AddItem ("Explain")
Animation.AddItem ("GestureDown")
Animation.AddItem ("GestureLeft")
Animation.AddItem ("GestureRight")
Animation.AddItem ("GetAttention")
Animation.AddItem ("LookUpBlink")
Animation.AddItem ("MoveDown")
Animation.AddItem ("MoveLeft")
Animation.AddItem ("MoveRight")
Animation.AddItem ("MoveUp")
Animation.AddItem ("Pleased")
Animation.AddItem ("Process")
Animation.AddItem ("Read")
Animation.AddItem ("Sad")
Animation.AddItem ("Search")
Animation.AddItem ("Show")
Animation.AddItem ("Think")
Animation.AddItem ("Wave")
Animation.AddItem ("Write")

这只是在激活并显示 Merlin 模型后,将 Merlin 拥有的每个动画添加到ComboBox中。 接下来,双击“Do It!”按钮并键入

   Set Merlin = ctlAgent.Characters("Merlin") ' Load Merlin to memory
   If Animation.Text = "" Then                ' If the Animation ComboBox has 
                                              ' nothing selected
      MsgBox ("No Animation Selected")        ' Give an error
   Else ‘ If something has been chosen in the ComboBox
      Merlin.Play Animation.Text   ' Have Merlin play the selected animation
   End If

   If Speech.Text = "" Then    ' If no text has been entered into the TextBox
      MsgBox ("No Text Entered to speak") ‘ Give an error
   Else                        ' If text has been entered
      Merlin.Speak Speech.Text ' Have Merlin say whatever is written in the 
                               'TextBox
   End If
End Sub

现在,当您运行该程序时,如果一切顺利(如果不是,请参阅本教程后面的可能错误),那么当出现该窗体时,Merlin 也应该出现,您可以选择他的任何动画,并键入让他说的任何内容,他就会执行。 相当酷,不是吗?

可能出现的错误

我遇到的一个错误是将我的项目命名为“Merlin”,这导致了一个错误,因为该模型被命名为 Merlin,并且每当我设置 Merlin 的属性时,编译器都认为我指的是该项目。

另外,如果您不安装这两个文件,那么角色要么不会出现,要么您将听不到他说的任何内容,您只会看到文本。

希望您喜欢本教程。 如果您有任何问题或建议,请随时通过电子邮件发送至 spiderfreak3000@msn.com

历史

  • 2004 年 6 月 21 日:首次发布
© . All rights reserved.