www.pudn.com > ruier_TTS_SR(vc6).rar > SRDLG.cpp


// SRDLG.cpp : implementation file 
// 
 
#include "stdafx.h" 
#include "TTS_SR.h" 
#include "SRDLG.h" 
 
#ifdef _DEBUG 
#define new DEBUG_NEW 
#undef THIS_FILE 
static char THIS_FILE[] = __FILE__; 
#endif 
 
///////////////////////////////////////////////////////////////////////////// 
// CSRDLG dialog 
 
 
CSRDLG::CSRDLG(CWnd* pParent /*=NULL*/) 
	: CDialog(CSRDLG::IDD, pParent) 
{ 
	//{{AFX_DATA_INIT(CSRDLG) 
		// NOTE: the ClassWizard will add member initialization here 
	//}}AFX_DATA_INIT 
} 
 
 
void CSRDLG::DoDataExchange(CDataExchange* pDX) 
{ 
	CDialog::DoDataExchange(pDX); 
	//{{AFX_DATA_MAP(CSRDLG) 
	DDX_Control(pDX, IDC_EDIT_SR, m_Edit_SR); 
	//}}AFX_DATA_MAP 
} 
 
 
BEGIN_MESSAGE_MAP(CSRDLG, CDialog) 
	//{{AFX_MSG_MAP(CSRDLG) 
	ON_BN_CLICKED(IDC_BUTTON_START_SR, OnButtonStartSr) 
	ON_MESSAGE(WM_SREVENT, OnSREvent) 
	//}}AFX_MSG_MAP 
END_MESSAGE_MAP() 
 
///////////////////////////////////////////////////////////////////////////// 
// CSRDLG message handlers 
 
void CSRDLG::OnButtonStartSr()  
{ 
	// TODO: Add your control notification handler code here 
 
	CString s; 
	((CButton *)GetDlgItem(IDC_BUTTON_START_SR))->GetWindowText(s); 
 
 
	if(s=="开始"){ 
		sr.SetVoice(this->m_hWnd,IDC_COMBO_SR); 
		((CWnd *)(this->GetDlgItem(IDC_COMBO_SR)))->EnableWindow(FALSE); 
		((CWnd *)GetDlgItem(IDC_BUTTON_START_SR))->SetWindowText("停止"); 
 
		if(fir){ 
				((CWnd *)GetDlgItem(IDC_STATIC_STATE))->SetWindowText("状态:配置向导...."); 
		int u=MessageBox("这也许是您第一次使用语音识别,强烈建议您运行配置向导以配置相关选项。\n是否运行配置向导?","语音识别",MB_YESNO|MB_ICONQUESTION);		 
			if(u==IDYES)  
			{ 
			sr.MicrophoneSetup(m_hWnd); 
			sr.VoiceTraining(m_hWnd); 
			} 
		} 
		((CWnd *)GetDlgItem(IDC_STATIC_STATE))->SetWindowText("状态:听写...."); 
		sr.Start(); 
	}else{ 
		((CWnd *)GetDlgItem(IDC_STATIC_STATE))->SetWindowText("状态:就绪"); 
		((CWnd *)(this->GetDlgItem(IDC_COMBO_SR)))->EnableWindow(TRUE); 
		((CWnd *)GetDlgItem(IDC_BUTTON_START_SR))->SetWindowText("开始"); 
		sr.Stop(); 
	} 
	 
} 
 
BOOL CSRDLG::OnInitDialog()  
{ 
	CDialog::OnInitDialog(); 
	 
	// TODO: Add extra initialization here 
	fir=TRUE; 
	sr.Initialize(this->m_hWnd,IDC_COMBO_SR); 
	 
	sr.Stop(); 
	return TRUE;  // return TRUE unless you set the focus to a control 
	              // EXCEPTION: OCX Property Pages should return FALSE 
} 
 
 
LRESULT CSRDLG::OnSREvent(WPARAM, LPARAM) 
{ 
	 
    WCHAR *pwzText; 
    sr.GetText(&pwzText); 
    m_strText += CString(pwzText); 
	m_Edit_SR.SetWindowText(m_strText); 
	CString pd("状态:听写...."); 
		 
		pd+=pwzText; 
	((CWnd *)GetDlgItem(IDC_STATIC_STATE))->SetWindowText(pd); 
 
	 
    UpdateData(FALSE); 
    return 0L; 
}