gps/GPSProject/MusicPlayer/MusicPlayer.cpp

293 lines
6.0 KiB
C++
Executable File
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

// MusicPlayer.cpp : Defines the class behaviors for the application.
//
#include "stdafx.h"
#include "MusicPlayer.h"
#include "MusicPlayerDlg.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
CPlaylist g_Playlist;
/////////////////////////////////////////////////////////////////////////////
// CMusicPlayerApp
BEGIN_MESSAGE_MAP(CMusicPlayerApp, CWinApp)
//{{AFX_MSG_MAP(CMusicPlayerApp)
// NOTE - the ClassWizard will add and remove mapping macros here.
// DO NOT EDIT what you see in these blocks of generated code!
//}}AFX_MSG
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// CMusicPlayerApp construction
CMusicPlayerApp::CMusicPlayerApp()
: CWinApp()
{
// TODO: add construction code here,
// Place all significant initialization in InitInstance
m_Language = GetRegLanguage();//LANG_CHINESE;
m_IsBeep = GetRegBeep();
}
/////////////////////////////////////////////////////////////////////////////
// The one and only CMusicPlayerApp object
CMusicPlayerApp theApp;
/////////////////////////////////////////////////////////////////////////////
// CMusicPlayerApp initialization
BOOL CMusicPlayerApp::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.
CoInitialize(NULL);
CMusicPlayerDlg dlg;
m_pMainWnd = &dlg;
int nResponse = dlg.DoModal();
if (nResponse == IDOK)
{
// TODO: Place code here to handle when the dialog is
// dismissed with OK
}
else if (nResponse == IDCANCEL)
{
// TODO: Place code here to handle when the dialog is
// dismissed with Cancel
}
// Since the dialog has been closed, return FALSE so that we exit the
// application, rather than start the application's message pump.
return FALSE;
}
int CMusicPlayerApp::ExitInstance()
{
// TODO: Add your specialized code here and/or call the base class
CoUninitialize();
if(m_ResourceLib)
{
FreeLibrary(m_ResourceLib);
}
return CWinApp::ExitInstance();
}
int CMusicPlayerApp::GetLanguage()
{
return m_Language;
}
bool CMusicPlayerApp::GetBeep()
{
return m_IsBeep;
}
void CMusicPlayerApp::PlayMsgSound(int iSound)
{
// <20><><EFBFBD><EFBFBD>wav<61>ļ<EFBFBD>
if (iSound == -1)
{
//PlaySound(L"default.wav",NULL,SND_FILENAME);
//MessageBeep(MB_OK);
}
else
{
// <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Դwav
//PlaySound(MAKEINTRESOURCE(iSound),AfxGetResourceHandle(),SND_RESOURCE);
//MessageBeep(MB_ICONEXCLAMATION);
}
}
HINSTANCE CMusicPlayerApp::GetResourceLib()
{
return m_ResourceLib;
}
HINSTANCE CMusicPlayerApp::LoadLanguageRes(int iLanguage)
{
if (m_ResourceLib)
{
FreeLibrary(m_ResourceLib);
}
if (iLanguage == LANG_ENGLISH)
{
m_ResourceLib = LoadLibrary(L"LanguageENU.dll");
}
else if(iLanguage == LANG_CHINESE)
{
m_ResourceLib = LoadLibrary(L"LanguageCHS.dll");
}
return m_ResourceLib;
}
bool CMusicPlayerApp::GetRegBeep()
{
HKEY hKey;
DWORD hResult,hType;
// <20><><EFBFBD><EFBFBD>ע<EFBFBD><D7A2><EFBFBD><EFBFBD>
hResult = RegCreateKeyEx(HKEY_LOCAL_MACHINE,
_T("SOFTWARE\\PDA")
,0,0,0,0,0,&hKey,&hType);
if (hResult == ERROR_SUCCESS)
{
// <20><><EFBFBD>ݴ<EFBFBD>С
DWORD dwSize = 4;
DWORD dwType = REG_DWORD;
// <20>ж<EFBFBD><D0B6><EFBFBD><EFBFBD>½<EFBFBD><C2BD><EFBFBD><EFBFBD>Ǵ򿪸ü<F2BFAAB8>
if (hType == REG_CREATED_NEW_KEY)
{
// Ĭ<><C4AC><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
int lpData = 0;
// <20><>Ĭ<EFBFBD><C4AC>ֵ<EFBFBD><D6B5><EFBFBD>ӵ<EFBFBD>ע<EFBFBD><D7A2><EFBFBD><EFBFBD>
hResult = RegSetValueEx(hKey,L"Beep",NULL,REG_DWORD,(CONST BYTE*)&lpData,sizeof(REG_DWORD));
// <20>ر<EFBFBD>
RegCloseKey(hKey);
// <20><><EFBFBD><EFBFBD>Ĭ<EFBFBD><C4AC><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
return true;
}
else
{
// <20><>Ҫ<EFBFBD><D2AA>ȡ<EFBFBD><C8A1><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
BYTE lpData;
// <20><>ע<EFBFBD><D7A2><EFBFBD><EFBFBD><EFBFBD>ж<EFBFBD>ȡ<EFBFBD><C8A1><EFBFBD><EFBFBD>
hResult = RegQueryValueEx(hKey,L"Beep",NULL,&dwType,(BYTE*)&lpData,&dwSize);
// <20>ж϶<D0B6>ȡ<EFBFBD>Ƿ<EFBFBD><C7B7>ɹ<EFBFBD>
if (hResult == ERROR_SUCCESS)
{
// <20>ر<EFBFBD>
RegCloseKey(hKey);
if (lpData == 0)
{
return false;
}
else
{
return true;
}
}
else if (hResult == ERROR_FILE_NOT_FOUND)
{
// Ĭ<>Ͻ<EFBFBD>ֹ<EFBFBD><D6B9><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
int lpData = 0;
// <20><>Ĭ<EFBFBD><C4AC>ֵ<EFBFBD><D6B5><EFBFBD>ӵ<EFBFBD>ע<EFBFBD><D7A2><EFBFBD><EFBFBD>
hResult = RegSetValueEx(hKey,L"Beep",NULL,REG_DWORD,(CONST BYTE*)&lpData,sizeof(REG_DWORD));
// <20>ر<EFBFBD>
RegCloseKey(hKey);
// <20><><EFBFBD><EFBFBD>Ĭ<EFBFBD><C4AC>
return true;
}
else
{
// <20>ر<EFBFBD>
RegCloseKey(hKey);
// <20><>ȡʧ<C8A1>ܷ<EFBFBD><DCB7><EFBFBD>Ĭ<EFBFBD><C4AC>ֵ
return true;
}
}
}
else
{
// <20>ر<EFBFBD>
RegCloseKey(hKey);
// <20><><EFBFBD><EFBFBD>Ĭ<EFBFBD><C4AC>ֵ
return false;
}
}
int CMusicPlayerApp::GetRegLanguage()
{
HKEY hKey;
DWORD hResult,hType;
// <20><><EFBFBD><EFBFBD>ע<EFBFBD><D7A2><EFBFBD><EFBFBD>
hResult = RegCreateKeyEx(HKEY_LOCAL_MACHINE,
_T("SOFTWARE\\PDA")
,0,0,0,0,0,&hKey,&hType);
if (hResult == ERROR_SUCCESS)
{
// <20><><EFBFBD>ݴ<EFBFBD>С
DWORD dwSize = 4;
DWORD dwType = REG_DWORD;
// <20>ж<EFBFBD><D0B6><EFBFBD><EFBFBD>½<EFBFBD><C2BD><EFBFBD><EFBFBD>Ǵ򿪸ü<F2BFAAB8>
if (hType == REG_CREATED_NEW_KEY)
{
// Ĭ<><C4AC><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
int lpData = LANG_CHINESE;
// <20><>Ĭ<EFBFBD><C4AC>ֵ<EFBFBD><D6B5><EFBFBD>ӵ<EFBFBD>ע<EFBFBD><D7A2><EFBFBD><EFBFBD>
hResult = RegSetValueEx(hKey,L"DefaultLanguage",NULL,REG_DWORD,(CONST BYTE*)&lpData,sizeof(REG_DWORD));
// <20>ر<EFBFBD>
RegCloseKey(hKey);
// <20><><EFBFBD><EFBFBD>Ĭ<EFBFBD><C4AC><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
return lpData;
}
else
{
// <20><>Ҫд<D2AA><D0B4><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
BYTE lpData;
// <20><>ע<EFBFBD><D7A2><EFBFBD><EFBFBD><EFBFBD>ж<EFBFBD>ȡ<EFBFBD><C8A1><EFBFBD><EFBFBD>
hResult = RegQueryValueEx(hKey,L"DefaultLanguage",NULL,&dwType,(BYTE*)&lpData,&dwSize);
// <20>ж϶<D0B6>ȡ<EFBFBD>Ƿ<EFBFBD><C7B7>ɹ<EFBFBD>
if (hResult == ERROR_SUCCESS)
{
// <20>ر<EFBFBD>
RegCloseKey(hKey);
return lpData;
}
else if (hResult == ERROR_FILE_NOT_FOUND)
{
// Ĭ<><C4AC><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
int lpData = LANG_CHINESE;
// <20><>Ĭ<EFBFBD><C4AC>ֵ<EFBFBD><D6B5><EFBFBD>ӵ<EFBFBD>ע<EFBFBD><D7A2><EFBFBD><EFBFBD>
hResult = RegSetValueEx(hKey,L"DefaultLanguage",NULL,REG_DWORD,(CONST BYTE*)&lpData,sizeof(REG_DWORD));
// <20>ر<EFBFBD>
RegCloseKey(hKey);
// <20><><EFBFBD><EFBFBD>Ĭ<EFBFBD><C4AC><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
return lpData;
}
else
{
// <20>ر<EFBFBD>
RegCloseKey(hKey);
// <20><>ȡʧ<C8A1>ܷ<EFBFBD><DCB7><EFBFBD>Ĭ<EFBFBD><C4AC>ֵ
return LANG_CHINESE;
}
}
}
else
{
// <20>ر<EFBFBD>
RegCloseKey(hKey);
// <20><><EFBFBD><EFBFBD>Ĭ<EFBFBD>ϵ<EFBFBD><CFB5><EFBFBD><EFBFBD><EFBFBD>
return LANG_CHINESE;
}
}