www.pudn.com > VQ_Final.rar > Step2.cpp
// Step2.cpp : implementation file
//
#include "afxwin.h"
#include "afxctl.h"
#include "resource.h"
#include "Step2.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
UINT VQ(LPVOID ptr);
/////////////////////////////////////////////////////////////////////////////
// CStep2 property page
IMPLEMENT_DYNCREATE(CStep2, CPropertyPage)
CStep2::CStep2() : CPropertyPage(CStep2::IDD)
{
//{{AFX_DATA_INIT(CStep2)
//}}AFX_DATA_INIT
}
CStep2::~CStep2()
{
}
void CStep2::DoDataExchange(CDataExchange* pDX)
{
CPropertyPage::DoDataExchange(pDX);
//{{AFX_DATA_MAP(CStep2)
DDX_Control(pDX, IDC_VQINFO, m_sInfo);
DDX_Control(pDX, IDC_VQPRG, m_prgVQ);
//}}AFX_DATA_MAP
}
BEGIN_MESSAGE_MAP(CStep2, CPropertyPage)
//{{AFX_MSG_MAP(CStep2)
ON_BN_CLICKED(IDC_START, OnStart)
ON_BN_CLICKED(IDC_SHOWRESULT, OnShowresult)
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// CStep2 message handlers
BOOL CStep2::OnSetActive()
{
m_pSheet->SetWizardButtons(0); //先不让用户点“下一步”
return CPropertyPage::OnSetActive();
}
void CStep2::OnStart()
{
char szFilters[]="VQ结果文件 (*.txt)|*.txt|";
CString t;
t=m_pSheet->m_sTitle+"的VQ结果.txt";
CFileDialog dlg(FALSE,"txt",t,OFN_HIDEREADONLY,szFilters,this);
m_prgVQ.SetRange(0,100);
m_prgVQ.SetPos(0);
if( dlg.DoModal()==IDOK)
{
m_pSheet->m_sVQ = dlg.GetPathName();
GetDlgItem(IDC_START)->EnableWindow(FALSE);
//启动写VQ结果的线程
m_pThread=AfxBeginThread(VQ,(LPVOID)this,THREAD_PRIORITY_NORMAL,0,0,NULL);
}
}
UINT VQ(LPVOID ptr) //写VQ结果的线程
{
CStep2 *pDlg=(CStep2 *)ptr;
CFile fVQ;
UINT i;
CString t;
//因为在上一步中矢量量化已经完成,结果在m_pVQ中,所以以下写入VQ结果。
pDlg->m_sInfo.SetWindowText("正在写入VQ结果......");
CFileException e;
if (!fVQ.Open(pDlg->m_pSheet->m_sVQ,CFile::modeCreate|CFile::modeWrite,&e))
{
e.ReportError();
return 1;
}
//先写入向量个数
t.Format("向量个数:%d 以下为向量的索引:\15\12",pDlg->m_pSheet->m_nNum);
fVQ.Write(t,t.GetLength());
for (i=0;im_pSheet->m_nNum;i++)
{
t.Format("[%5d]",pDlg->m_pSheet->m_pVQ[i]);
fVQ.Write(t,t.GetLength());
if ((i+1)%16==0) //每行16个 "\15\12"是换行
{
t.Format("\15\12");
fVQ.Write(t,t.GetLength());
}
pDlg->m_prgVQ.SetPos(i*100/pDlg->m_pSheet->m_nNum);
if (pDlg->m_bStopThread)
return 1;
}
fVQ.Close();
pDlg->m_sInfo.SetWindowText("VQ结果已经写入。");
pDlg->m_prgVQ.SetPos(100);
(CButton *)(pDlg->GetDlgItem(IDC_START))->EnableWindow(FALSE);
(CButton *)(pDlg->GetDlgItem(IDC_SHOWRESULT))->ShowWindow(SW_SHOW);
pDlg->m_pSheet->SetWizardButtons(PSWIZB_NEXT);
return 0;
}
BOOL CStep2::OnQueryCancel()
{
if (m_pThread)
{
m_bStopThread=TRUE;
m_sInfo.SetWindowText("正在结束线程......");
WaitForSingleObject(m_pThread->m_hThread,1);
}
return CPropertyPage::OnQueryCancel();
}
void CStep2::OnShowresult()
{
CString t="notepad ";
t+=m_pSheet->m_sVQ;
WinExec(t,SW_SHOW);
}