Microsoft Agent Technology Application

Source: Internet
Author: User

Microsoft Agent Technology Application
-- Introduction to the implementation principle of AgentShell

[Abstract]
This article describes how to apply the Agent and how to implement AgentShell and several important technical processes.

[Keywords]
Agent, COM, role, speech recognition, and speech synthesis.

The Agent programming methods are mainly called by ActiveX using VB, VC, and other languages. In addition, the Agent can be directly called by COM through VC.
Program call. In VB, it is the easiest to call the Agent. However, the vbprogram has many defects and is difficult to be applied in practice.
In VC, because the Agent fully adopts UNICODE encoding, it also needs to handle a variety of complicated COM interfaces.
Fixed issues. AgentShell is a shell program established between the Agent and the application. It can be used to connect the complex COM
The port is encapsulated into a simple function call to control the Agent. At the same time, AgentShell is also used as an independent process
This article will introduce in detail its implementation principles.
(1) Principles
The connection between AgentShell and Agent Server is implemented through the COM call, and the communication with the application is implemented through WM_COPYDATA
Message to indicate the relationship between AgentShell and other programs:
[Agent Server]
|
[COM call]
|
[AgentShell]
|
[Message]
|
[Application]

We call it a "role" to attach the corresponding animation and voice code to an Agent control. Generally, an Agent role is created by calling COM,
The process is as follows:
[Initialize COM]
|
[Connect to Agent COM Sever and create Agent control]
|
[Register the message reactors controlled by the Agent (Notify Sink)]
|
[Load the role data file and create a role (Character)]
|
[Set the language, initial position, and other attributes of a role]
|
[Show roles]

The following global variables are defined in AgentShell to control the attributes and actions of a role:
Message ID of the Role: long g_lpolicysinkid.
Role ID: long g_lMyAgentID.
Agent control pointer: IAgentEx * g_pAgentEx.
Role pointer: IAgentCharacterEx * g_pMyAgent.
Role message reactor pointer: agentpolicysink * g_pSink.

Using the preceding variables, you can easily call the Agent function, such as displaying roles:
BOOL agentShow ()
{
HRESULT hRes;
Long lRequestID;

If (! G_pMyAgent)
Return FALSE;
HRes = g_pMyAgent-> Show (FALSE, & lRequestID );
If (FAILED (hRes ))
Return FALSE;
Return TRUE;
}

(2) role Language Processing
Currently, the Agent supports many languages, including not only display, but also speech synthesis and speech recognition (only display is supported for Chinese ).
The language is also divided into the subject Language and sub-language (or sub-language). If the main language of Chinese is Chinese (LANG_CHINESE), sub-language can
Simplified (SUBLANG_CHINESE_SIMPLIFIED) and traditional Chinese. In AgentShell, two global variables are defined to express the language of the role:

Main language: DWORD g_nMainLang.
Sub-language: DWORD g_nSubLang.
In this way, the program must display different information based on the current language, such as the quit message when the program exits:
First, define different language information, which can be macro-defined or resource data:
# Define MES_GOODBYEL "Goodbye! "
# Define MES_GOODBYE_CH L "goodbye! "
# Define MES_GOODNIGHTL "Good night! "
# Define MES_GOODNIGHT_CH L "Good night! "
The exit prompt code is as follows:
Void Goodbye ()
{
If (g_bAgentOK)
{
SYSTEMTIME time;
AgentStop ();
AgentShow ();
AgentPlay (L "Wave ");
GetLocalTime (& time );
// Prompt different information based on time
If (g_nMainLang = LANG_ENGLISH)
{
// Prompt in English
If (time. wHour <19)
AgentSpeak (MES_GOODBYE );
Else
AgentSpeak (MES_GOODNIGHT );
}
Else
{
// Chinese prompt
If (time. wHour <19)
AgentSpeak (MES_GOODBYE_CH );
Else
AgentSpeak (MES_GOODNIGHT_CH );
}
AgentHide ();
// Wait for several times
Sleep (MAX_QUIT_TIME );
}
}
Of course, the above is just a simple method to describe this principle.

(3) Enable Automatic English Reading
Automatic Reading is actually the process of responding to the clipboard message. When the selected text information is copied, the system automatically sends the WM_DRAWCLIPBOARD
The message is sent to all the window in the clipboard monitoring queue. The corresponding window only needs to read the information in the current clipboard. The specific implementation is as follows:

Install clipboard monitoring:
Void InstallClipSpy ()
{
G_hNextWnd = SetClipboardViewer (g_hMainWnd );
}

The corresponding clipboard message in the callback function of the main window:
Lresult callback WndProc (HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
{
// The clipboard window queue has changed.
Case WM_CHANGECBCHAIN:
HwndRemove = (HWND) wParam; // handle of window being removed
HwndNext = (HWND) lParam;
If (hwndRemove = g_hNextWnd)
{
G_hNextWnd = hwndNext;
}
If (g_hNextWnd)
{
SendMessage (hwndNext, WM_CHANGECBCHAIN, wParam, lParam );
}
// The Clipboard data changes.
Case WM_DRAWCLIPBOARD:
// Automatic reading?
If (g_bEnableRead)
{
// Read the clipboard Information
ReadClipText ();
}
If (g_hNextWnd)
{
SendMessage (g_hNextWnd, WM_DRAWCLIPBOARD, wParam, lParam );
}
Obtain the clipboard information and read it aloud:
Void ReadClipText ()
{
If (g_bAgentOK)
{
// Read only text files
If (IsClipboardFormatAvailable (CF_TEXT ))
{

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.