?? customwavfile.cpp
字號:
// CustomWavFile.cpp : implementation file
//
//Modify by 徐景周 2000.10
//功能:自定制情話及文字
#include "stdafx.h"
#include "scrgenius.h"
#include "CustomWavFile.h"
#include "AnimEffect.h" //對話框動畫效果顯示
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
CString strOpenWavName=""; //情話文件名
CString strWavFile=""; //不含路徑的情話文件名
bool bOriginWavPlay=true; //是否播放原始的情話標志位
CString strPath=""; //主執行程序所在的路徑
/////////////////////////////////////////////////////////////////////////////
// CCustomWavFile dialog
CCustomWavFile::CCustomWavFile(CWnd* pParent /*=NULL*/)
: CDialog(CCustomWavFile::IDD, pParent)
{
//{{AFX_DATA_INIT(CCustomWavFile)
m_TextDescription = _T("");
m_FilePathString1 = _T("");
//}}AFX_DATA_INIT
bOriginWavPlay=true; //是否恢復原始情話文件的初始值為真
}
void CCustomWavFile::DoDataExchange(CDataExchange* pDX)
{
CDialog::DoDataExchange(pDX);
//{{AFX_DATA_MAP(CCustomWavFile)
DDX_Control(pDX, IDC_EDIT2, m_TextDescriptionEdit);
DDX_Text(pDX, IDC_EDIT2, m_TextDescription);
DDV_MaxChars(pDX, m_TextDescription, 40);
DDX_Text(pDX, IDC_EDIT1, m_FilePathString1); //情話文件一編輯框變量
DDX_Control(pDX, IDOK, m_OK);
DDX_Control(pDX, IDCANCEL, m_Cancel);
//}}AFX_DATA_MAP
}
BEGIN_MESSAGE_MAP(CCustomWavFile, CDialog)
//{{AFX_MSG_MAP(CCustomWavFile)
ON_BN_CLICKED(IDC_FILEBROWSER1, OnFilebrowser1)
ON_WM_SHOWWINDOW()
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// CCustomWavFile message handlers
void CCustomWavFile::OnFilebrowser1()
{
CFileDialog fileDialog(TRUE,NULL,NULL,NULL,"情話文件(*.wav)|*.wav||");
if (fileDialog.DoModal() == IDOK) {
strOpenWavName = fileDialog.GetPathName(); //含路徑
strWavFile=fileDialog.GetFileName(); //不含路徑
m_FilePathString1 = strOpenWavName;
UpdateData(FALSE);
}
}
void CCustomWavFile::OnOK()
{
m_TextDescriptionEdit.GetWindowText(m_TextDescription); //賦字符值
if (strOpenWavName.IsEmpty() && m_TextDescription =="")
{
AfxMessageBox("\n 抱歉,情話文件名和文字不能同時為空!\r\n 否則,請按恢復按鈕來恢復原始情話. ");
return;
}
bOriginWavPlay=false; //播放定制的情話.
if(strWavFile!=""||m_TextDescription!="")
{
//建一數據文件,保存當前文件名(不含路徑),第二次運行程序時自動播放
CStdioFile TxtFile;
//創建情話數據文件,保存路徑設為主執行程序所在路徑
if (!TxtFile.Open(strPath+ "\\lovepet.dat", CFile::modeCreate | CFile::modeWrite | CFile::typeText))
{
CString strErrorMessage;
strErrorMessage = "創建情話數據文件: "+strPath+"lovepet.dat 失敗 !";
AfxMessageBox(strErrorMessage);
}
else
{
//寫入情話文件名(不含路徑,及默認當前路徑,好一起發給對方)和文字表達
if(strWavFile!="" && m_TextDescription!="")
{
TxtFile.WriteString(strWavFile);
TxtFile.WriteString ("$$$");
TxtFile.WriteString (m_TextDescription);
}
else if(m_TextDescription!="")
{
TxtFile.WriteString ("$$$");
TxtFile.WriteString (m_TextDescription);
}
else
{
TxtFile.WriteString(strWavFile);
TxtFile.WriteString ("$$$");
}
TxtFile.Close();
}
}
CDialog::OnOK();
}
//獲取選中的情話文件名
CString CCustomWavFile::GetWaveFile()
{
CString sWaveFile="";
if(strOpenWavName!="")
sWaveFile=strOpenWavName;
return sWaveFile;
}
//獲取是否播放定制情話文件標志
bool CCustomWavFile::GetOriginPlayFlag ()
{
bool bOriginWavePlayFlag=true;
if(!bOriginWavPlay)
bOriginWavePlayFlag=bOriginWavPlay;
return bOriginWavePlayFlag;
}
void CCustomWavFile::OnCancel()
{
CStdioFile TxtFile;
//情話數據文件存在,則刪除它
if (TxtFile.Open(strPath+"\\lovepet.dat", CFile::modeRead|CFile::typeText))
{
TxtFile.Close();
//在恢復原始情話時,刪除自定制情話數據文件
TxtFile.Remove(strPath+"\\lovepet.dat");
}
CDialog::OnCancel();
}
BOOL CCustomWavFile::OnInitDialog()
{
CDialog::OnInitDialog();
//此處獲取主程序所在路徑,存在全局變量strPath中
GetModuleFileName(NULL,strPath.GetBufferSetLength (MAX_PATH+1),MAX_PATH);
strPath.ReleaseBuffer ();
int nPos;
nPos=strPath.ReverseFind ('\\');
strPath=strPath.Left (nPos);
//在此將文件瀏覽按鈕設為扁平狀,顏色和自定義窗體色相同
m_SourceFile.SubclassDlgItem(IDC_FILEBROWSER1, this);
m_SourceFile.SetActiveBgColor(RGB(240,200,90));
m_SourceFile.SetInactiveBgColor(RGB(240,200,90));
m_SourceFile.SetTooltipText(IDS_TOOLTIP_BROWER);
m_SourceFile.SetIcon(IDI_FILEOPEN);
// m_SourceFile.SetFlat(FALSE); //不扁平顯示
m_SourceFile.SetBtnCursor(IDC_HAND);
return TRUE; // return TRUE unless you set the focus to a control
// EXCEPTION: OCX Property Pages should return FALSE
}
BOOL CCustomWavFile::DestroyWindow()
{
CRect rc4; //對話框動畫顯示效果
AnimEffect anim4;
//在此加入對話框動畫關閉效果
GetWindowRect(rc4 );
rc4.DeflateRect(2,2);//動態方框顯示
anim4.DrawWireRects(rc4, CRect(rc4.CenterPoint().x-10,rc4.CenterPoint().y-10,rc4.CenterPoint().x+10,rc4.CenterPoint().y+10 ), 10);
// anim4.Close(rc4); ////對話框動畫效果顯示關閉
// Sleep(50); //延緩50毫秒后關閉
return CDialog::DestroyWindow();
}
void CCustomWavFile::OnShowWindow(BOOL bShow, UINT nStatus)
{
CDialog::OnShowWindow(bShow, nStatus);
CRect rc4; //對話框動畫顯示效果
AnimEffect anim4;
//在此加入對話框動畫打開效果
GetWindowRect(rc4 );
anim4.Open( rc4 ); //對話框動畫效果顯示打開
}
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -