⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 agent.h

📁 vc编写的精灵显示源码
💻 H
字号:
// Agent.h:		The header file for CAgent class - wrapper class for MsAgent
// Autor:		Michael Mac
// Contact:		All bugs, suggestions and opinions send to GreenSequoia@wp.pl
// Copyright:	This code is free. It can be used without any limitations. You can modify it but 
//				mark what you've changed.
//				It would be nice if you would credit me somewhere in your program or documentation 
//				
// History:
//	08.02.2002	The class was created. It contains the main functionality.
//	
//////////////////////////////////////////////////////////////////////

#if !defined(gS_MsAgent_DEFINED)
#define gS_MsAgent_DEFINED

// compilation consts
#define BALLOONINPUT	// Input MFC balloon
#define TIP				// Tip MFC balloon


// MsAgent
#include "AgtSvr_i.c"
#include "agtsvr.h"
#include "AgtErr.h"

// CArray
#include <afxtempl.h>

#ifdef TIP
	#include "TipWnd.h"
#endif
#ifdef BALLOONINPUT
	#include "InputBalloon.h"	
#endif

////////////////////
// Lang IDs
/*
Arabic (Saudi) 0x0401			Italian 0x0410
Basque 0x042d					Japanese 0x0411
Chinese (Simplified) 0x0804		Korean 0x0412
Chinese (Traditional) 0x0404	Norwegian 0x0414
Croatian 0x041A					Polish 0x0415
Czech 0x0405					Portuguese (Portugal) 0x0816
Danish 0x0406					Portuguese (Brazil) 0x0416
Dutch 0x0413					Romanian 0x0418
English (British) 0x0809		Russian 0x0419
English (US) 0x0409				Slovakian 0x041B
Finnish 0x040B					Slovenian 0x0424
French 0x040C					Spanish 0x0C0A
German 0x0407					Swedish 0x041D
Greek 0x0408					Thai 0x041E
Hebrew 0x040D					Turkish 0x041F
Hungarian 0x040E
*/

////////////////////
// Consts - they are already defined in the MsAgent header files

// STOP_TYPE_ALL 				// Stops all animation requests, including non-queued Prepare requests. 
// STOP_TYPE_PLAY 				// Stops all Play requests. 
// STOP_TYPE_MOVE 				// Stops all Move requests. 
// STOP_TYPE_SPEAK				// Stops all Speak requests. 
// STOP_TYPE_PREPARE	 		// Stops all queued Prepare requests. 
// STOP_TYPE_NONQUEUEDPREPARE	// Stops all non-queued Prepare requests. 
// STOP_TYPE_VISIBLE			// Stops all Hide or Show requests. 

void CheckAndThrow (int nCode);
void Throw (int nCode);

class CAgent
{
public:

	class CBalloon
	{
	public:
		CBalloon() {};
		~CBalloon() {};
		
		BOOL GetEnabled ();

		long GetNumLines ();
		long GetNumCharsPerLine ();
		inline void SetNumLines ( long lLines );
		inline void SetNumCharsPerLine ( long lChars );

		CString GetFontName ();
		inline void SetFontName ( CString strFontName );
		long GetFontSize ();
		inline void SetFontSize ( long lSize );
		short GetFontCharSet ();
		inline void SetFontCharSet ( short sCharSet );

		BOOL GetFontBold ();
		BOOL GetFontItalic ();
		BOOL GetFontStrikethru ();
		BOOL GetFontUnderline ();

		COLORREF GetForeColor ();
		COLORREF GetBackColor ();
		COLORREF GetBorderColor ();

		BOOL GetVisible ( );
		inline void SetVisible ( BOOL bVisible );

		DWORD GetStyle ( );
		inline void SetStyle ( DWORD dwStyle );
		/*
		BALLOON_STYLE_BALLOONON = 0x00000001; The balloon is supported for output. 
		BALLOON_STYLE _SIZETOTEXT = 0x0000002; The balloon height is sized to accommodate the text output. 
		BALLOON_STYLE _AUTOHIDE = 0x00000004; The balloon is automatically hidden. 
		BALLOON_STYLE _AUTOPACE = 0x00000008; The text output is paced based on the output rate.  
		*/

	public:
		IAgentBalloonEx* m_pBalloon;
	};

private:
	// This structure contains main characters info
	typedef struct tagCHAR
	{
		IAgentCharacterEx* pCharacterEx;
		long lCharID, lReqID;
		CBalloon* pBalloon;
	#ifdef TIP
		CTipWnd* pTipWnd;
	#endif
	#ifdef BALLOONINPUT
		CInputBalloon* pInputBalloon;// MFC Input balloon
	#endif
	}tagCHAR;
public:
	
	class CNotifySink : public IAgentNotifySinkEx
	{
	public:
		CNotifySink();
		~CNotifySink();

		STDMETHODIMP QueryInterface(REFIID, LPVOID FAR *);
		STDMETHODIMP_(ULONG) AddRef();
		STDMETHODIMP_(ULONG) Release();

		STDMETHODIMP GetTypeInfoCount(UINT *);
		STDMETHODIMP GetTypeInfo(UINT, LCID, ITypeInfo **);
		STDMETHODIMP GetIDsOfNames(REFIID, OLECHAR **, UINT, LCID, DISPID *);
		STDMETHODIMP Invoke(DISPID, REFIID, LCID, WORD, DISPPARAMS *, VARIANT *, EXCEPINFO *, UINT *);

		virtual STDMETHODIMP Command(long dwCommandID, IUnknown * punkUserInput);
		virtual STDMETHODIMP ActivateInputState(long dwCharID, long bActivated);
		virtual STDMETHODIMP Restart();
		virtual STDMETHODIMP Shutdown();
		virtual STDMETHODIMP VisibleState(long dwCharID, long bVisible, long lCause);
		virtual STDMETHODIMP Click(long dwCharID, short fwKeys, long x, long y);
		virtual STDMETHODIMP DblClick(long dwCharID, short fwKeys, long x, long y);
		virtual STDMETHODIMP DragStart(long dwCharID, short fwKeys, long x, long y);
		virtual STDMETHODIMP DragComplete(long dwCharID, short fwKeys, long x, long y);
		virtual STDMETHODIMP RequestStart(long dwRequestID);
		virtual STDMETHODIMP RequestComplete(long dwRequestID, long hrStatus);
		virtual STDMETHODIMP BookMark(long dwBookMarkID);
		virtual STDMETHODIMP Idle(long dwCharID, long bStart);
		virtual STDMETHODIMP Move(long dwCharID, long x, long y, long lCause);
		virtual STDMETHODIMP Size(long dwCharID, long lWidth, long lHeight);
		virtual STDMETHODIMP BalloonVisibleState(long dwCharID, long bVisible);

		virtual STDMETHODIMP HelpComplete(long dwCharID, long dwCommandID, long dwCause);
		virtual STDMETHODIMP ListeningState(long dwCharacterID, long bListenState, long dwCause);
		virtual STDMETHODIMP DefaultCharacterChange(BSTR bszGUID);
		virtual STDMETHODIMP AgentPropertyChange();
		virtual STDMETHODIMP ActiveClientChange(long dwCharID, long lStatus);
#ifdef TIP
		virtual STDMETHODIMP Tip( long dwCharID, long lEvent );
		static STDMETHODIMP CALLBACK TipProc( long lEvent, long lAgent, long dwCharID );
#endif
#ifdef BALLOONINPUT
		virtual STDMETHODIMP InputBalloon( long dwCharID, long lEvent );
		static STDMETHODIMP CALLBACK InputBalloonProc( long lRetVal, long lAgent, long dwCharID );
#endif
		CAgent *m_pAgent;
	private:
		ULONG	m_cRefs;
	};

	// Initialize/uninitialize
	void Init ( CNotifySink* pNotifySink = NULL);
	void Close ();
	void LoadCharacter ( CString strChar, long *pCharID );
	void UnloadCharacter ( long lCharID);
	BOOL IsInit ();

	/*inline */void ShowDefaultCharacterProperties ( long x, long y, BOOL bUseDefault );
	void ShowAgentPropertySheet ( BOOL bShow );

	void GetVersion ( short* pMajor, short* pMinor );

	long GetIndexFromID (long lID, BOOL bThrow = TRUE);

	void Show ( BOOL bShow = TRUE, BOOL bAnimation = TRUE, long lCharID = -1 );
	
	void Play ( BSTR bstrAnimation, long lCharID = -1 );
	void Play ( CString strAnimation, long lCharID = -1 );

	void GetAnimationNames ( BSTR* pAnimations, long lCharID = -1 );
	void GetAnimationNames ( CString* pAnimations, long lCharID = -1 );

	void Stop ( long lRequestID, long lCharID = -1);
	void StopAll ( long lType = STOP_TYPE_PLAY, long lCharID = -1);	// NOTE: see top of the file for available values

	void GestureAt ( int x, int y, long lCharID = -1);
	void MoveTo ( int x, int y, int nSpeed=1000, long lCharID = -1); // nSpeed=0 - no animation

	POINT GetPosition ( long lCharID = -1 );
	SIZE GetSize ( long lCharID = -1 );
	BOOL GetVisible ( long lCharID = -1 );

	void GetCharacterInfo ( BSTR* pName, BSTR* pDescription, long lCharID = -1);
	void GetCharacterInfo ( CString* pName, CString* pDescription, long lCharID = -1);

	void Speak ( BSTR bstrText, BSTR bstrURL = NULL, long lCharID = -1);	// NOTE: (b)strURL has not been 
	void Speak ( CString strText, CString strURL = "", long lCharID = -1);// implemented in MFC balloon yet

	void SetSoundEffects ( BOOL bEnable, long lCharID = -1);
	BOOL GetSoundEffects ( long lCharID = -1);
	void SetIdle ( BOOL bEnable, long lCharID = -1);
	BOOL GetIdle ( long lCharID = -1);
	void SetAutoPopupMenu ( BOOL bEnable, long lCharID = -1);
	BOOL GetAutoPopupMenu ( long lCharID = -1);

	// Language functions
	void SetLanguageID ( long lLangID, long lCharID = -1); // NOTE: all ID are enumed at the beginning of the header file
	long GetLanguageID ( long lCharID = -1);

	// Balloon


	// ReqID && CBalloon && CInputBalloon
	long GetLastReqID ( long lCharID = -1 );
	CAgent::CBalloon* GetBalloon ( long lCharID = -1 );
#ifdef TIP
	CTipWnd* GetTip ( long lCharID = -1 );
#endif
#ifdef BALLOONINPUT
	CInputBalloon* GetInputBalloon ( long lCharID = -1 );
#endif

	// Error info

	
	// Constructor/Destructor
	CAgent();
	virtual ~CAgent();

public:
	long m_lDefaultCharID;				// Contains CharID of the deafult character
	CNotifySink* m_pNotifySink;			// NotifySink pointer if set
private:
	CArray<tagCHAR, tagCHAR> m_arChars;	// The array contains characters' IDs & pointers
	IAgentEx* m_pAgentEx;				// MsAgent main pointer
	long m_lNotifySinkID;				// NotifySink ID (used to unregister)
};

#endif // !defined( gS_MsAgent_DEFINED )

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -