📄 eringdlg.cpp
字号:
// eRingDlg.cpp : implementation file
//
#include "stdafx.h"
#include "eRing.h"
#include "eRingDlg.h"
#include "Mmsystem.h"
//#include "AboutDlg.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
#define RINGTONEKEY L"ControlPanel\\Sounds\\RingTone0"
#define SCRIPT L"Script"
#define SCRIPTVALUE L"apw3r"
#define SOUND L"Sound"
#define CATEGORY L"Category"
#define CATEGORYVALUE L"Ring"
/////////////////////////////////////////////////////////////////////////////
// CERingDlg dialog
CERingDlg::CERingDlg(CWnd* pParent /*=NULL*/)
: CDialog(CERingDlg::IDD, pParent)
{
//{{AFX_DATA_INIT(CERingDlg)
//}}AFX_DATA_INIT
// Note that LoadIcon does not require a subsequent DestroyIcon in Win32
m_hIcon = AfxGetApp()->LoadIcon(IDR_MAINFRAME);
listWave.SetSize(0);
listSelect.SetSize(0);
listRing.SetSize(0);
sortStatus[0]=sortStatus[1]=sortStatus[2]=true;
beStop=false;
bAbout=false;
indexSort=-1;
bWait=FALSE;
count=0;
}
void CERingDlg::DoDataExchange(CDataExchange* pDX)
{
CDialog::DoDataExchange(pDX);
//{{AFX_DATA_MAP(CERingDlg)
DDX_Control(pDX, IDC_LISTWAVE, m_List);
//}}AFX_DATA_MAP
}
BEGIN_MESSAGE_MAP(CERingDlg, CDialog)
//{{AFX_MSG_MAP(CERingDlg)
ON_NOTIFY(LVN_ITEMCHANGED, IDC_LISTWAVE, OnItemchangedListwave)
ON_NOTIFY(LVN_COLUMNCLICK, IDC_LISTWAVE, OnColumnclickListwave)
ON_BN_CLICKED(IDC_PREVIEW, OnPreview)
ON_BN_CLICKED(IDC_STOP, OnStop)
ON_WM_SIZE()
ON_WM_PAINT()
ON_COMMAND(IDM_SETRINGTONE, OnSetRingTone)
ON_WM_ACTIVATE()
ON_WM_LBUTTONDOWN()
ON_WM_KEYDOWN()
ON_WM_CANCELMODE()
ON_WM_HELPINFO()
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// CERingDlg message handlers
BOOL CERingDlg::OnInitDialog()
{
CDialog::OnInitDialog();
// 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
CenterWindow(GetDesktopWindow()); // center to the hpc screen
// TODO: Add extra initialization here
m_List.SetNotifyWnd(this);
m_List.SetPoint(&m_Point);
ArrangeItems();
ListView_SetExtendedListViewStyle
(m_List.GetSafeHwnd(), LVS_EX_CHECKBOXES | LVS_EX_FULLROWSELECT);
CString suffix;
suffix.LoadString(IDS_SUFFIX);
InitList();
// m_List.DeleteAllItems();
// ReleaseData();
// listWave.RemoveAll();
// listRing.RemoveAll();
// count=0;
// ReFresh();
m_exit=true;
return TRUE; // return TRUE unless you set the focus to a control
}
void CERingDlg::OnItemchangedListwave(NMHDR* pNMHDR, LRESULT* pResult)
{
NM_LISTVIEW* pNMListView = (NM_LISTVIEW*)pNMHDR;
// TODO: Add your control notification handler code here
*pResult = 0;
if (pNMListView->uOldState == 0 && pNMListView->uNewState == 0)
return; // No change
BOOL bPrevState = (BOOL)(((pNMListView->uOldState &
LVIS_STATEIMAGEMASK)>>12)-1); // Old check box state
if (bPrevState < 0) // On startup there's no previous state
bPrevState = 0; // so assign as false (unchecked)
// New check box state
BOOL bChecked=(BOOL)(((pNMListView->uNewState & LVIS_STATEIMAGEMASK)>>12)-1);
if (bChecked < 0) // On non-checkbox notifications assume false
bChecked = 0;
if (bPrevState == bChecked) // No change in check box
return;
if (bChecked){
// m_List.SetItemState(pNMListView->iItem,LVNI_FOCUSED,LVNI_FOCUSED);
// m_List.SetItemState(pNMListView->iItem,LVNI_SELECTED,LVNI_SELECTED);
int idx=m_List.GetItemData(pNMListView->iItem);
// AddStrToArray(listSelect,listWave.GetAt(idx)->szPathName);
}
else{
// m_List.SetItemState(pNMListView->iItem,~LVNI_FOCUSED,LVNI_FOCUSED);
// m_List.SetItemState(pNMListView->iItem,~LVNI_SELECTED,LVNI_SELECTED);
int idx=m_List.GetItemData(pNMListView->iItem);
// DeleteStrFromArray(listSelect,listWave.GetAt(idx)->szPathName);
}
}
void CERingDlg::OnColumnclickListwave(NMHDR* pNMHDR, LRESULT* pResult)
{
NM_LISTVIEW* pNMListView = (NM_LISTVIEW*)pNMHDR;
// TODO: Add your control notification handler code here
*pResult = 0;
int idx;
LVCOLUMN lvc;
memset(&lvc,0,sizeof(lvc));
idx=pNMListView->iSubItem;
lvc.mask=LVCF_IMAGE;
ListView_GetColumn(m_List.GetSafeHwnd(),idx,&lvc);
sortStatus[idx]=!sortStatus[idx];
if (sortStatus[idx])
lvc.iImage=1;
else
lvc.iImage=2;
ListView_SetColumn(m_List.GetSafeHwnd(),idx,&lvc);
for (int i=1;i<3;i++){
int tmp=(idx+i)%3;
ListView_GetColumn(m_List.GetSafeHwnd(),tmp,&lvc);
lvc.iImage=0;
ListView_SetColumn(m_List.GetSafeHwnd(),tmp,&lvc);
}
switch(idx){
case 0:{
m_List.SortItems(CompareFunc_Name,(LPARAM) this);
break;
}
case 1:{
m_List.SortItems(CompareFunc_Date,(LPARAM) this);
break;
}
case 2:{
m_List.SortItems(CompareFunc_Size,(LPARAM) this);
break;
}
}
indexSort=idx;
}
//void CERingDlg::OnAbout()
//{
// // TODO: Add your control notification handler code here
// bAbout=true;
// CAboutDlg dlg(&bAbout);
// dlg.DoModal();
//}
DWORD WINAPI CERingDlg::thdPlaySound(LPVOID para) {
((CERingDlg*)para)->Preview();
return 0;
}
void CERingDlg::OnPreview()
{
// TODO: Add your control notification handler code here
DWORD ThreadId;
HANDLE hThread;
hThread=CreateThread(NULL,0,(unsigned long(__cdecl*)(void*))thdPlaySound,this,0,&ThreadId);
CloseHandle(hThread);
}
void CERingDlg::OnStop()
{
// TODO: Add your control notification handler code here
beStop=true;
sndPlaySound(NULL,SND_ASYNC);
}
void CERingDlg::OnOK()
{
// TODO: Add extra validation here
/* {
GetSelectedWave();
SetRingTone(listSelect);
ReleaseData();
listWave.RemoveAll();
listRing.RemoveAll();
listSelect.RemoveAll();
bAbout=true;
CDialog::OnOK();
}
*/
if (!m_exit){
m_exit=true;
return;
}
GetSelectedWave();
SetRingTone(listSelect);
ReleaseData();
listWave.RemoveAll();
listRing.RemoveAll();
listSelect.RemoveAll();
bAbout=true;
CDialog::OnOK();
}
void CERingDlg::OnSize(UINT nType, int cx, int cy)
{
CDialog::OnSize(nType, cx, cy);
// TODO: Add your message handler code here
CRect rt;
int y;
CButton *btn;
btn=(CButton *)GetDlgItem(IDC_PREVIEW);
btn->GetWindowRect(&rt);
ScreenToClient(&rt);
y=rt.bottom+3;
m_List.GetWindowRect(&rt);
rt.top=y;
rt.bottom=cy-3;
m_List.MoveWindow(&rt);
}
void CERingDlg::GetWaveList(CString path,BOOL bSub)
{
WIN32_FIND_DATA findData;
TCHAR szDir[MAX_PATH];
HANDLE fileHandle;
CStringArray m_filter;
CString sub;
FINDDATA pData;
int i;
m_filter.SetSize(0);
CString suffix;
suffix.LoadString(IDS_SUFFIX);
while(suffix.GetLength()>0){
i=suffix.Find(';');
if (i<0){
m_filter.Add(suffix);
suffix=L"";
}
else{
sub=suffix.Left(i);
suffix=suffix.Right(suffix.GetLength()-i-1);
sub.TrimLeft();
sub.TrimRight();
m_filter.Add(sub);
}
}
if (m_filter.GetSize()==0)
return;
if (path.GetLength()==0&&bSub)
{
fileHandle = FindFirstFlashCard(&findData);
if (fileHandle != INVALID_HANDLE_VALUE)
{
GetWaveList(findData.cFileName);
while (FindNextFlashCard(fileHandle, &findData))
{
GetWaveList(findData.cFileName);
}
}
FindClose(fileHandle);
}
wsprintf(szDir,path+L"\\*.*");
fileHandle = FindFirstFile(szDir, &findData);
if (fileHandle != INVALID_HANDLE_VALUE)
{
if(findData.dwFileAttributes==FILE_ATTRIBUTE_DIRECTORY&&bSub)
{
GetWaveList(path+L"\\"+findData.cFileName);
}
else
{
CString tmps=findData.cFileName;
tmps.MakeLower();
for (i=0;i<m_filter.GetSize();i++)
{
CString filter=L"";
filter=m_filter.GetAt(i);
filter=filter.Right(filter.GetLength()-1);
filter.MakeLower();
if(tmps.Right(filter.GetLength())==filter)
{
pData.dwFileAttributes=findData.dwFileAttributes;
pData.ftLastWriteTime=findData.ftCreationTime;
pData.szFileName=findData.cFileName;
pData.szPathName=path+L"\\"+findData.cFileName;
pData.nFileSize=findData.nFileSizeLow;
FillWaveList(&count,&pData);
break;
}
}
}
while (FindNextFile(fileHandle, &findData))
{
if(findData.dwFileAttributes==FILE_ATTRIBUTE_DIRECTORY&&bSub)
{
GetWaveList(path+L"\\"+findData.cFileName);
}
else
{
CString tmps=findData.cFileName;
tmps.MakeLower();
for (i=0;i<m_filter.GetSize();i++)
{
CString filter=L"";
filter=m_filter.GetAt(i);
filter=filter.Right(filter.GetLength()-1);
filter.MakeLower();
if(tmps.Right(filter.GetLength())==filter)
{
pData.dwFileAttributes=findData.dwFileAttributes;
pData.ftLastWriteTime=findData.ftCreationTime;
pData.szFileName=findData.cFileName;
pData.szPathName=path+L"\\"+findData.cFileName;
pData.nFileSize=findData.nFileSizeLow;
FillWaveList(&count,&pData);
break;
}
}
}
}
}
FindClose(fileHandle);
}
void CERingDlg::InitList()
{
CString str;
str.LoadString(IDS_NAME);
imgSmall.Create(IDB_LISTSORT,15,0,RGB(0,0,0));
HWND hHead=ListView_GetHeader(m_List.GetSafeHwnd());
Header_SetImageList(hHead,imgSmall.GetSafeHandle());
LVCOLUMN lvc={LVCF_FMT|LVCF_TEXT|LVCF_IMAGE|LVCF_WIDTH,LVCFMT_CENTER|LVCFMT_BITMAP_ON_RIGHT|LVCFMT_IMAGE,120,str.GetBuffer(0),0,0,0,0};
m_List.InsertColumn(0,&lvc);
str.LoadString(IDS_DATE);
LVCOLUMN lvc1={LVCF_FMT|LVCF_TEXT|LVCF_IMAGE|LVCF_WIDTH,LVCFMT_CENTER|LVCFMT_BITMAP_ON_RIGHT|LVCFMT_IMAGE,80,str.GetBuffer(0),0,0,0,1};
m_List.InsertColumn(1,&lvc1);
str.LoadString(IDS_SIZE);
LVCOLUMN lvc2={LVCF_FMT|LVCF_TEXT|LVCF_IMAGE|LVCF_WIDTH,LVCFMT_CENTER|LVCFMT_BITMAP_ON_RIGHT|LVCFMT_IMAGE,60,str.GetBuffer(0),0,0,0,2};
m_List.InsertColumn(2,&lvc2);
}
void CERingDlg::FillWaveList(int *pindex,PFINDDATA pData)
{
SYSTEMTIME systm;
DWORD size;
CString str;
PFINDDATA ptr;
BOOL bAdd=FALSE;
ptr=new FINDDATA;
ptr->dwFileAttributes=pData->dwFileAttributes;
ptr->ftLastWriteTime=pData->ftLastWriteTime;
ptr->nFileSize=pData->nFileSize;
ptr->szFileName=pData->szFileName;
ptr->szPathName=pData->szPathName;
if (FindFileInArray(listWave,pData->szFileName)==-1)
{
listWave.Add(ptr);
m_List.InsertItem(*pindex,pData->szFileName);
m_List.SetItemData(*pindex,*pindex);
FileTimeToSystemTime(&pData->ftLastWriteTime,&systm);
str.Format(L"%d/%d/%d",systm.wYear,systm.wMonth,systm.wDay);
m_List.SetItemText(*pindex,1,str);
size=pData->nFileSize;
if (size>1024){
if (size>1048576){
str.Format(L"%.2fM",((float)size)/1048576);
}
else{
str.Format(L"%.2fK",((float)size)/1024);
}
}
else{
str.Format(L"%dB",size);
}
m_List.SetItemText(*pindex,2,str);
str=pData->szPathName.Left(pData->szPathName.GetLength()-pData->szFileName.GetLength()-1);
CString pn;
pn.LoadString(IDS_RINGTONEFOLDER);
if (!str.CompareNoCase(pn)){
ListView_SetItemState (m_List.GetSafeHwnd(),*pindex,
UINT((int(TRUE) + 1) << 12), LVIS_STATEIMAGEMASK);
AddStrToArray(listRing,pData->szPathName);
}
else{
if (FindStrInArray(listSelect,pData->szPathName)!=-1){
CString nn;
nn.LoadString(IDS_RINGTONEFOLDER);
nn+=L"\\"+pData->szFileName;
if (FindStrInArray(listRing,nn)==-1){
ListView_SetItemState (m_List.GetSafeHwnd(), *pindex,
UINT((int(TRUE) + 1) << 12), LVIS_STATEIMAGEMASK);
}
else{
// DeleteStrFromArray(listSelect,pData->szPathName);
}
}
}
*pindex+=1;
}
}
void CERingDlg::ArrangeItems()
{
CStatic *stc;
CButton *btn;
CString str;
CDC *pdc;
CRect rt;
int h;
stc=(CStatic *)GetDlgItem(IDC_MSGSHOWN);
str.LoadString(IDS_MSGSHOWN);
if (stc){
CSize sz;
stc->SetWindowText(str);
stc->GetWindowRect(&rt);
rt.left=8;
rt.right=232;
pdc=stc->GetDC();
sz=pdc->GetTextExtent(str);
if (sz.cx>rt.Width()){
int i;
i=sz.cx/rt.Width()+((sz.cx%rt.Width()>0)?1:0);
rt.bottom=rt.top+sz.cy*i;
}
ScreenToClient(&rt);
stc->MoveWindow(&rt);
stc->ReleaseDC(pdc);
h=rt.bottom+6;
stc->Invalidate();
}
btn=(CButton *)GetDlgItem(IDC_PREVIEW);
str.LoadString(IDS_PREVIEW);
if (btn){
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -