📄 makem3udlg.cpp
字号:
// MakeM3uDlg.cpp : implementation file
//
#include "stdafx.h"
#include "MakeM3u.h"
#include "MakeM3uDlg.h"
#include "DirDialog.h" //目录浏览对话框
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
/////////////////////////////////////////////////////////////////////////////
// CMakeM3uDlg dialog
CMakeM3uDlg::CMakeM3uDlg(CWnd* pParent /*=NULL*/)
: CDialog(CMakeM3uDlg::IDD, pParent)
{
//{{AFX_DATA_INIT(CMakeM3uDlg)
// NOTE: the ClassWizard will add member initialization here
//}}AFX_DATA_INIT
// Note that LoadIcon does not require a subsequent DestroyIcon in Win32
m_hIcon = AfxGetApp()->LoadIcon(IDR_MAINFRAME);
}
void CMakeM3uDlg::DoDataExchange(CDataExchange* pDX)
{
CDialog::DoDataExchange(pDX);
//{{AFX_DATA_MAP(CMakeM3uDlg)
// NOTE: the ClassWizard will add DDX and DDV calls here
//}}AFX_DATA_MAP
}
BEGIN_MESSAGE_MAP(CMakeM3uDlg, CDialog)
//{{AFX_MSG_MAP(CMakeM3uDlg)
ON_WM_PAINT()
ON_WM_QUERYDRAGICON()
ON_BN_CLICKED(IDC_BUTTON1, OnBrowserButton)
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// CMakeM3uDlg message handlers
BOOL CMakeM3uDlg::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
// TODO: Add extra initialization here
return TRUE; // return TRUE unless you set the focus to a control
}
// If you add a minimize button to your dialog, you will need the code below
// to draw the icon. For MFC applications using the document/view model,
// this is automatically done for you by the framework.
void CMakeM3uDlg::OnPaint()
{
if (IsIconic())
{
CPaintDC dc(this); // device context for painting
SendMessage(WM_ICONERASEBKGND, (WPARAM) dc.GetSafeHdc(), 0);
// Center icon in client rectangle
int cxIcon = GetSystemMetrics(SM_CXICON);
int cyIcon = GetSystemMetrics(SM_CYICON);
CRect rect;
GetClientRect(&rect);
int x = (rect.Width() - cxIcon + 1) / 2;
int y = (rect.Height() - cyIcon + 1) / 2;
// Draw the icon
dc.DrawIcon(x, y, m_hIcon);
}
else
{
CDialog::OnPaint();
}
}
// The system calls this to obtain the cursor to display while the user drags
// the minimized window.
HCURSOR CMakeM3uDlg::OnQueryDragIcon()
{
return (HCURSOR) m_hIcon;
}
void CMakeM3uDlg::OnBrowserButton()
{
// TODO: Add your control notification handler code here
CDirDialog dlg;
if (dlg.DoBrowse(this) == IDOK) {
//set target path
m_targetpath = dlg.m_strPath;
}
}
void CMakeM3uDlg::ReadFileToM3u(CString DirName)
{
HANDLE hFindFile;
WIN32_FIND_DATA FindFileData;
SetCurrentDirectory(DirName);
hFindFile=FindFirstFile("*.*",&FindFileData);
CString tFile;
if(hFindFile!=INVALID_HANDLE_VALUE)
{
do{
tFile=FindFileData.cFileName;
if((tFile==".")||(tFile=="……"))continue;
if(FindFileData.dwFileAttributes==FILE_ATTRIBUTE_DIRECTORY)continue;
if(tFile.Right(3)=="MP3"||tFile.Right(3)=="mp3")
{
//here create .m3u file programe
HANDLE hFile=CreateFile("MakeM3u.m3u",GENERIC_READ||GENERIC_WRITE,FILE_SHARE_READ||FILE_SHARE_WRITE,NULL,OPEN_ALWAYS,FILE_ATTRIBUTE_NORMAL,NULL);
CloseHandle(hFile);
//here read and write mp3 file to .m3u
CFile file;
file.Open("MakeM3u.m3u",CFile::modeWrite|CFile::shareDenyWrite);
tFile+='\r';
tFile+='\n';
file.SeekToEnd();
file.Write(tFile,tFile.GetLength());
file.Close();
}
}
while(FindNextFile(hFindFile,&FindFileData));
FindClose(hFindFile);
}
}
void CMakeM3uDlg::OnOK()
{
// TODO: Add extra validation here
ReadFileToM3u(m_targetpath);
CDialog::OnOK();
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -