Click here to Skip to main content
15,883,901 members
Articles / Programming Languages / C++
Article

MSAgent Class

Rate me:
Please Sign up or sign in to vote.
4.38/5 (8 votes)
23 Sep 20032 min read 80.5K   2.7K   41   15
A Class to use MS-Agents instead of MessageBoxes

Introduction

Apologies in advance about my English and the brief descriptions, as my native language is German. I demonstrate a class to use MS-Agents instead of MessageBoxes to communicate with users. The following features are included:

  • simple command interface.
  • serialize all commands.
  • support scripting.
  • can interact with user through mouse events.

Using the code

class cAgent

cAgent (char *Character = NULL);

Create a Agent object. Character can be a *.acs file. NULL uses the default character from system.

bool  Command (char *Command);

Push a Command to the Queue. Commands are case sensitive, Parameters and Values are not.

CommandParameterValues [defaults]

Speak

Text 
ThinkText 
PlayAnimationName 
MoveToxPos yPos Speed{number}{number}{[0]|> 0}
MoveToPosition Speed{center|lefttop|leftbottom|righttop|rightbottom}{[0]|>0}
MoveDeltaX DeltaY Speed{number}{number}{[0]|>0}
ShowSpeed{[slow]|fast}
HideSpeed{[slow]|fast}
SizexSize ySize{number}{number}
Resize  
NameName for Character 
LanguageLanguage{german|american|english}
MenuShowAutoPopup{[off]|on}
SoundsAnimationSounds{[on]|off}
Volumechannel switch{master|wave}{[on]|off|reset|volume in percent}
PhraseFileName{[Phrases.txt]}
ExecuteExecutable [Parameter] 
Shell["Verb"] File 
Stop  
Quit  

bool  Script (char *IniFile,char *Key);

Execute a script. Scripts are Sections from Windows .ini files :

An additional command available from scripts is :

CommandParameterValues [defaults]

Goto

a key in this script file 

Sample Script File :

[FIRST]
MoveTo Center 0
Show Slow
Play Greet

[HALLO]
Goto First
Speak Hallo !
Hide Slow

[GOODBY]
Goto First
Speak Goodby !
Hide Slow
Quit

void  GetIdle     (void);

Wait for Queue is empty.

void  GetQuit     (void);

Wait for Quit command and terminate. You can't use the cAgent Object after GetQuit().

virtual void   Click     (teMouseEventKeys keys,tMousePosition p);
virtual void   DblClick   (teMouseEventKeys keys,tMousePosition p);

Overwrite this functions to get response from Agent. A window created from here will be destroyed with the cAgent object.
Click() will be called before DblClick(), to avoid this use the next four functions.

virtual void   LeftClick      (teVirtualKeys key,bool SysTray);
virtual void   RightClick     (teVirtualKeys key,bool SysTray);
virtual void   LeftDblClick   (teVirtualKeys key,bool SysTray);
virtual void   RightDblClick  (teVirtualKeys key,bool SysTray);

Overwrite this functions to get response from Agent. This functions would be executed from a thread that terminate on return XXClick(). A window created from here will be destroyed after return !

The simplest way to use :

#include "cAgent.h"

extern "C" int PASCAL WinMain (HINSTANCE i,HINSTANCE prev,
    LPSTR cmd,int show) {
cAgent *Agent = new cAgent();

Agent->Command ("MoveTo  Center 0");
Agent->Command ("Show    Slow");
Agent->Command ("Play    Greet");
Agent->Command ("Speak   Hallo world !");
Agent->Command ("Play    RestPose");
Agent->Command ("Hide    slow");
Agent->GetIdle ();

delete Agent;
return ERROR_SUCCESS;
}

Other classes used from cAgent

cAgentCommands

Covers the commands from cAgent.

cAgentSink

Controls the queue that will serialize the commands. Raise mouse and bookmark events.

Queue

A simple circular buffer to hold the commands.

cMMControl , cPhrase

cMMControl controls the system audio mixer. cPhrase picks a random phrase from a simple formatted text file.

Points of Interest

MS-Agent Hompagehttp://www.microsoft.com/msagent/
Developer downloads

http://www.microsoft.com/msagent/downloads/

History

  • 15 Sep 2003 Initial release
  • 24 Sep 2003 Updated sourcecode

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


Written By
Germany Germany
This member has not yet provided a Biography. Assume it's interesting and varied, and probably something to do with programming.

Comments and Discussions

 
GeneralMS Agent, why Scroll lock Pin
Muammar©10-May-07 21:37
Muammar©10-May-07 21:37 
GeneralBorland C++ BuilderX compatibility? (how to) Pin
Millyard16-Mar-05 11:46
Millyard16-Mar-05 11:46 
Hi there,

I am using Borland C++ BuilderX application -- it appears to be using a slightly different version of C+ -- the above example is not working...do you have any thoughts on adjustments in order to make it work fine.

Cheers.
Questioncan u show me how to use that Pin
nigrl23-Oct-03 15:42
nigrl23-Oct-03 15:42 
GeneralCrash, error on NT 4 ( not only? ) Pin
Ondrej Novotny25-Sep-03 1:41
Ondrej Novotny25-Sep-03 1:41 
GeneralRe: Crash, error on NT 4 ( not only? ) Pin
Stefan Voitel25-Sep-03 11:51
Stefan Voitel25-Sep-03 11:51 
GeneralVC++ 6 project/conpile files Pin
Bagpuss16-Sep-03 6:13
Bagpuss16-Sep-03 6:13 
GeneralRe: VC++ 6 project/conpile files Pin
Stefan Voitel18-Sep-03 9:14
Stefan Voitel18-Sep-03 9:14 
GeneralRe: VC++ 6 project/conpile files Pin
Member 3813137-Oct-03 20:25
Member 3813137-Oct-03 20:25 
GeneralRe: VC++ 6 project/conpile files Pin
Arbesto Pelta28-Jan-04 6:27
Arbesto Pelta28-Jan-04 6:27 
GeneralSome commands are missing... Pin
Anonymous15-Sep-03 11:38
Anonymous15-Sep-03 11:38 
GeneralRe: Some commands are missing... Pin
Stefan Voitel18-Sep-03 9:02
Stefan Voitel18-Sep-03 9:02 
GeneralWaaahhh!!!! Pin
jhwurmbach15-Sep-03 3:49
jhwurmbach15-Sep-03 3:49 
GeneralRe: Waaahhh!!!! Pin
Greg Ellis15-Sep-03 5:12
Greg Ellis15-Sep-03 5:12 
GeneralRe: Waaahhh!!!! Pin
Stefan Voitel18-Sep-03 9:04
Stefan Voitel18-Sep-03 9:04 
GeneralRe: Waaahhh!!!! Pin
Stefan Voitel18-Sep-03 9:20
Stefan Voitel18-Sep-03 9:20 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.