[MMSYS] Move global variables into a GLOBAL_DATA struct and free allocated memory on WM_DESTROY.

This commit is contained in:
Eric Kohl 2019-01-13 23:19:25 +01:00
parent 473e0bfc83
commit 5f11c16ca8

View file

@ -17,47 +17,48 @@
#include <debug.h> #include <debug.h>
struct __APP_MAP__; typedef struct _LABEL_MAP
typedef struct __LABEL_MAP__
{ {
TCHAR * szName; TCHAR *szName;
TCHAR * szDesc; TCHAR *szDesc;
TCHAR * szIcon; TCHAR *szIcon;
struct __APP_MAP__ * AppMap; struct _APP_MAP *AppMap;
struct __LABEL_MAP__ * Next; struct _LABEL_MAP *Next;
} LABEL_MAP, *PLABEL_MAP; } LABEL_MAP, *PLABEL_MAP;
typedef struct __APP_MAP__ typedef struct _APP_MAP
{ {
TCHAR szName[MAX_PATH]; TCHAR szName[MAX_PATH];
TCHAR szDesc[MAX_PATH]; TCHAR szDesc[MAX_PATH];
TCHAR szIcon[MAX_PATH]; TCHAR szIcon[MAX_PATH];
struct __APP_MAP__ *Next; struct _APP_MAP *Next;
PLABEL_MAP LabelMap; PLABEL_MAP LabelMap;
} APP_MAP, *PAPP_MAP; } APP_MAP, *PAPP_MAP;
typedef struct __LABEL_CONTEXT__ typedef struct _LABEL_CONTEXT
{ {
PLABEL_MAP LabelMap; PLABEL_MAP LabelMap;
PAPP_MAP AppMap; PAPP_MAP AppMap;
TCHAR szValue[MAX_PATH]; TCHAR szValue[MAX_PATH];
struct __LABEL_CONTEXT__ *Next; struct _LABEL_CONTEXT *Next;
} LABEL_CONTEXT, *PLABEL_CONTEXT; } LABEL_CONTEXT, *PLABEL_CONTEXT;
typedef struct __SOUND_SCHEME_CONTEXT__ typedef struct _SOUND_SCHEME_CONTEXT
{ {
TCHAR szName[MAX_PATH]; TCHAR szName[MAX_PATH];
TCHAR szDesc[MAX_PATH]; TCHAR szDesc[MAX_PATH];
PLABEL_CONTEXT LabelContext; PLABEL_CONTEXT LabelContext;
} SOUND_SCHEME_CONTEXT, *PSOUND_SCHEME_CONTEXT; } SOUND_SCHEME_CONTEXT, *PSOUND_SCHEME_CONTEXT;
static PLABEL_MAP s_Map = NULL; typedef struct _GLOBAL_DATA
static PAPP_MAP s_App = NULL; {
TCHAR szDefault[MAX_PATH];
HIMAGELIST hSoundsImageList;
PLABEL_MAP pLabelMap;
PAPP_MAP pAppMap;
} GLOBAL_DATA, *PGLOBAL_DATA;
TCHAR szDefault[MAX_PATH];
HIMAGELIST hSoundsImageList = NULL;
/* A filter string is a list separated by NULL and ends with double NULLs. */ /* A filter string is a list separated by NULL and ends with double NULLs. */
LPWSTR MakeFilter(LPWSTR psz) LPWSTR MakeFilter(LPWSTR psz)
@ -77,9 +78,9 @@ LPWSTR MakeFilter(LPWSTR psz)
return psz; return psz;
} }
PLABEL_MAP FindLabel(PAPP_MAP pAppMap, TCHAR * szName) PLABEL_MAP FindLabel(PGLOBAL_DATA pGlobalData, PAPP_MAP pAppMap, TCHAR * szName)
{ {
PLABEL_MAP pMap = s_Map; PLABEL_MAP pMap = pGlobalData->pLabelMap;
while (pMap) while (pMap)
{ {
@ -115,20 +116,20 @@ PLABEL_MAP FindLabel(PAPP_MAP pAppMap, TCHAR * szName)
} }
pMap->AppMap = pAppMap; pMap->AppMap = pAppMap;
pMap->Next = s_Map; pMap->Next = pGlobalData->pLabelMap;
s_Map = pMap; pGlobalData->pLabelMap = pMap;
return pMap; return pMap;
} }
VOID RemoveLabel(PLABEL_MAP pMap) VOID RemoveLabel(PGLOBAL_DATA pGlobalData, PLABEL_MAP pMap)
{ {
PLABEL_MAP pCurMap = s_Map; PLABEL_MAP pCurMap = pGlobalData->pLabelMap;
if (pCurMap == pMap) if (pCurMap == pMap)
{ {
s_Map = s_Map->Next; pGlobalData->pLabelMap = pGlobalData->pLabelMap->Next;
return; return;
} }
@ -143,10 +144,23 @@ VOID RemoveLabel(PLABEL_MAP pMap)
} }
} }
static
PAPP_MAP FindApp(TCHAR * szName) VOID
FreeLabelMap(PGLOBAL_DATA pGlobalData)
{ {
PAPP_MAP pMap = s_App; PLABEL_MAP pCurMap;
while (pGlobalData->pLabelMap)
{
pCurMap = pGlobalData->pLabelMap->Next;
HeapFree(GetProcessHeap(), 0, pGlobalData->pLabelMap);
pGlobalData->pLabelMap = pCurMap;
}
}
PAPP_MAP FindApp(PGLOBAL_DATA pGlobalData, TCHAR *szName)
{
PAPP_MAP pMap = pGlobalData->pAppMap;
while (pMap) while (pMap)
{ {
@ -159,8 +173,21 @@ PAPP_MAP FindApp(TCHAR * szName)
return NULL; return NULL;
} }
static
VOID
FreeAppMap(PGLOBAL_DATA pGlobalData)
{
PAPP_MAP pCurMap;
PLABEL_CONTEXT FindLabelContext(PSOUND_SCHEME_CONTEXT pSoundScheme, TCHAR * AppName, TCHAR * LabelName) while (pGlobalData->pAppMap)
{
pCurMap = pGlobalData->pAppMap->Next;
HeapFree(GetProcessHeap(), 0, pGlobalData->pAppMap);
pGlobalData->pAppMap = pCurMap;
}
}
PLABEL_CONTEXT FindLabelContext(PGLOBAL_DATA pGlobalData, PSOUND_SCHEME_CONTEXT pSoundScheme, TCHAR * AppName, TCHAR * LabelName)
{ {
PLABEL_CONTEXT pLabelContext; PLABEL_CONTEXT pLabelContext;
@ -182,8 +209,8 @@ PLABEL_CONTEXT FindLabelContext(PSOUND_SCHEME_CONTEXT pSoundScheme, TCHAR * AppN
if (!pLabelContext) if (!pLabelContext)
return NULL; return NULL;
pLabelContext->AppMap = FindApp(AppName); pLabelContext->AppMap = FindApp(pGlobalData, AppName);
pLabelContext->LabelMap = FindLabel(pLabelContext->AppMap, LabelName); pLabelContext->LabelMap = FindLabel(pGlobalData, pLabelContext->AppMap, LabelName);
ASSERT(pLabelContext->AppMap); ASSERT(pLabelContext->AppMap);
ASSERT(pLabelContext->LabelMap); ASSERT(pLabelContext->LabelMap);
pLabelContext->szValue[0] = _T('\0'); pLabelContext->szValue[0] = _T('\0');
@ -195,7 +222,7 @@ PLABEL_CONTEXT FindLabelContext(PSOUND_SCHEME_CONTEXT pSoundScheme, TCHAR * AppN
BOOL BOOL
LoadEventLabel(HKEY hKey, TCHAR * szSubKey) LoadEventLabel(PGLOBAL_DATA pGlobalData, HKEY hKey, TCHAR * szSubKey)
{ {
HKEY hSubKey; HKEY hSubKey;
DWORD cbValue; DWORD cbValue;
@ -241,26 +268,27 @@ LoadEventLabel(HKEY hKey, TCHAR * szSubKey)
{ {
return FALSE; return FALSE;
} }
pMap->szName = _tcsdup(szSubKey); pMap->szName = _tcsdup(szSubKey);
pMap->szDesc = _tcsdup(szDesc); pMap->szDesc = _tcsdup(szDesc);
pMap->szIcon = _tcsdup(szData); pMap->szIcon = _tcsdup(szData);
if (s_Map) if (pGlobalData->pLabelMap)
{ {
pMap->Next = s_Map; pMap->Next = pGlobalData->pLabelMap;
s_Map = pMap; pGlobalData->pLabelMap = pMap;
} }
else else
{ {
s_Map = pMap; pGlobalData->pLabelMap = pMap;
s_Map->Next = 0; pGlobalData->pLabelMap->Next = NULL;
} }
return TRUE; return TRUE;
} }
BOOL BOOL
LoadEventLabels() LoadEventLabels(PGLOBAL_DATA pGlobalData)
{ {
HKEY hSubKey; HKEY hSubKey;
DWORD dwCurKey; DWORD dwCurKey;
@ -293,7 +321,7 @@ LoadEventLabels()
if (dwResult == ERROR_SUCCESS) if (dwResult == ERROR_SUCCESS)
{ {
if (LoadEventLabel(hSubKey, szName)) if (LoadEventLabel(pGlobalData, hSubKey, szName))
{ {
dwCount++; dwCount++;
} }
@ -368,26 +396,24 @@ AddSoundProfile(HWND hwndDlg, HKEY hKey, TCHAR * szSubKey, BOOL SetDefault)
DWORD DWORD
EnumerateSoundProfiles(HWND hwndDlg, HKEY hKey) EnumerateSoundProfiles(PGLOBAL_DATA pGlobalData, HWND hwndDlg, HKEY hKey)
{ {
HKEY hSubKey; HKEY hSubKey;
DWORD dwName, dwCurKey, dwResult, dwNumSchemes; DWORD dwName, dwCurKey, dwResult, dwNumSchemes;
DWORD cbDefault; DWORD cbDefault;
TCHAR szName[MAX_PATH]; TCHAR szName[MAX_PATH];
cbDefault = sizeof(szDefault); cbDefault = sizeof(pGlobalData->szDefault);
if (RegQueryValueEx(hKey, if (RegQueryValueEx(hKey,
NULL, NULL,
NULL, NULL,
NULL, NULL,
(LPBYTE)szDefault, (LPBYTE)pGlobalData->szDefault,
&cbDefault) != ERROR_SUCCESS) &cbDefault) != ERROR_SUCCESS)
{ {
return FALSE; return FALSE;
} }
if (RegOpenKeyEx(hKey, if (RegOpenKeyEx(hKey,
_T("Names"), _T("Names"),
0, 0,
@ -413,7 +439,7 @@ EnumerateSoundProfiles(HWND hwndDlg, HKEY hKey)
if (dwResult == ERROR_SUCCESS) if (dwResult == ERROR_SUCCESS)
{ {
if (AddSoundProfile(hwndDlg, hSubKey, szName, (!_tcsicmp(szName, szDefault)))) if (AddSoundProfile(hwndDlg, hSubKey, szName, (!_tcsicmp(szName, pGlobalData->szDefault))))
{ {
dwNumSchemes++; dwNumSchemes++;
} }
@ -431,16 +457,18 @@ PSOUND_SCHEME_CONTEXT FindSoundProfile(HWND hwndDlg, TCHAR * szName)
{ {
LRESULT lCount, lIndex, lResult; LRESULT lCount, lIndex, lResult;
PSOUND_SCHEME_CONTEXT pScheme; PSOUND_SCHEME_CONTEXT pScheme;
HWND hwndComboBox;
lCount = ComboBox_GetCount(GetDlgItem(hwndDlg, IDC_SOUND_SCHEME)); hwndComboBox = GetDlgItem(hwndDlg, IDC_SOUND_SCHEME);
lCount = ComboBox_GetCount(hwndComboBox);
if (lCount == CB_ERR) if (lCount == CB_ERR)
{ {
return NULL; return NULL;
} }
for(lIndex = 0; lIndex < lCount; lIndex++) for (lIndex = 0; lIndex < lCount; lIndex++)
{ {
lResult = ComboBox_GetItemData(GetDlgItem(hwndDlg, IDC_SOUND_SCHEME), lIndex); lResult = ComboBox_GetItemData(hwndComboBox, lIndex);
if (lResult == CB_ERR) if (lResult == CB_ERR)
{ {
continue; continue;
@ -455,9 +483,43 @@ PSOUND_SCHEME_CONTEXT FindSoundProfile(HWND hwndDlg, TCHAR * szName)
return NULL; return NULL;
} }
static
VOID
FreeSoundProfiles(HWND hwndDlg)
{
LRESULT lCount, lIndex, lResult;
PSOUND_SCHEME_CONTEXT pScheme;
PLABEL_CONTEXT pLabelContext;
HWND hwndComboBox;
hwndComboBox = GetDlgItem(hwndDlg, IDC_SOUND_SCHEME);
lCount = ComboBox_GetCount(hwndComboBox);
if (lCount == CB_ERR)
return;
for (lIndex = 0; lIndex < lCount; lIndex++)
{
lResult = ComboBox_GetItemData(hwndComboBox, lIndex);
if (lResult == CB_ERR)
{
continue;
}
pScheme = (PSOUND_SCHEME_CONTEXT)lResult;
while (pScheme->LabelContext)
{
pLabelContext = pScheme->LabelContext->Next;
HeapFree(GetProcessHeap(), 0, pScheme->LabelContext);
pScheme->LabelContext = pLabelContext;
}
HeapFree(GetProcessHeap(), 0, pScheme);
}
}
BOOL BOOL
ImportSoundLabel(HWND hwndDlg, HKEY hKey, TCHAR * szProfile, TCHAR * szLabelName, TCHAR * szAppName, PAPP_MAP AppMap, PLABEL_MAP LabelMap) ImportSoundLabel(PGLOBAL_DATA pGlobalData, HWND hwndDlg, HKEY hKey, TCHAR * szProfile, TCHAR * szLabelName, TCHAR * szAppName, PAPP_MAP AppMap, PLABEL_MAP LabelMap)
{ {
HKEY hSubKey; HKEY hSubKey;
TCHAR szValue[MAX_PATH]; TCHAR szValue[MAX_PATH];
@ -470,7 +532,7 @@ ImportSoundLabel(HWND hwndDlg, HKEY hKey, TCHAR * szProfile, TCHAR * szLabelName
//MessageBox(hwndDlg, szProfile, szLabelName, MB_OK); //MessageBox(hwndDlg, szProfile, szLabelName, MB_OK);
bCurrentProfile = !_tcsicmp(szProfile, _T(".Current")); bCurrentProfile = !_tcsicmp(szProfile, _T(".Current"));
bActiveProfile = !_tcsicmp(szProfile, szDefault); bActiveProfile = !_tcsicmp(szProfile, pGlobalData->szDefault);
if (RegOpenKeyEx(hKey, if (RegOpenKeyEx(hKey,
szProfile, szProfile,
@ -493,7 +555,7 @@ ImportSoundLabel(HWND hwndDlg, HKEY hKey, TCHAR * szProfile, TCHAR * szLabelName
} }
if (bCurrentProfile) if (bCurrentProfile)
pScheme = FindSoundProfile(hwndDlg, szDefault); pScheme = FindSoundProfile(hwndDlg, pGlobalData->szDefault);
else else
pScheme = FindSoundProfile(hwndDlg, szProfile); pScheme = FindSoundProfile(hwndDlg, szProfile);
@ -502,7 +564,7 @@ ImportSoundLabel(HWND hwndDlg, HKEY hKey, TCHAR * szProfile, TCHAR * szLabelName
//MessageBox(hwndDlg, szProfile, _T("no profile!!"), MB_OK); //MessageBox(hwndDlg, szProfile, _T("no profile!!"), MB_OK);
return FALSE; return FALSE;
} }
pLabelContext = FindLabelContext(pScheme, AppMap->szName, LabelMap->szName); pLabelContext = FindLabelContext(pGlobalData, pScheme, AppMap->szName, LabelMap->szName);
cchLength = ExpandEnvironmentStrings(szValue, szBuffer, _countof(szBuffer)); cchLength = ExpandEnvironmentStrings(szValue, szBuffer, _countof(szBuffer));
if (cchLength == 0 || cchLength > _countof(szBuffer)) if (cchLength == 0 || cchLength > _countof(szBuffer))
@ -521,7 +583,7 @@ ImportSoundLabel(HWND hwndDlg, HKEY hKey, TCHAR * szProfile, TCHAR * szLabelName
DWORD DWORD
ImportSoundEntry(HWND hwndDlg, HKEY hKey, TCHAR * szLabelName, TCHAR * szAppName, PAPP_MAP pAppMap) ImportSoundEntry(PGLOBAL_DATA pGlobalData, HWND hwndDlg, HKEY hKey, TCHAR * szLabelName, TCHAR * szAppName, PAPP_MAP pAppMap)
{ {
HKEY hSubKey; HKEY hSubKey;
DWORD dwNumProfiles; DWORD dwNumProfiles;
@ -539,10 +601,10 @@ ImportSoundEntry(HWND hwndDlg, HKEY hKey, TCHAR * szLabelName, TCHAR * szAppName
{ {
return FALSE; return FALSE;
} }
pLabel = FindLabel(pAppMap, szLabelName); pLabel = FindLabel(pGlobalData, pAppMap, szLabelName);
ASSERT(pLabel); ASSERT(pLabel);
RemoveLabel(pLabel); RemoveLabel(pGlobalData, pLabel);
pLabel->AppMap = pAppMap; pLabel->AppMap = pAppMap;
pLabel->Next = pAppMap->LabelMap; pLabel->Next = pAppMap->LabelMap;
@ -564,7 +626,7 @@ ImportSoundEntry(HWND hwndDlg, HKEY hKey, TCHAR * szLabelName, TCHAR * szAppName
if (dwResult == ERROR_SUCCESS) if (dwResult == ERROR_SUCCESS)
{ {
if (ImportSoundLabel(hwndDlg, hSubKey, szProfile, szLabelName, szAppName, pAppMap, pLabel)) if (ImportSoundLabel(pGlobalData, hwndDlg, hSubKey, szProfile, szLabelName, szAppName, pAppMap, pLabel))
{ {
dwNumProfiles++; dwNumProfiles++;
} }
@ -580,7 +642,7 @@ ImportSoundEntry(HWND hwndDlg, HKEY hKey, TCHAR * szLabelName, TCHAR * szAppName
DWORD DWORD
ImportAppProfile(HWND hwndDlg, HKEY hKey, TCHAR * szAppName) ImportAppProfile(PGLOBAL_DATA pGlobalData, HWND hwndDlg, HKEY hKey, TCHAR * szAppName)
{ {
HKEY hSubKey; HKEY hSubKey;
TCHAR szDefault[MAX_PATH]; TCHAR szDefault[MAX_PATH];
@ -638,8 +700,8 @@ ImportAppProfile(HWND hwndDlg, HKEY hKey, TCHAR * szAppName)
_tcscpy(AppMap->szDesc, szDefault); _tcscpy(AppMap->szDesc, szDefault);
_tcscpy(AppMap->szIcon, szIcon); _tcscpy(AppMap->szIcon, szIcon);
AppMap->Next = s_App; AppMap->Next = pGlobalData->pAppMap;
s_App = AppMap; pGlobalData->pAppMap = AppMap;
dwCurKey = 0; dwCurKey = 0;
@ -657,7 +719,7 @@ ImportAppProfile(HWND hwndDlg, HKEY hKey, TCHAR * szAppName)
NULL); NULL);
if (dwResult == ERROR_SUCCESS) if (dwResult == ERROR_SUCCESS)
{ {
if (ImportSoundEntry(hwndDlg, hSubKey, szName, szAppName, AppMap)) if (ImportSoundEntry(pGlobalData, hwndDlg, hSubKey, szName, szAppName, AppMap))
{ {
dwNumEntry++; dwNumEntry++;
} }
@ -671,7 +733,7 @@ ImportAppProfile(HWND hwndDlg, HKEY hKey, TCHAR * szAppName)
BOOL BOOL
ImportSoundProfiles(HWND hwndDlg, HKEY hKey) ImportSoundProfiles(PGLOBAL_DATA pGlobalData, HWND hwndDlg, HKEY hKey)
{ {
DWORD dwCurKey; DWORD dwCurKey;
DWORD dwResult; DWORD dwResult;
@ -699,7 +761,7 @@ ImportSoundProfiles(HWND hwndDlg, HKEY hKey)
if (dwResult == ERROR_SUCCESS) if (dwResult == ERROR_SUCCESS)
{ {
if (ImportAppProfile(hwndDlg, hSubKey, szName)) if (ImportAppProfile(pGlobalData, hwndDlg, hSubKey, szName))
{ {
dwNumApps++; dwNumApps++;
} }
@ -714,7 +776,7 @@ ImportSoundProfiles(HWND hwndDlg, HKEY hKey)
BOOL BOOL
LoadSoundProfiles(HWND hwndDlg) LoadSoundProfiles(PGLOBAL_DATA pGlobalData, HWND hwndDlg)
{ {
HKEY hSubKey; HKEY hSubKey;
DWORD dwNumSchemes; DWORD dwNumSchemes;
@ -728,13 +790,13 @@ LoadSoundProfiles(HWND hwndDlg)
return FALSE; return FALSE;
} }
dwNumSchemes = EnumerateSoundProfiles(hwndDlg, hSubKey); dwNumSchemes = EnumerateSoundProfiles(pGlobalData, hwndDlg, hSubKey);
if (dwNumSchemes) if (dwNumSchemes)
{ {
//MessageBox(hwndDlg, _T("importing sound profiles..."), NULL, MB_OK); //MessageBox(hwndDlg, _T("importing sound profiles..."), NULL, MB_OK);
ImportSoundProfiles(hwndDlg, hSubKey); ImportSoundProfiles(pGlobalData, hwndDlg, hSubKey);
} }
RegCloseKey(hSubKey); RegCloseKey(hSubKey);
@ -808,7 +870,7 @@ LoadSoundFiles(HWND hwndDlg)
BOOL BOOL
ShowSoundScheme(HWND hwndDlg) ShowSoundScheme(PGLOBAL_DATA pGlobalData, HWND hwndDlg)
{ {
LRESULT lIndex; LRESULT lIndex;
PSOUND_SCHEME_CONTEXT pScheme; PSOUND_SCHEME_CONTEXT pScheme;
@ -822,9 +884,9 @@ ShowSoundScheme(HWND hwndDlg)
hDlgCtrl = GetDlgItem(hwndDlg, IDC_SOUND_SCHEME); hDlgCtrl = GetDlgItem(hwndDlg, IDC_SOUND_SCHEME);
hList = GetDlgItem(hwndDlg, IDC_SCHEME_LIST); hList = GetDlgItem(hwndDlg, IDC_SCHEME_LIST);
if (hSoundsImageList != NULL) if (pGlobalData->hSoundsImageList != NULL)
{ {
TreeView_SetImageList(hList, hSoundsImageList, TVSIL_NORMAL); TreeView_SetImageList(hList, pGlobalData->hSoundsImageList, TVSIL_NORMAL);
} }
lIndex = SendMessage(hDlgCtrl, CB_GETCURSEL, (WPARAM)0, (LPARAM)0); lIndex = SendMessage(hDlgCtrl, CB_GETCURSEL, (WPARAM)0, (LPARAM)0);
@ -840,9 +902,9 @@ ShowSoundScheme(HWND hwndDlg)
} }
pScheme = (PSOUND_SCHEME_CONTEXT)lIndex; pScheme = (PSOUND_SCHEME_CONTEXT)lIndex;
_tcscpy(szDefault, pScheme->szName); _tcscpy(pGlobalData->szDefault, pScheme->szName);
pAppMap = s_App; pAppMap = pGlobalData->pAppMap;
while (pAppMap) while (pAppMap)
{ {
ZeroMemory(&tvItem, sizeof(tvItem)); ZeroMemory(&tvItem, sizeof(tvItem));
@ -862,10 +924,10 @@ ShowSoundScheme(HWND hwndDlg)
pLabelMap = pAppMap->LabelMap; pLabelMap = pAppMap->LabelMap;
while (pLabelMap) while (pLabelMap)
{ {
pLabelContext = FindLabelContext(pScheme, pAppMap->szName, pLabelMap->szName); pLabelContext = FindLabelContext(pGlobalData, pScheme, pAppMap->szName, pLabelMap->szName);
ZeroMemory(&tvItem, sizeof(tvItem)); ZeroMemory(&tvItem, sizeof(tvItem));
tvItem.hParent = /*TVI_ROOT;*/ hTreeItem; tvItem.hParent = hTreeItem;
tvItem.hInsertAfter = TVI_SORT; tvItem.hInsertAfter = TVI_SORT;
tvItem.item.mask = TVIF_STATE | TVIF_TEXT | TVIF_PARAM | TVIF_IMAGE | TVIF_SELECTEDIMAGE; tvItem.item.mask = TVIF_STATE | TVIF_TEXT | TVIF_PARAM | TVIF_IMAGE | TVIF_SELECTEDIMAGE;
@ -882,7 +944,7 @@ ShowSoundScheme(HWND hwndDlg)
tvItem.item.iImage = IMAGE_SOUND_NONE; tvItem.item.iImage = IMAGE_SOUND_NONE;
tvItem.item.iSelectedImage = IMAGE_SOUND_NONE; tvItem.item.iSelectedImage = IMAGE_SOUND_NONE;
} }
tvItem.item.lParam = (LPARAM)FindLabelContext(pScheme, pAppMap->szName, pLabelMap->szName); tvItem.item.lParam = (LPARAM)FindLabelContext(pGlobalData, pScheme, pAppMap->szName, pLabelMap->szName);
TreeView_InsertItem(hList, &tvItem); TreeView_InsertItem(hList, &tvItem);
@ -1031,32 +1093,39 @@ SoundsDlgProc(HWND hwndDlg,
WPARAM wParam, WPARAM wParam,
LPARAM lParam) LPARAM lParam)
{ {
PGLOBAL_DATA pGlobalData;
OPENFILENAMEW ofn; OPENFILENAMEW ofn;
WCHAR filename[MAX_PATH]; WCHAR filename[MAX_PATH];
WCHAR szFilter[256], szTitle[256]; WCHAR szFilter[256], szTitle[256];
LPWSTR pFileName; LPWSTR pFileName;
LRESULT lResult; LRESULT lResult;
pGlobalData = (PGLOBAL_DATA)GetWindowLongPtr(hwndDlg, DWLP_USER);
switch (uMsg) switch (uMsg)
{ {
case WM_INITDIALOG: case WM_INITDIALOG:
{ {
UINT NumWavOut = waveOutGetNumDevs(); UINT NumWavOut = waveOutGetNumDevs();
pGlobalData = (PGLOBAL_DATA)HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(GLOBAL_DATA));
SetWindowLongPtr(hwndDlg, DWLP_USER, (LONG_PTR)pGlobalData);
SendMessage(GetDlgItem(hwndDlg, IDC_PLAY_SOUND), SendMessage(GetDlgItem(hwndDlg, IDC_PLAY_SOUND),
BM_SETIMAGE,(WPARAM)IMAGE_ICON, BM_SETIMAGE,(WPARAM)IMAGE_ICON,
(LPARAM)(HANDLE)LoadIcon(hApplet, MAKEINTRESOURCE(IDI_PLAY_ICON))); (LPARAM)(HANDLE)LoadIcon(hApplet, MAKEINTRESOURCE(IDI_PLAY_ICON)));
hSoundsImageList = InitImageList(IDI_SOUND_SECTION, pGlobalData->hSoundsImageList = InitImageList(IDI_SOUND_SECTION,
IDI_SOUND_ASSIGNED, IDI_SOUND_ASSIGNED,
GetSystemMetrics(SM_CXSMICON), GetSystemMetrics(SM_CXSMICON),
GetSystemMetrics(SM_CXSMICON), GetSystemMetrics(SM_CXSMICON),
IMAGE_ICON); IMAGE_ICON);
LoadEventLabels(); LoadEventLabels(pGlobalData);
LoadSoundProfiles(hwndDlg); LoadSoundProfiles(pGlobalData, hwndDlg);
LoadSoundFiles(hwndDlg); LoadSoundFiles(hwndDlg);
ShowSoundScheme(hwndDlg); ShowSoundScheme(pGlobalData, hwndDlg);
if (!NumWavOut) if (!NumWavOut)
{ {
@ -1132,7 +1201,7 @@ SoundsDlgProc(HWND hwndDlg,
if (HIWORD(wParam) == CBN_SELENDOK) if (HIWORD(wParam) == CBN_SELENDOK)
{ {
(void)TreeView_DeleteAllItems(GetDlgItem(hwndDlg, IDC_SCHEME_LIST)); (void)TreeView_DeleteAllItems(GetDlgItem(hwndDlg, IDC_SCHEME_LIST));
ShowSoundScheme(hwndDlg); ShowSoundScheme(pGlobalData, hwndDlg);
EnableWindow(GetDlgItem(hwndDlg, IDC_SOUND_LIST), FALSE); EnableWindow(GetDlgItem(hwndDlg, IDC_SOUND_LIST), FALSE);
EnableWindow(GetDlgItem(hwndDlg, IDC_TEXT_SOUND), FALSE); EnableWindow(GetDlgItem(hwndDlg, IDC_TEXT_SOUND), FALSE);
EnableWindow(GetDlgItem(hwndDlg, IDC_PLAY_SOUND), FALSE); EnableWindow(GetDlgItem(hwndDlg, IDC_PLAY_SOUND), FALSE);
@ -1205,8 +1274,12 @@ SoundsDlgProc(HWND hwndDlg,
} }
case WM_DESTROY: case WM_DESTROY:
{ {
if (hSoundsImageList) FreeSoundProfiles(hwndDlg);
ImageList_Destroy(hSoundsImageList); FreeAppMap(pGlobalData);
FreeLabelMap(pGlobalData);
if (pGlobalData->hSoundsImageList)
ImageList_Destroy(pGlobalData->hSoundsImageList);
HeapFree(GetProcessHeap(), 0, pGlobalData);
break; break;
} }
case WM_NOTIFY: case WM_NOTIFY: