www.pudn.com > LECTEUR-MP3.zip > MusGest.cpp
// MusGest.cpp : Defines the class behaviors for the application. // #include "stdafx.h" #include "MusGest.h" #include "MainFrm.h" #include "MusGestDoc.h" #include "MusGestView.h" #include "NewDirDlg.h" #include "BaseVarFrame.h" #include "FileView.h" #include "ChildFrm.h" #include "PlayListView.h" #include "ControlView.h" #include#include #ifdef _DEBUG #define new DEBUG_NEW #undef THIS_FILE static char THIS_FILE[] = __FILE__; #endif static CRuntimeClass* myClass[3] = {RUNTIME_CLASS(CFileView),RUNTIME_CLASS(CPlayListView),RUNTIME_CLASS(CControlView)}; ///////////////////////////////////////////////////////////////////////////// // CMusGestApp BEGIN_MESSAGE_MAP(CMusGestApp, CWinApp) //{{AFX_MSG_MAP(CMusGestApp) ON_COMMAND(ID_APP_ABOUT, OnAppAbout) // NOTE - the ClassWizard will add and remove mapping macros here. // DO NOT EDIT what you see in these blocks of generated code! //}}AFX_MSG_MAP // Standard file based document commands ON_COMMAND(ID_FICHIER_NOUVEAU, OnNewFile) ON_COMMAND(ID_FILE_OPEN, OnFileOpen) ON_COMMAND(ID_OPTIONS_CHOISIRLEDOSSIERINITIAL, OnChoseFolder) //Volume ON_COMMAND(ID_OPTIONS_VOLUME_MUTE, OnMute) ON_COMMAND(ID_OPTIONS_VOLUME_10, OnVol10) ON_COMMAND(ID_OPTIONS_VOLUME_20, OnVol20) ON_COMMAND(ID_OPTIONS_VOLUME_30, OnVol30) ON_COMMAND(ID_OPTIONS_VOLUME_40, OnVol40) ON_COMMAND(ID_OPTIONS_VOLUME_50, OnVol50) ON_COMMAND(ID_OPTIONS_VOLUME_60, OnVol60) ON_COMMAND(ID_OPTIONS_VOLUME_70, OnVol70) ON_COMMAND(ID_OPTIONS_VOLUME_80, OnVol80) ON_COMMAND(ID_OPTIONS_VOLUME_90, OnVol90) ON_COMMAND(ID_OPTIONS_VOLUME_MAX, OnVolMax) ////// END_MESSAGE_MAP() ///////////////////////////////////////////////////////////////////////////// // CMusGestApp construction CMusGestApp::CMusGestApp() { // TODO: add construction code here, // Place all significant initialization in InitInstance for (int i = 0; i< 10;i++) m_bVolTab[i] = false; } ///////////////////////////////////////////////////////////////////////////// // The one and only CMusGestApp object CMusGestApp theApp; ///////////////////////////////////////////////////////////////////////////// // CMusGestApp initialization //---------------------------------------------------------- BOOL CMusGestApp::InitInstance() { AfxEnableControlContainer(); // Standard initialization // If you are not using these features and wish to reduce the size // of your final executable, you should remove from the following // the specific initialization routines you do not need. #ifdef _AFXDLL Enable3dControls(); // Call this when using MFC in a shared DLL #else Enable3dControlsStatic(); // Call this when linking to MFC statically #endif // Change the registry key under which our settings are stored. // TODO: You should modify this string to be something appropriate // such as the name of your company or organization. SetRegistryKey(_T("Local AppWizard-Generated Applications")); LoadStdProfileSettings(); // Load standard INI file options (including MRU) // Register the application's document templates. Document templates // serve as the connection between documents, frame windows and views. m_pDocTemplate = new CSingleDocTemplate( IDR_MAINFRAME, RUNTIME_CLASS(CMusGestDoc), RUNTIME_CLASS(CBaseVariableFrame), // main SDI frame window RUNTIME_CLASS(CMusGestView)); AddDocTemplate(m_pDocTemplate); CBaseVariableFrame::SetConfiguration(myClass,3,3); // Parse command line for standard shell commands, DDE, file open CCommandLineInfo cmdInfo; ParseCommandLine(cmdInfo); // Dispatch commands specified on the command line if (!ProcessShellCommand(cmdInfo)) return FALSE; m_pMainWnd->SetWindowText("Gestionaire de fichier audio"); // The one and only window has been initialized, so show and update it. m_pMainWnd->ShowWindow(SW_SHOW); m_pMainWnd->UpdateWindow(); LoadConfig(); return TRUE; } //---------------------------------------------------------- void CMusGestApp::OnNewFile() { CString strNewRepName; NewDirDlg Dlg; CMainFrame * pFrame = (CMainFrame*)m_pMainWnd; if (Dlg.DoModal() == IDOK) { strNewRepName = Dlg.GetName(); if (!strNewRepName.IsEmpty()) { if (pFrame) pFrame->NewFolder(strNewRepName); } } } //---------------------------------------------------------- void CMusGestApp::OnFileOpen() { CWnd * pWnd = this->m_pMainWnd; if (pWnd) { CString strRepertoire="c:\\"; if(GetFolder(&strRepertoire,"Sélection du répertoire",pWnd->m_hWnd, NULL, NULL)) { if (!strRepertoire.IsEmpty()) { m_strRepPath = strRepertoire; CMainFrame * pFrame = (CMainFrame*)m_pMainWnd; if (pFrame) pFrame->ChangeFolder(m_strRepPath); } } } } //---------------------------------------------------------- void CMusGestApp::OnChoseFolder() { CWnd * pWnd = this->m_pMainWnd; if (pWnd) { CString strRepertoire="c:\\"; if(GetFolder(&strRepertoire,"Sélection du répertoire",pWnd->m_hWnd, NULL, NULL)) { if (!strRepertoire.IsEmpty()) { CString strFile = "Config.ini"; CStdioFile fFile(strFile, CFile::modeCreate | CFile::modeWrite | CFile::typeText); CString strConf; strConf.Format("[INITIAL_FOLDER]\n%s", strRepertoire); fFile.Write(strConf, strConf.GetLength()); fFile.Close(); } } } } //---------------------------------------------------------- void CMusGestApp::LoadConfig() { CMainFrame * pFrame = (CMainFrame*)m_pMainWnd; //test si fichier existe if((_access( "Config.ini", 0 )) != -1 ) { CString strTmp; CStdioFile fFile("Config.ini", CFile::modeRead | CFile::typeText); while (fFile.ReadString(strTmp)) { if (strTmp.Find("[INITIAL_FOLDER]",0) != -1) { fFile.ReadString(m_strRepPath); if (pFrame) { CString strText = "Dossier Initial : " + m_strRepPath; pFrame->ChangeFolder(m_strRepPath); } } } } } //------------------------------------------------------------------------------- void CMusGestApp::OnMute() { CMainFrame * pFrame = (CMainFrame*)m_pMainWnd; if (pFrame) pFrame->ChangeVolume(0); } //------------------------------------------------------------------------------- void CMusGestApp::OnVol10() { CMainFrame * pFrame = (CMainFrame*)m_pMainWnd; if (pFrame) pFrame->ChangeVolume((float)0.1); } //------------------------------------------------------------------------------- void CMusGestApp::OnVol20() { CMainFrame * pFrame = (CMainFrame*)m_pMainWnd; if (pFrame) pFrame->ChangeVolume((float)0.2); } //------------------------------------------------------------------------------- void CMusGestApp::OnVol30() { CMainFrame * pFrame = (CMainFrame*)m_pMainWnd; if (pFrame) pFrame->ChangeVolume((float)0.3); } //------------------------------------------------------------------------------- void CMusGestApp::OnVol40() { CMainFrame * pFrame = (CMainFrame*)m_pMainWnd; if (pFrame) pFrame->ChangeVolume((float)0.4); } //------------------------------------------------------------------------------- void CMusGestApp::OnVol50() { CMainFrame * pFrame = (CMainFrame*)m_pMainWnd; if (pFrame) pFrame->ChangeVolume((float)0.5); } //------------------------------------------------------------------------------- void CMusGestApp::OnVol60() { CMainFrame * pFrame = (CMainFrame*)m_pMainWnd; if (pFrame) pFrame->ChangeVolume((float)0.6); } //------------------------------------------------------------------------------- void CMusGestApp::OnVol70() { CMainFrame * pFrame = (CMainFrame*)m_pMainWnd; if (pFrame) pFrame->ChangeVolume((float)0.7); } //------------------------------------------------------------------------------- void CMusGestApp::OnVol80() { CMainFrame * pFrame = (CMainFrame*)m_pMainWnd; if (pFrame) pFrame->ChangeVolume((float)0.8); } //------------------------------------------------------------------------------- void CMusGestApp::OnVol90() { CMainFrame * pFrame = (CMainFrame*)m_pMainWnd; if (pFrame) pFrame->ChangeVolume((float)0.9); } //------------------------------------------------------------------------------- void CMusGestApp::OnVolMax() { CMainFrame * pFrame = (CMainFrame*)m_pMainWnd; if (pFrame) pFrame->ChangeVolume(1); } //------------------------------------------------------------------------------- CString strTmpPath; int CALLBACK BrowseCallbackProc(HWND hwnd, UINT uMsg, LPARAM lParam, LPARAM lpData) { TCHAR szDir[MAX_PATH]; switch(uMsg) { case BFFM_INITIALIZED: if (lpData) { strcpy(szDir, strTmpPath.GetBuffer(strTmpPath.GetLength())); SendMessage(hwnd,BFFM_SETSELECTION,TRUE,(LPARAM)szDir); } break; case BFFM_SELCHANGED: { if (SHGetPathFromIDList((LPITEMIDLIST) lParam ,szDir)) { SendMessage(hwnd,BFFM_SETSTATUSTEXT,0,(LPARAM)szDir); } break; } default:break; } return 0; } //--------------------------------------------------------------------------------------------- BOOL CMusGestApp::GetFolder(CString* strSelectedFolder, const char* lpszTitle, const HWND hwndOwner, const char* strRootFolder, const char* strStartFolder) { char pszDisplayName[MAX_PATH]; LPITEMIDLIST lpID; BROWSEINFOA bi; bi.hwndOwner = hwndOwner; if (strRootFolder == NULL) { bi.pidlRoot = NULL; } else { LPITEMIDLIST pIdl = NULL; IShellFolder* pDesktopFolder; char szPath[MAX_PATH]; OLECHAR olePath[MAX_PATH]; ULONG chEaten; ULONG dwAttributes; strcpy(szPath, (LPCTSTR)strRootFolder); if (SUCCEEDED(SHGetDesktopFolder(&pDesktopFolder))) { MultiByteToWideChar(CP_ACP, MB_PRECOMPOSED, szPath, -1, olePath, MAX_PATH); pDesktopFolder->ParseDisplayName(NULL, NULL, olePath, &chEaten, &pIdl, &dwAttributes); pDesktopFolder->Release(); } bi.pidlRoot = pIdl; } bi.pszDisplayName = pszDisplayName; bi.lpszTitle = lpszTitle; #if _MFC_VER < 0x0700 bi.ulFlags = BIF_RETURNONLYFSDIRS | BIF_STATUSTEXT; #else bi.ulFlags = BIF_RETURNONLYFSDIRS | BIF_STATUSTEXT |BIF_NEWDIALOGSTYLE; OleInitialize(NULL); #endif bi.lpfn = BrowseCallbackProc; if (strStartFolder == NULL) { bi.lParam = FALSE; } else { strTmpPath.Format("%s", strStartFolder); bi.lParam = TRUE; } bi.iImage = NULL; lpID = SHBrowseForFolderA(&bi); if (lpID != NULL) { BOOL b = SHGetPathFromIDList(lpID, pszDisplayName); if (b == TRUE) { strSelectedFolder->Format("%s",pszDisplayName); return TRUE; } } else { strSelectedFolder->Empty(); } return FALSE; } ///////////////////////////////////////////////////////////////////////////// // CAboutDlg dialog used for App About class CAboutDlg : public CDialog { public: CAboutDlg(); // Dialog Data //{{AFX_DATA(CAboutDlg) enum { IDD = IDD_ABOUTBOX }; //}}AFX_DATA // ClassWizard generated virtual function overrides //{{AFX_VIRTUAL(CAboutDlg) protected: virtual void DoDataExchange(CDataExchange* pDX); // DDX/DDV support //}}AFX_VIRTUAL // Implementation protected: //{{AFX_MSG(CAboutDlg) // No message handlers //}}AFX_MSG DECLARE_MESSAGE_MAP() }; CAboutDlg::CAboutDlg() : CDialog(CAboutDlg::IDD) { //{{AFX_DATA_INIT(CAboutDlg) //}}AFX_DATA_INIT } void CAboutDlg::DoDataExchange(CDataExchange* pDX) { CDialog::DoDataExchange(pDX); //{{AFX_DATA_MAP(CAboutDlg) //}}AFX_DATA_MAP } BEGIN_MESSAGE_MAP(CAboutDlg, CDialog) //{{AFX_MSG_MAP(CAboutDlg) // No message handlers //}}AFX_MSG_MAP END_MESSAGE_MAP() // App command to run the dialog void CMusGestApp::OnAppAbout() { CAboutDlg aboutDlg; aboutDlg.DoModal(); } ///////////////////////////////////////////////////////////////////////////// // CMusGestApp message handlers