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


// TTDLG.cpp : implementation file 
// 
 
#include "stdafx.h" 
#include "TTS_SR.h" 
#include "TTDLG.h" 
 
#ifdef _DEBUG 
#define new DEBUG_NEW 
#undef THIS_FILE 
static char THIS_FILE[] = __FILE__; 
#endif 
 
///////////////////////////////////////////////////////////////////////////// 
// CTTDLG dialog 
 
 
CTTDLG::CTTDLG(CWnd* pParent /*=NULL*/) 
	: CDialog(CTTDLG::IDD, pParent) 
{ 
	//{{AFX_DATA_INIT(CTTDLG) 
	mv_Edit = _T(""); 
	//}}AFX_DATA_INIT 
} 
 
 
void CTTDLG::DoDataExchange(CDataExchange* pDX) 
{ 
	CDialog::DoDataExchange(pDX); 
	//{{AFX_DATA_MAP(CTTDLG) 
	DDX_Control(pDX, IDC_SLIDER_VO_TT, mc_Slider_VO_TT); 
	DDX_Control(pDX, IDC_SLIDER_RATE_TT, mc_Slider_RA_TT); 
	DDX_Control(pDX, IDC_EDIT_TT, mc_Edit_TT); 
	DDX_Text(pDX, IDC_EDIT_TT, mv_Edit); 
	//}}AFX_DATA_MAP 
} 
 
 
BEGIN_MESSAGE_MAP(CTTDLG, CDialog) 
	//{{AFX_MSG_MAP(CTTDLG) 
	ON_BN_CLICKED(IDC_BUTTON_START_TT, OnButtonStartTt) 
	ON_MESSAGE(WM_TTSEVENT, OnSpeakEvent) 
	ON_NOTIFY(NM_RELEASEDCAPTURE, IDC_SLIDER_RATE_TT, OnReleasedcaptureSliderRateTt) 
	ON_NOTIFY(NM_RELEASEDCAPTURE, IDC_SLIDER_VO_TT, OnReleasedcaptureSliderVoTt) 
	ON_BN_CLICKED(IDC_BUTTON_PAUSE_TT, OnButtonPauseTt) 
	//}}AFX_MSG_MAP 
END_MESSAGE_MAP() 
 
///////////////////////////////////////////////////////////////////////////// 
// CTTDLG message handlers 
 
void CTTDLG::OnButtonStartTt()  
{ 
	// TODO: Add your control notification handler code here 
	CString s; 
	((CButton *)GetDlgItem(IDC_BUTTON_START_TT))->GetWindowText(s); 
 
 
	if(s=="开始"){ 
		if(!mc_Edit_TT.GetWindowTextLength())  
		{ 
 
			MessageBox("尚未输入任何字符","错误",MB_ICONERROR); 
			return ; 
 
		} 
			t2s.SetVoice(this->m_hWnd,IDC_COMBO_TT); 
			((CWnd *)GetDlgItem(IDC_BUTTON_START_TT))->SetWindowText("结束"); 
			((CWnd *)(this->GetDlgItem(IDC_COMBO_TT)))->EnableWindow(FALSE); 
			((CWnd *)(this->GetDlgItem(IDC_BUTTON_PAUSE_TT)))->EnableWindow(TRUE); 
			mc_Edit_TT.SetReadOnly(); 
 
		 
	 
 
		 
 
		LPWSTR lpszW = new WCHAR[mc_Edit_TT.GetWindowTextLength()+1]; 
		char* cf=new char[mc_Edit_TT.GetWindowTextLength()+1] ; 
		mc_Edit_TT.GetWindowText(cf,mc_Edit_TT.GetWindowTextLength()+1); 
	 
		char* cw=" we"; 
		LPTSTR lpStr1 = (LPTSTR)cf; 
		nLen = MultiByteToWideChar (CP_ACP, 0, lpStr1, -1,NULL, NULL)-1; 
		 
		strcat(cf,cw); 
		 
	 
		 
	 
 
		LPTSTR lpStr = (LPTSTR)cf; 
	 
 
		int inLen = MultiByteToWideChar (CP_ACP, 0, lpStr, -1,NULL, NULL); 
 
	/*	char* o=new char[5]; 
		itoa(nLen,o,10); 
	//	MessageBox(o);	*/ 
 
 
		MultiByteToWideChar(CP_ACP, 0, lpStr, -1, lpszW, inLen); 
		 
		t2s.Speak(lpszW,SPF_ASYNC); 
		mc_Edit_TT.SetFocus(); 
	}else{ 
		 ((CWnd *)GetDlgItem(IDC_BUTTON_START_TT))->SetWindowText("开始"); 
 
		 ((CWnd *)(this->GetDlgItem(IDC_COMBO_TT)))->EnableWindow(TRUE); 
		((CWnd *)(this->GetDlgItem(IDC_BUTTON_PAUSE_TT)))->EnableWindow(FALSE); 
		mc_Edit_TT.SetReadOnly(FALSE); 
		t2s.Stop(); 
		mc_Edit_TT.SetFocus(); 
		mc_Edit_TT.SetSel(0,-1); 
	 
	} 
 
 
	 
	 
} 
 
void CTTDLG::OnReleasedcaptureSliderRateTt(NMHDR* pNMHDR, LRESULT* pResult)  
{ 
	// TODO: Add your control notification handler code here 
	t2s.SetRate(mc_Slider_RA_TT.GetPos()); 
	mc_Edit_TT.SetFocus(); 
	*pResult = 0; 
} 
void CTTDLG::OnReleasedcaptureSliderVoTt(NMHDR* pNMHDR, LRESULT* pResult)  
{ 
	// TODO: Add your control notification handler code here 
	t2s.SetVolume(mc_Slider_VO_TT.GetPos()-10); 
	mc_Edit_TT.SetFocus(); 
	*pResult = 0; 
} 
 
BOOL CTTDLG::OnInitDialog()  
{ 
	CDialog::OnInitDialog(); 
	 
	// TODO: Add extra initialization here 
 
	t2s.Initialize(this->m_hWnd,IDC_COMBO_TT); 
	mc_Slider_RA_TT.SetRange(0,20); 
	long n=0; 
	t2s.GetRate(&n); 
	 
 
	mc_Slider_VO_TT.SetRange(0,100); 
	unsigned short m=0; 
	t2s.GetVolume(&m); 
	mc_Slider_VO_TT.SetPos(m); 
	mc_Slider_RA_TT.SetPos((int)n+10); 
	return TRUE;  // return TRUE unless you set the focus to a control 
	              // EXCEPTION: OCX Property Pages should return FALSE 
 
 
 
} 
 
LRESULT CTTDLG::OnSpeakEvent(WPARAM wParam, LPARAM lParam)  
{ 
     
 
 
	t2s.PrcEvent(wParam,lParam,this,nLen); 
    return 0; 
 
} 
 
 
 
void CTTDLG::OnButtonPauseTt()  
{ 
	// TODO: Add your control notification handler code here 
	CString s; 
	((CButton *)GetDlgItem(IDC_BUTTON_PAUSE_TT))->GetWindowText(s); 
 
 
	if(s=="暂停"){ 
		((CWnd *)(this->GetDlgItem(IDC_BUTTON_START_TT)))->EnableWindow(FALSE); 
		((CWnd *)GetDlgItem(IDC_BUTTON_PAUSE_TT))->SetWindowText("恢复"); 
		t2s.Pause(); 
	} 
	else{ 
		((CWnd *)GetDlgItem(IDC_BUTTON_PAUSE_TT))->SetWindowText("暂停"); 
		((CWnd *)(this->GetDlgItem(IDC_BUTTON_START_TT)))->EnableWindow(TRUE); 
		t2s.Resume(); 
	} 
	mc_Edit_TT.SetFocus(); 
}