5,696,576 members and growing! (14,501 online)
Email Password   helpLost your password?
General Programming » Programming Tips » General     Intermediate

Programming the MS Agent Control

By Santosh Rao

Programming an animated agent similar to the office assistant.
VC6, C++Windows, NT4, MFC, VS6, Visual Studio, Dev

Posted: 3 Mar 2000
Updated: 3 Mar 2000
Views: 129,518
Bookmarked: 49 times
Announcements
Loading...



Search    
Advanced Search
Sitemap
32 votes for this Article.
Popularity: 7.01 Rating: 4.65 out of 5
1 vote, 7.1%
1
0 votes, 0.0%
2
1 vote, 7.1%
3
0 votes, 0.0%
4
12 votes, 85.7%
5
  • Download demo project - 21 Kb
  • Download source files - 44 Kb
  • Introduction to the Microsoft Agent

    Microsoft has introduced the new MS Agent Control. This control is very similar to the office assistant that we see in MS Office Applications. This control can seamlessly integrate into existing applications with a lot of ease due to good programming support that is available. It richly enhances the user interface and has seemingly wide applications as it is even scriptable in to Web Pages for which it is actually meant and supposed to have good performance on the internet because of low band width requirements.

    The control is available as an OCX interface and COM programming support is also provided.

    Key appreciable features are:

    • Text To Speech Conversion Support
    • Speech Recognition Engine

    The MS Agent is distributed in to several components (put into a single file AGENT.CPP and AGENT.H in the sample):

    • Request
    • Agent (control)
    • Characters (collection)
    • Character Commands (collection)
    • Command
    • Balloon
    • AnimationNames (collection)
    • SpeechInput
    • AudioOutput
    • CommandsWindow
    • PropertySheet

    The best place to go to refer to the documentation is at Microsoft's site.


    Programming

    I wished to make a control like the office agent almost a year back. But then I knew I had to do it on my own and I gave up at ease. All I wished was an API interface to the Agent and the prayer was answered even without asking.

    I wished to share with you this information as I felt all might find this information quite useful. I really don’t deserve any credit for this code as I have just referred MSDN, Microsoft Web site and MS Samples. But I will surely be glad to help if you need any help from me.

    This sample is provided so that you can check it out and the MFC Wrapper class that I have written encapsulates quite a few details and can be useful in case it helps you.

    Steps that I followed were to download the following and I could install it without problems:

    1. Download the Microsoft Agent core components
    2. Download Agent Interface files. Unzip the header files to your DevStudio/VisualStudio VC/Include folder.
    3. Download MS Agent Characters. (Peedy and Genie are really cute characters)
      (Note: - After installation characters will be available in your $Windows\MSAgent\Chars directory)
    4. Download the Text to Speech engines.
    5. Download the Speech Recognition engines. (I have not yet checked this out)
    6. Download the Speech control panel.
    7. Optionally download:
      • Agent Character Editor
      • Linguistic information sound editing Tool
      • The Microsoft Site offers lot of code samples and documentation to download.
    8. Download the End User Downloads
    9. Download the Developer Downloads


    Sample Screen of the test application


    The MFC Wrapper: CMsAgentWrapper

    CMsAgentWrapper does not have a base class. A CMsAgentWrapper object consists of a CAgentCtlEx MS Agent.

    Data Members

    • CAgentCtlEx m_obAgent - the the Agent Control Object.
    • CStringArray m_szAnimationsArray - an array of supported Animations.
    • BOOL m_bStopBeforePlay - determines whether Previous Animation should be stopped before playing next Animation
    • BOOL m_bAgentReady - determines whether the Agent Character Loaded.

    Construction/Destruction

    • CMsAgentWrapper();
    • virtual ~CMsAgentWrapper();

    Initialization and Cleanup

    BOOL Create(UINT uId, CWnd *pParentWnd = NULL, DWORD dwStyle = WS_CHILDWINDOW, BOOL bRaiseRequestErrors = FALSE);
    Creates the MS Agent Wrapper control for the given id.

    BOOL Exit();
    Closes the Agent Control.

    BOOL LoadCharacter(CString pszCharFilename);
    Loads a Character File. (Note: - After installation characters will be available in your $Windows\MSAgent\Chars directory)

    BOOL Move(int iX, int iY);
    Moves the Microsoft Agent Character Absolute screen coordinated X,Y Location taking into account the agent size.

    BOOL Speak(CString szSpeakText, BOOL bBalloonEnabled = TRUE, BOOL bBalloonSizeToText = TRUE, BOOL bBalloonAutoPace = TRUE, BOOL bBalloonAutoHide = TRUE);
    The specified text is shown in a message box and if a sound card and Text to speech support is installed the given text is spoken out. Setting Auto Pace to FALSE makes the text displayed in the message box appear at once rather than a word at a time.

    BOOL SetSoundEffectsOn(BOOL bSoundEffectsOn = TRUE);
    Sets sound support for the agent.

    BOOL Stop();
    Requests the Agent to stop animations.

    BOOL Show();
    Requests the Agent Server to show the selected character.

    BOOL Hide();
    Requests the Agent Server to hide the selected character.

    BOOL ActivateApp(BOOL bActive);
    Requests the Agent Server to hide/select the selected character. This function is ideal to be used to activate and deactivate the Agent when the parent activates and deactivates.

    LPCTSTR GetCharacter>();
    Gets the Name of the Character not correctly implemented yet.

    void SetStopBeforePlay(BOOL bStopBeforePlay = TRUE);
    Decides whether the previous animation should be stopped before playing the next animation.

    BOOL GetStopBeforePlay();
    Retrieves the setting specifying whether previous animation should be stopped before playing the next animation.

    int GetSizeOfAnimations();
    Retrieves the number of supported animations for the given Microsoft Agent Control.

    CString GetAnimationIndex(int i);
    Retrieves the name of the specified supported animations by index.

    BOOL Play(int iAnim = 0, BOOL bStop = TRUE);
    Plays the Animation at the specified index. bStop specifies whether the previous animation has to be stopped before playing the current animation.


    Additional Resources

    License

    This article has no explicit license attached to it but may contain usage terms in the article text or the download files themselves. If in doubt please contact the author via the discussion board below.

    A list of licenses authors might use can be found here

    About the Author

    Santosh Rao


    1993 started with Computers

    BE(Computer Science) and MS (Software Systems)

    Industry Experience: 10 Years

    C, C++, VC++(MFC), .NET, C#, MTS, Queuing, ASP.NET, AJAX, Java, J2EE, SunOne, JMS

    Banking, Insurance & Pension,Health Care

    Occupation: Architect
    Location: India India

    Other popular Programming Tips articles:

    Article Top
    Sign Up to vote for this article
    You must Sign In to use this message board.
    FAQ FAQ Noise ToleranceSearch Search Messages 
     Layout  Per page   
     Msgs 1 to 25 of 37 (Total in Forum: 37) (Refresh)FirstPrevNext
    GeneralHow would you list all the available voices?memberprudnik7:02 18 Dec '07  
    QuestionThermal measurement projectmemberisraa mohammed0:23 24 Nov '07  
    GeneralConext menu in MS Agent controlsussneetu gahlot20:23 23 Sep '05  
    GeneralBorland C++ BuilderX compatible? (how to)memberMillyard12:48 16 Mar '05  
    Generaldisplay indexed msgmemberbayue18:18 27 Dec '04  
    Generaladd ms agent to my webpage without uploding itmemberbayue17:40 27 Dec '04  
    Generalautomaticly recordingmembermenag4:19 2 Nov '04  
    GeneralHow to mix animation with speechsussAnonymous9:51 13 May '04  
    Generalordinal 5076sussAnonymous8:14 18 Nov '03  
    GeneralRe: ordinal 5076sussAnonymous23:47 21 Mar '05  
    GeneralAssertion with Dev 7...memberLilMoke19:06 25 Oct '03  
    GeneralRe: Assertion with Dev 7...memberLilMoke5:11 26 Oct '03  
    GeneralSame Compile Errormemberalan936:10 30 Sep '03  
    GeneralOrdinal 5077 & 5076memberSanjin12:44 17 Dec '02  
    GeneralRe: Ordinal 5077 & 5076memberTeisDraiby11:16 27 Dec '02  
    GeneralRe: Ordinal 5077 & 5076memberBill94421:05 21 Sep '03  
    GeneralRe: Ordinal 5077 & 5076sussAnonymous9:44 23 Jun '03  
    GeneralGreat Job!memberPaul Kissel21:20 13 Dec '02  
    GeneralSome help!!sussAnonymous18:37 11 Oct '02  
    GeneralWhy did Error happen when I added ActiveX control?memberAnonymous18:22 8 Jul '02  
    GeneralMS Access versus MS AgentmemberRobert Goyvaerts13:13 21 May '02  
    GeneralCompile errormemberAbhishek Jain8:00 8 Apr '02  
    GeneralRe: Compile errormemberFranz Brunner0:29 2 Nov '03  
    GeneralCompile errormemberAbhishek Jain7:55 8 Apr '02  
    GeneralRe: Compile errormemberwingswings18:34 8 Jun '03  

    General General    News News    Question Question    Answer Answer    Joke Joke    Rant Rant    Admin Admin   

    PermaLink | Privacy | Terms of Use
    Last Updated: 3 Mar 2000
    Editor: Valerie Bradley
    Copyright 2000 by Santosh Rao
    Everything else Copyright © CodeProject, 1999-2008
    Web16 | Advertise on the Code Project