Component File /Utils/AgentManager.cs (C#)
using System;  
using System.Windows.Forms;  
  
namespace YariSoft.Utils  
{  
    public class AgentManager  
    {      
        #region Local variables  
        private System.Drawing.Point                _defaultPosition= new System.Drawing.Point (Screen.PrimaryScreen.Bounds.Width - 150, Screen.PrimaryScreen.Bounds.Height - 180 );  
        private AgentInfo                            _info            = null;  
        private AgentServerObjects.IAgentCharacter    _agent            = null;  
        private AgentServerObjects.IAgentEx            _server            = null;  
        private int                                    characterID        = 0;  
        #endregion  
          
        #region Properties  
        public AgentServerObjects.IAgentCharacter Character  
        {  
            get{ return this._agent; }  
        }  
        #endregion  
  
        #region Constructor/Destructor  
        public AgentManager()  
        {  
        }  
        #endregion  
  
        #region Public functions  
        public bool Init( AgentInfo    Info, bool ActivateOperations )  
        {  
            this._info = Info;  
            try{  
                if( Info.AgentActive ){  
                    this._server = ( AgentServerObjects.IAgentEx )new AgentServerObjects.AgentServerClass();  
                    int pdwReqID;  
                    this._server.Load( null, out this.characterID, out pdwReqID);  
                      
                    object ptrAgent;  
                    this._server.GetCharacter ( this.characterID, out ptrAgent );  
                    this._agent = (( AgentServerObjects.IAgentCharacterEx )ptrAgent);  
                    if( ActivateOperations ){  
                        this.Show();  
                    }  
                } else {  
                    if( ActivateOperations ){  
                        this.Hide();  
                    }  
                }  
            }catch{  
                return false;  
            }  
            return true;  
        }  
  
        public bool Init( AgentInfo    Info )  
        {  
            return this.Init( Info, false );  
        }  
  
        [System.Runtime.InteropServices.DllImport("user32.dll")]  
        static extern IntPtr FindWindow( int ClassName, string WinCaption );  
  
        [System.Runtime.InteropServices.DllImport("user32.dll")]  
        static extern bool SetForegroundWindow( IntPtr WinHandle );  
  
        public void ShowProperties ()  
        {  
            if( this._server != null ){  
                this._agent.StopAll( 0xFFFFFFF );  
                this._server.ShowDefaultCharacterProperties ( (short)( Screen.PrimaryScreen.Bounds.Width / 2 ),  
                                                              (short)( Screen.PrimaryScreen.Bounds.Height / 2 ),  
                                                               0 );  
  
                IntPtr ptr = FindWindow ( 0, "Character Properties" );  
                if( ptr.ToInt32() != 0 ){  
                    SetForegroundWindow ( ptr );  
                }  
            }  
        }  
  
        public void Show ()  
        {  
            if( this._agent != null ){  
                int pdwReqID;  
                this._agent.SetPosition( _defaultPosition.X, _defaultPosition.Y );  
                this._agent.Show( 0, out pdwReqID );  
                this.Play( Utils.AgentPlayer.MovieTypeEnum.Start );  
            }  
        }  
  
        public void Hide()  
        {  
            if( this._agent != null ){  
                int pdwReqID;  
                this.Play( Utils.AgentPlayer.MovieTypeEnum.Stop );  
                this._agent.Hide    ( 0, out pdwReqID );  
                this._agent = null;  
                this._server.Unload ( this.characterID );  
                this._server = null;  
            }  
        }  
  
        public void Play( Utils.AgentPlayer.MovieTypeEnum MovieType )  
        {  
            if( this._agent != null && this._info.ConfigFileName != "" ){  
                if( MovieType == Utils.AgentPlayer.MovieTypeEnum.DefPosition ){  
                    int LeftPos;  
                    int TopPos;  
                    this._agent.GetPosition ( out LeftPos, out TopPos );  
                    if( LeftPos != _defaultPosition.X || TopPos != _defaultPosition.Y ){  
                        AgentMovie movie = new AgentMovie( "Untitled" );  
                        movie.AddOperation( new AgentOperation ( AgentOperation.OperationTypeEnum.MoveTo, _defaultPosition ));  
                        AgentPlayer agentPlayer = Utils.AgentPlayer.LoadFromFile( this._info.ConfigFileName );  
                        agentPlayer.Play( movie, this.Character );  
                    }  
                }else{  
                    AgentPlayer agentPlayer = Utils.AgentPlayer.LoadFromFile( this._info.ConfigFileName );  
                    agentPlayer.Play( MovieType, this.Character );  
                }  
            }  
        }  
        #endregion  
    }  
}