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

📄 agt3dlg.cpp

📁 ms_agent操作
💻 CPP
字号:
// agt3Dlg.cpp : implementation file
//
/*
purpose:
Manipulating the msAgent Ctrl in VC is a hard work.
so I work with a wrap ctrl(MsAgentWrap.ocx) , i developed the wrap ctrl with VB.
It is seem to be more easy to take the advantage of msAgent ctrl.

MS Agent Demo
this demo source will show you how to use the wrap ctrl,
and the error handle.

by wenyy, wyy_cq@21cn.com, http://vchelp.163.net
the wrap control and the source code is absolutely free.
but if you modify my code and distribute the modified, 
you must add the comment to the modified place.

*/
#include "stdafx.h"
#include "agt3.h"
#include "agt3Dlg.h"

#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif

/////////////////////////////////////////////////////////////////////////////
// CAgt3Dlg dialog

CAgt3Dlg::CAgt3Dlg(CWnd* pParent /*=NULL*/)
	: CDialog(CAgt3Dlg::IDD, pParent)
{
	//{{AFX_DATA_INIT(CAgt3Dlg)
	m_x = 0;
	m_y = 0;
	//}}AFX_DATA_INIT
	// Note that LoadIcon does not require a subsequent DestroyIcon in Win32
	m_hIcon = AfxGetApp()->LoadIcon(IDR_MAINFRAME);
}

void CAgt3Dlg::DoDataExchange(CDataExchange* pDX)
{
	CDialog::DoDataExchange(pDX);
	//{{AFX_DATA_MAP(CAgt3Dlg)
	DDX_Control(pDX, IDC_VCHELPMSAGENTWRAP1, m_agent);
	DDX_Text(pDX, IDC_X, m_x);
	DDV_MinMaxUInt(pDX, m_x, 0, 400);
	DDX_Text(pDX, IDC_Y, m_y);
	DDV_MinMaxUInt(pDX, m_y, 0, 400);
	//}}AFX_DATA_MAP
}

BEGIN_MESSAGE_MAP(CAgt3Dlg, CDialog)
	//{{AFX_MSG_MAP(CAgt3Dlg)
	ON_WM_PAINT()
	ON_WM_QUERYDRAGICON()
	ON_BN_CLICKED(IDC_SH, OnSh)
	ON_BN_CLICKED(IDC_PLAY, OnPlay)
	ON_BN_CLICKED(IDC_SPEAK, OnSpeak)
	ON_BN_CLICKED(IDC_GUES, OnGues)
	ON_BN_CLICKED(IDC_MOVE, OnMove)
	ON_BN_CLICKED(IDC_STOP, OnStop)
	ON_BN_CLICKED(IDC_EH, OnEh)
	//}}AFX_MSG_MAP
END_MESSAGE_MAP()

/////////////////////////////////////////////////////////////////////////////
// CAgt3Dlg message handlers

BOOL CAgt3Dlg::OnInitDialog()
{
	CDialog::OnInitDialog();

	// Set the icon for this dialog.  The framework does this automatically
	//  when the application's main window is not a dialog
	SetIcon(m_hIcon, TRUE);			// Set big icon
	SetIcon(m_hIcon, FALSE);		// Set small icon
	
	// TODO: Add extra initialization here
	CString szP("d:\\WINDOWS\\MSAGENT\\CHARS\\merlin.acs");
	m_agent.LoadChar(szP);
	return TRUE;  // return TRUE  unless you set the focus to a control
}

// If you add a minimize button to your dialog, you will need the code below
//  to draw the icon.  For MFC applications using the document/view model,
//  this is automatically done for you by the framework.

void CAgt3Dlg::OnPaint() 
{
	if (IsIconic())
	{
		CPaintDC dc(this); // device context for painting

		SendMessage(WM_ICONERASEBKGND, (WPARAM) dc.GetSafeHdc(), 0);

		// Center icon in client rectangle
		int cxIcon = GetSystemMetrics(SM_CXICON);
		int cyIcon = GetSystemMetrics(SM_CYICON);
		CRect rect;
		GetClientRect(&rect);
		int x = (rect.Width() - cxIcon + 1) / 2;
		int y = (rect.Height() - cyIcon + 1) / 2;

		// Draw the icon
		dc.DrawIcon(x, y, m_hIcon);
	}
	else
	{
		CDialog::OnPaint();
	}
}

// The system calls this to obtain the cursor to display while the user drags
//  the minimized window.
HCURSOR CAgt3Dlg::OnQueryDragIcon()
{
	return (HCURSOR) m_hIcon;
}

void CAgt3Dlg::OnSh() 
{
	m_agent.Show(((CButton*)GetDlgItem(IDC_SH))->GetCheck());
}

void CAgt3Dlg::OnPlay() 
{
	m_agent.Play("DoMagic2");
}

void CAgt3Dlg::OnSpeak() 
{
	m_agent.Speak("hello , this is agent!");
}

void CAgt3Dlg::OnGues() 
{
	UpdateData();
	m_agent.GestureAt(m_x,m_y);
}

void CAgt3Dlg::OnMove() 
{
	UpdateData();
	m_agent.MoveTo(m_x,m_y);
}

void CAgt3Dlg::OnStop() 
{
	m_agent.StopAll();	
}

void CAgt3Dlg::OnEh() 
{
	TRY
	{
		m_agent.Play("DoMagic4");
	}
	CATCH(CException, e)
	{
		char szBuf[100];
		e->GetErrorMessage(szBuf,100);
		strcat(szBuf,"\n - caught error");
		AfxMessageBox(szBuf);
		e->Delete();
	}
	END_CATCH
}

⌨️ 快捷键说明

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