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

📄 msagentdlg.cpp

📁 vc编写的精灵显示源码
💻 CPP
字号:
// MSAgentDlg.cpp : implementation file
//

#include "stdafx.h"
#include "MSAgent.h"
#include "MSAgentDlg.h"

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

/////////////////////////////////////////////////////////////////////////////
// CAboutDlg dialog used for App About

class CAboutDlg : public CDialog
{
public:
	CAboutDlg();

// Dialog Data
	//{{AFX_DATA(CAboutDlg)
	enum { IDD = IDD_ABOUTBOX };
	//}}AFX_DATA

	// ClassWizard generated virtual function overrides
	//{{AFX_VIRTUAL(CAboutDlg)
	protected:
	virtual void DoDataExchange(CDataExchange* pDX);    // DDX/DDV support
	//}}AFX_VIRTUAL

// Implementation
protected:
	//{{AFX_MSG(CAboutDlg)
	//}}AFX_MSG
	DECLARE_MESSAGE_MAP()
};

CAboutDlg::CAboutDlg() : CDialog(CAboutDlg::IDD)
{
	//{{AFX_DATA_INIT(CAboutDlg)
	//}}AFX_DATA_INIT
}

void CAboutDlg::DoDataExchange(CDataExchange* pDX)
{
	CDialog::DoDataExchange(pDX);
	//{{AFX_DATA_MAP(CAboutDlg)
	//}}AFX_DATA_MAP
}

BEGIN_MESSAGE_MAP(CAboutDlg, CDialog)
	//{{AFX_MSG_MAP(CAboutDlg)
		// No message handlers
	//}}AFX_MSG_MAP
END_MESSAGE_MAP()

/////////////////////////////////////////////////////////////////////////////
// CMSAgentDlg dialog

CMSAgentDlg::CMSAgentDlg(CWnd* pParent /*=NULL*/)
	: CDialog(CMSAgentDlg::IDD, pParent)
{
	//{{AFX_DATA_INIT(CMSAgentDlg)
	m_strSpeak = _T("");
	m_strInfo = _T("");
	m_nX = 0;
	m_nY = 0;
	m_nAutoHide = 1;
	m_nButtons = 2;
	m_strTitle = _T("This is a title");
	m_strText = _T("And this is a text");
	m_bCheckBox = FALSE;
	m_bTextBox = FALSE;
	m_nRadios = 2;
	m_bIcon = FALSE;
	//}}AFX_DATA_INIT
	// Note that LoadIcon does not require a subsequent DestroyIcon in Win32
	m_hIcon = AfxGetApp()->LoadIcon(IDR_MAINFRAME);
	m_nX = 200;
	m_nY = 200;
}

void CMSAgentDlg::DoDataExchange(CDataExchange* pDX)
{
	CDialog::DoDataExchange(pDX);
	//{{AFX_DATA_MAP(CMSAgentDlg)
	DDX_Control(pDX, IDC_ANIMATIONS, m_ctrlAnimations);
	DDX_Text(pDX, IDC_TEXTSPEAK, m_strSpeak);
	DDX_Text(pDX, IDC_INFO2, m_strInfo);
	DDX_Text(pDX, IDC_X, m_nX);
	DDX_Text(pDX, IDC_Y, m_nY);
	DDX_Text(pDX, IDC_TIPAUTOHIDE, m_nAutoHide);
	DDX_Text(pDX, IDC_BUTTONSN, m_nButtons);
	DDX_Text(pDX, IDC_TITLE, m_strTitle);
	DDX_Text(pDX, IDC_TEXT, m_strText);
	DDX_Check(pDX, IDC_CHECKBOXE, m_bCheckBox);
	DDX_Check(pDX, IDC_TEXTBOXE, m_bTextBox);
	DDX_Text(pDX, IDC_RADION, m_nRadios);
	DDX_Check(pDX, IDC_ICONE, m_bIcon);
	//}}AFX_DATA_MAP
}

BEGIN_MESSAGE_MAP(CMSAgentDlg, CDialog)
	//{{AFX_MSG_MAP(CMSAgentDlg)
	ON_WM_SYSCOMMAND()
	ON_WM_PAINT()
	ON_WM_QUERYDRAGICON()
	ON_BN_CLICKED(IDC_SPEAK, OnSpeak)
	ON_BN_CLICKED(IDC_PLAY, OnPlay)
	ON_BN_CLICKED(IDC_STOP, OnStop)
	ON_LBN_DBLCLK(IDC_ANIMATIONS, OnDblclkAnimations)
	ON_BN_CLICKED(IDC_SHOWHIDE, OnShowHide)
	ON_BN_CLICKED(IDC_MOVETO, OnMoveTo)
	ON_BN_CLICKED(IDC_GESTUREAT, OnGestureAt)
	ON_BN_CLICKED(IDC_TIP, OnTip)
	ON_BN_CLICKED(IDC_SHOWINPUT, OnShowInput)
	ON_BN_CLICKED(IDABOUT, OnAbout)
	//}}AFX_MSG_MAP
END_MESSAGE_MAP()

/////////////////////////////////////////////////////////////////////////////
// CMSAgentDlg message handlers

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

	// Add "About..." menu item to system menu.

	// IDM_ABOUTBOX must be in the system command range.
	ASSERT((IDM_ABOUTBOX & 0xFFF0) == IDM_ABOUTBOX);
	ASSERT(IDM_ABOUTBOX < 0xF000);

	CMenu* pSysMenu = GetSystemMenu(FALSE);
	if (pSysMenu != NULL)
	{
		CString strAboutMenu;
		strAboutMenu.LoadString(IDS_ABOUTBOX);
		if (!strAboutMenu.IsEmpty())
		{
			pSysMenu->AppendMenu(MF_SEPARATOR);
			pSysMenu->AppendMenu(MF_STRING, IDM_ABOUTBOX, strAboutMenu);
		}
	}

	// 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
	
	// Init MsAgent
	try
	{
		m_pSink = new CSink();
		m_cAgent.Init ( m_pSink );
		m_cAgent.LoadCharacter ( "merlin.acs", &m_cAgent.m_lDefaultCharID );
		m_cAgent.SetLanguageID (0x0409 );
		
		CString strName;
		m_cAgent.GetCharacterInfo( &strName, NULL );
		m_strSpeak.Format("hello,I'm %s!", strName);

		// Enum animations
		CString strAnimations;
		m_cAgent.GetAnimationNames( &strAnimations );
		while (TRUE)
		{
			int nPos = strAnimations.Find( ';' );
			if (nPos == -1 ) break;	// No more animations

			m_ctrlAnimations.AddString( strAnimations.Left( nPos ) );
			
			strAnimations.Delete(0, nPos +1 );
		}

		OnShowHide();
	}
	catch (int *pErr)
	{
		// An error
		MessageBox ("Init err");
		PostQuitMessage( 0 );
		delete pErr;
	}

	
	return TRUE;  // return TRUE  unless you set the focus to a control
}

void CMSAgentDlg::OnSysCommand(UINT nID, LPARAM lParam)
{
	if ((nID & 0xFFF0) == IDM_ABOUTBOX)
	{
		CAboutDlg dlgAbout;
		dlgAbout.DoModal();
	}
	else
	{
		CDialog::OnSysCommand(nID, lParam);
	}
}

// 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 CMSAgentDlg::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 CMSAgentDlg::OnQueryDragIcon()
{
	return (HCURSOR) m_hIcon;
}

void CMSAgentDlg::OnSpeak() 
{
	UpdateData();
	m_cAgent.Speak( m_strSpeak );
}

void CMSAgentDlg::OnPlay() 
{
	int nSel = m_ctrlAnimations.GetCurSel();
	if (nSel == -1) return;

	CString strAnimations;
	m_ctrlAnimations.GetText( nSel, strAnimations );
	try 
	{
		m_cAgent.Play( strAnimations );
	}
	catch (int *pErr)
	{
		MessageBox ("Play err");
		delete pErr;
	}
	
}

void CMSAgentDlg::OnStop() 
{
	try 
	{
		m_cAgent.StopAll(  );
	}
	catch (int *pErr)
	{
		MessageBox ("Stop err");
		delete pErr;
	}

}

void CMSAgentDlg::OnDblclkAnimations() 
{
	OnPlay();	
}

void CMSAgentDlg::UpdateInfo()
{
	CString strInfo;
	short sMajor, sMinor;
	CString strName, strDescription;
	POINT point;

	try
	{
		// Version
		m_cAgent.GetVersion( &sMajor, &sMinor );
		strInfo.Format("%d.%d\n", sMajor, sMinor );
		m_strInfo = strInfo;

		if ( m_cAgent.IsInit() )
			m_strInfo += "是\n";
		else
			m_strInfo += "否\n";
		
		if ( m_cAgent.GetVisible() )
			m_strInfo += "显示\n";
		else
			m_strInfo += "隐藏\n";

		// Position
		point = m_cAgent.GetPosition();
		strInfo.Format("x: %d, y: %d\n", point.x, point.y);
		m_strInfo += strInfo;

		// Name and description
		m_cAgent.GetCharacterInfo( &strName, &strDescription );
		strInfo.Format("%s\n", strName);
		m_strInfo += strInfo;
		strInfo.Format("%s\n", strDescription);
		m_strInfo += strInfo;
		
	}
	catch (int *pErr)
	{
		MessageBox ("Info err");
		delete pErr;
	}

	UpdateData( false );
}

void CMSAgentDlg::OnShowHide() 
{
	try 
	{
		if ( m_cAgent.GetVisible() )
			GetDlgItem( IDC_SHOWHIDE )->SetWindowText( "显示" );
		else
			GetDlgItem( IDC_SHOWHIDE )->SetWindowText( "隐藏" );

		m_cAgent.Show( !m_cAgent.GetVisible() );
	}
	catch (int *pErr)
	{
		MessageBox ("Show\\Hide err");
		delete pErr;
	}
		
}

void CMSAgentDlg::OnMoveTo() 
{
	UpdateData();
	try
	{
		m_cAgent.MoveTo( m_nX, m_nY );
	}
	catch (int *pErr)
	{
		MessageBox ("MoveTo err");
		delete pErr;
	}
}

void CMSAgentDlg::OnGestureAt() 
{
	UpdateData();
	try
	{
		m_cAgent.GestureAt( m_nX, m_nY );
	}
	catch (int *pErr)
	{
		MessageBox ("GestureAt err");
		delete pErr;
	}
}

void CMSAgentDlg::OnTip() 
{
	UpdateData();
	try
	{
		m_cAgent.GetTip()->ShowTip( TRUE, ( m_nAutoHide > 0 ? m_nAutoHide : INFINITE) );
	}
	catch (int *pErr)
	{
		MessageBox ("ShowTip err");
		delete pErr;
	}		
}

void CMSAgentDlg::OnShowInput() 
{
	UpdateData();
	try
	{
		DWORD dwFlags = 0;
		if ( m_bCheckBox ) dwFlags |= BI_CHECKBOX; 
		if ( m_bTextBox ) dwFlags |= BI_TEXTBOX;
		m_bIcon ? m_cAgent.GetInputBalloon()->m_hIcon = m_hIcon : NULL;

		m_cAgent.GetInputBalloon()->SetUpControls( m_nButtons, m_nRadios, dwFlags );
		m_cAgent.GetInputBalloon()->m_strTitle = m_strTitle;
		m_cAgent.GetInputBalloon()->m_strText = m_strText;
		m_cAgent.GetInputBalloon()->SetPosition(  );
		m_cAgent.GetInputBalloon()->Show( m_hWnd );
	}
	catch (int *pErr)
	{
		MessageBox ("InputBalloon err");
		delete pErr;
	}		
}

void CMSAgentDlg::OnAbout() 
{
	CAboutDlg dlgAbout;
	dlgAbout.DoModal();	
}

⌨️ 快捷键说明

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