- Register default sound schemes when an new audio adapter is installed

- Pass the full filename to PlaySound as the sound might not be in standard location

svn path=/trunk/; revision=39915
This commit is contained in:
Johannes Anderwald 2009-03-09 11:51:28 +00:00
parent c5a305d2a5
commit b27721cbe6
3 changed files with 189 additions and 4 deletions

View file

@ -30,6 +30,62 @@ typedef enum
HWPD_MAX = HWPD_LARGELIST
} HWPAGE_DISPLAYMODE, *PHWPAGE_DISPLAYMODE;
typedef struct
{
LPWSTR LabelName;
LPWSTR DefaultName;
UINT LocalizedResId;
LPWSTR FileName;
}EVENT_LABEL_ITEM;
typedef struct
{
LPWSTR LabelName;
LPWSTR DefaultName;
UINT IconId;
}SYSTEM_SCHEME_ITEM;
static EVENT_LABEL_ITEM EventLabels[] =
{
{
L"WindowsLogon",
L"ReactOS Logon",
IDS_REACTOS_LOGON,
L"ReactOS_Logon.wav"
},
{
L"WindowsLogoff",
L"ReactOS Logoff",
IDS_REACTOS_LOGOFF,
L"ReactOS_Logoff.wav"
},
{
NULL,
NULL,
0,
NULL
}
};
static SYSTEM_SCHEME_ITEM SystemSchemes[] =
{
{
L".Default",
L"ReactOS Standard",
IDS_REACTOS_DEFAULT_SCHEME
},
{
L".None",
L"No Sounds",
-1
},
{
NULL,
NULL
}
};
HWND WINAPI
DeviceCreateHardwarePageEx(HWND hWndParent,
LPGUID lpGuids,
@ -156,6 +212,127 @@ ShowFullControlPanel(HWND hwnd,
DPRINT1("ShowFullControlPanel() stubs\n");
}
VOID
InstallSystemSoundLabels(HKEY hKey)
{
UINT i = 0;
HKEY hSubKey;
WCHAR Buffer[40];
do
{
if (RegCreateKeyExW(hKey, EventLabels[i].LabelName, 0, NULL, REG_OPTION_NON_VOLATILE, KEY_ALL_ACCESS, NULL, &hSubKey, NULL) == ERROR_SUCCESS)
{
RegSetValueExW(hSubKey, NULL, 0, REG_SZ, (LPBYTE)EventLabels[i].DefaultName, (wcslen(EventLabels[i].DefaultName)+1) * sizeof(WCHAR));
swprintf(Buffer, L"@mmsys.cpl,-%u", EventLabels[i].LocalizedResId);
RegSetValueExW(hSubKey, L"DispFileName", 0, REG_SZ, (LPBYTE)Buffer, (wcslen(Buffer)+1) * sizeof(WCHAR));
RegCloseKey(hSubKey);
}
i++;
}while(EventLabels[i].LabelName);
}
VOID
InstallSystemSoundSchemeNames(HKEY hKey)
{
UINT i = 0;
HKEY hSubKey;
do
{
if (RegCreateKeyExW(hKey, SystemSchemes[i].LabelName, 0, NULL, REG_OPTION_NON_VOLATILE, KEY_ALL_ACCESS, NULL, &hSubKey, NULL) == ERROR_SUCCESS)
{
RegSetValueExW(hSubKey, NULL, 0, REG_SZ, (LPBYTE)SystemSchemes[i].DefaultName, (wcslen(SystemSchemes[i].DefaultName)+1) * sizeof(WCHAR));
RegCloseKey(hSubKey);
}
i++;
}while(SystemSchemes[i].LabelName);
}
VOID
InstallDefaultSystemSoundScheme(HKEY hRootKey)
{
HKEY hKey, hSubKey;
WCHAR Path[MAX_PATH];
UINT i = 0;
if (RegCreateKeyExW(hRootKey, L".Default", 0, NULL, REG_OPTION_NON_VOLATILE, KEY_ALL_ACCESS, NULL, &hKey, NULL) != ERROR_SUCCESS)
return;
RegSetValueExW(hKey, NULL, 0, REG_SZ, (LPBYTE)SystemSchemes[0].DefaultName, (wcslen(SystemSchemes[0].DefaultName)+1) * sizeof(WCHAR));
swprintf(Path, L"@mmsys.cpl,-%u", SystemSchemes[0].IconId);
RegSetValueExW(hKey, L"DispFileName", 0, REG_SZ, (LPBYTE)Path, (wcslen(Path)+1) * sizeof(WCHAR));
do
{
if (RegCreateKeyExW(hKey, EventLabels[i].LabelName, 0, NULL, REG_OPTION_NON_VOLATILE, KEY_ALL_ACCESS, NULL, &hSubKey, NULL) == ERROR_SUCCESS)
{
HKEY hScheme;
swprintf(Path, L"%%SystemRoot%%\\media\\%s", EventLabels[i].FileName);
if (RegCreateKeyExW(hSubKey, L".Current", 0, NULL, REG_OPTION_NON_VOLATILE, KEY_ALL_ACCESS, NULL, &hScheme, NULL) == ERROR_SUCCESS)
{
RegSetValueExW(hScheme, NULL, 0, REG_SZ, (LPBYTE)Path, (wcslen(Path)+1) * sizeof(WCHAR));
RegCloseKey(hScheme);
}
if (RegCreateKeyExW(hSubKey, L".Default", 0, NULL, REG_OPTION_NON_VOLATILE, KEY_ALL_ACCESS, NULL, &hScheme, NULL) == ERROR_SUCCESS)
{
RegSetValueExW(hScheme, NULL, 0, REG_SZ, (LPBYTE)Path, (wcslen(Path)+1) * sizeof(WCHAR));
RegCloseKey(hScheme);
}
RegCloseKey(hSubKey);
}
i++;
}while(EventLabels[i].LabelName);
RegCloseKey(hKey);
}
VOID
InstallSystemSoundScheme()
{
HKEY hKey, hSubKey;
DWORD dwDisposition;
if (RegCreateKeyExW(HKEY_CURRENT_USER, L"AppEvents", 0, NULL, REG_OPTION_NON_VOLATILE, KEY_ALL_ACCESS, NULL, &hKey, NULL) != ERROR_SUCCESS)
return;
if (RegCreateKeyExW(hKey, L"EventLabels", 0, NULL, REG_OPTION_NON_VOLATILE, KEY_ALL_ACCESS, NULL, &hSubKey, NULL) == ERROR_SUCCESS)
{
InstallSystemSoundLabels(hSubKey);
RegCloseKey(hSubKey);
}
if (RegCreateKeyExW(hKey, L"Schemes", 0, NULL, REG_OPTION_NON_VOLATILE, KEY_ALL_ACCESS, NULL, &hSubKey, &dwDisposition) == ERROR_SUCCESS)
{
HKEY hNames;
if (RegCreateKeyExW(hSubKey, L"Names", 0, NULL, REG_OPTION_NON_VOLATILE, KEY_ALL_ACCESS, NULL, &hNames, NULL) == ERROR_SUCCESS)
{
InstallSystemSoundSchemeNames(hNames);
RegCloseKey(hNames);
}
if (RegCreateKeyExW(hSubKey, L"Apps", 0, NULL, REG_OPTION_NON_VOLATILE, KEY_ALL_ACCESS, NULL, &hNames, NULL) == ERROR_SUCCESS)
{
InstallDefaultSystemSoundScheme(hNames);
RegCloseKey(hNames);
if (dwDisposition & REG_CREATED_NEW_KEY)
{
RegSetValueExW(hSubKey, NULL, 0, REG_SZ, (LPBYTE)L".Default", (wcslen(L".Default")+1) * sizeof(WCHAR)); //FIXME
}
}
RegCloseKey(hSubKey);
}
RegCloseKey(hKey);
}
DWORD
MMSYS_InstallDevice(HDEVINFO hDevInfo, PSP_DEVINFO_DATA pspDevInfoData)
{
@ -263,6 +440,7 @@ MMSYS_InstallDevice(HDEVINFO hDevInfo, PSP_DEVINFO_DATA pspDevInfoData)
}
RegCloseKey(hKey);
}
InstallSystemSoundScheme();
return ERROR_DI_DO_DEFAULT;

View file

@ -66,6 +66,11 @@
#define IDC_SPEAKIMG 4625
#define IDC_MUTE_ICON 4626
#define IDS_REACTOS_LOGON 5853
#define IDS_REACTOS_LOGOFF 5852
#define IDS_REACTOS_DEFAULT_SCHEME 5856
/* Strings */
#define IDS_CPLNAME 1000
#define IDS_CPLDESCRIPTION 1001

View file

@ -826,15 +826,17 @@ SoundsDlgProc(HWND hwndDlg,
case IDC_PLAY_SOUND:
{
LRESULT lIndex;
TCHAR szValue[MAX_PATH];
lIndex = SendDlgItemMessage(hwndDlg, IDC_SOUND_LIST, CB_GETCURSEL, (WPARAM)0, (LPARAM)0);
if (lIndex == CB_ERR)
{
break;
}
SendDlgItemMessage(hwndDlg, IDC_SOUND_LIST, CB_GETLBTEXT, (WPARAM)lIndex, (LPARAM)szValue);
PlaySound(szValue, NULL, SND_FILENAME);
lIndex = SendDlgItemMessage(hwndDlg, IDC_SOUND_LIST, CB_GETITEMDATA, (WPARAM)lIndex, (LPARAM)0);
if (lIndex != CB_ERR)
{
PlaySound((TCHAR*)lIndex, NULL, SND_FILENAME);
}
break;
}
case IDC_SOUND_SCHEME: