// MediaPlayer.cpp : Defines the class behaviors for the application. // #include "stdafx.h" #include "MediaPlayer.h" #include "MediaPlayerDlg.h" #ifdef _DEBUG #define new DEBUG_NEW #undef THIS_FILE static char THIS_FILE[] = __FILE__; #endif ///////////////////////////////////////////////////////////////////////////// // CMediaPlayerApp BEGIN_MESSAGE_MAP(CMediaPlayerApp, CWinApp) //{{AFX_MSG_MAP(CMediaPlayerApp) // 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() ///////////////////////////////////////////////////////////////////////////// // CMediaPlayerApp construction CMediaPlayerApp::CMediaPlayerApp() : CWinApp() { // TODO: add construction code here, // Place all significant initialization in InitInstance m_Language = GetRegLanguage();//LANG_CHINESE; m_IsBeep = GetRegBeep(); } ///////////////////////////////////////////////////////////////////////////// // The one and only CMediaPlayerApp object CMediaPlayerApp theApp; ///////////////////////////////////////////////////////////////////////////// // CMediaPlayerApp initialization BOOL CMediaPlayerApp::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); CMediaPlayerDlg 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 CMediaPlayerApp::ExitInstance() { // TODO: Add your specialized code here and/or call the base class CoUninitialize(); if(m_ResourceLib) { FreeLibrary(m_ResourceLib); } return CWinApp::ExitInstance(); } int CMediaPlayerApp::GetLanguage() { return m_Language; } bool CMediaPlayerApp::GetBeep() { return m_IsBeep; } void CMediaPlayerApp::PlayMsgSound(int iSound) { // 播放wav文件 if (iSound == -1) { //PlaySound(L"default.wav",NULL,SND_FILENAME); //MessageBeep(MB_OK); } else { // 播放资源wav //PlaySound(MAKEINTRESOURCE(iSound),AfxGetResourceHandle(),SND_RESOURCE); //MessageBeep(MB_ICONEXCLAMATION); } } HINSTANCE CMediaPlayerApp::GetResourceLib() { return m_ResourceLib; } HINSTANCE CMediaPlayerApp::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 CMediaPlayerApp::GetRegBeep() { HKEY hKey; DWORD hResult,hType; // 打开注册表 hResult = RegCreateKeyEx(HKEY_LOCAL_MACHINE, _T("SOFTWARE\\PDA") ,0,0,0,0,0,&hKey,&hType); if (hResult == ERROR_SUCCESS) { // 数据大小 DWORD dwSize = 4; DWORD dwType = REG_DWORD; // 判断是新建还是打开该键 if (hType == REG_CREATED_NEW_KEY) { // 默认语言 int lpData = 0; // 将默认值添加到注册表 hResult = RegSetValueEx(hKey,L"Beep",NULL,REG_DWORD,(CONST BYTE*)&lpData,sizeof(REG_DWORD)); // 关闭 RegCloseKey(hKey); // 返回默认语言 return true; } else { // 将要读取的数据 BYTE lpData; // 从注册表中读取配置 hResult = RegQueryValueEx(hKey,L"Beep",NULL,&dwType,(BYTE*)&lpData,&dwSize); // 判断读取是否成功 if (hResult == ERROR_SUCCESS) { // 关闭 RegCloseKey(hKey); if (lpData == 0) { return false; } else { return true; } } else if (hResult == ERROR_FILE_NOT_FOUND) { // 默认禁止按键发音 int lpData = 0; // 将默认值添加到注册表 hResult = RegSetValueEx(hKey,L"Beep",NULL,REG_DWORD,(CONST BYTE*)&lpData,sizeof(REG_DWORD)); // 关闭 RegCloseKey(hKey); // 返回默认 return true; } else { // 关闭 RegCloseKey(hKey); // 读取失败返回默认值 return true; } } } else { // 关闭 RegCloseKey(hKey); // 返回默认值 return false; } } int CMediaPlayerApp::GetRegLanguage() { HKEY hKey; DWORD hResult,hType; // 打开注册表 hResult = RegCreateKeyEx(HKEY_LOCAL_MACHINE, _T("SOFTWARE\\PDA") ,0,0,0,0,0,&hKey,&hType); if (hResult == ERROR_SUCCESS) { // 数据大小 DWORD dwSize = 4; DWORD dwType = REG_DWORD; // 判断是新建还是打开该键 if (hType == REG_CREATED_NEW_KEY) { // 默认语言 int lpData = LANG_CHINESE; // 将默认值添加到注册表 hResult = RegSetValueEx(hKey,L"DefaultLanguage",NULL,REG_DWORD,(CONST BYTE*)&lpData,sizeof(REG_DWORD)); // 关闭 RegCloseKey(hKey); // 返回默认语言 return lpData; } else { // 将要写入的数据 BYTE lpData; // 从注册表中读取配置 hResult = RegQueryValueEx(hKey,L"DefaultLanguage",NULL,&dwType,(BYTE*)&lpData,&dwSize); // 判断读取是否成功 if (hResult == ERROR_SUCCESS) { // 关闭 RegCloseKey(hKey); return lpData; } else if (hResult == ERROR_FILE_NOT_FOUND) { // 默认语言 int lpData = LANG_CHINESE; // 将默认值添加到注册表 hResult = RegSetValueEx(hKey,L"DefaultLanguage",NULL,REG_DWORD,(CONST BYTE*)&lpData,sizeof(REG_DWORD)); // 关闭 RegCloseKey(hKey); // 返回默认语言 return lpData; } else { // 关闭 RegCloseKey(hKey); // 读取失败返回默认值 return LANG_CHINESE; } } } else { // 关闭 RegCloseKey(hKey); // 返回默认的语言 return LANG_CHINESE; } }