ReactOS Fundraising Campaign 2012
 
€ 4,410 / € 30,000

Information | Donate

Home | Info | Community | Development | myReactOS | Contact Us

  1. Home
  2. Community
  3. Development
  4. myReactOS
  5. Fundraiser 2012

  1. Main Page
  2. Alphabetical List
  3. Data Structures
  4. Directories
  5. File List
  6. Data Fields
  7. Globals
  8. Related Pages

ReactOS Development > Doxygen

sounds.c
Go to the documentation of this file.
00001 /* $Id: main.c 12852 2005-01-06 13:58:04Z mf $
00002  *
00003  * PROJECT:         ReactOS Multimedia Control Panel
00004  * FILE:            dll/cpl/mmsys/mmsys.c
00005  * PURPOSE:         ReactOS Multimedia Control Panel
00006  * PROGRAMMER:      Thomas Weidenmueller <w3seek@reactos.com>
00007  *                  Johannes Anderwald <janderwald@reactos.com>
00008  *                  Dmitry Chapyshev <dmitry@reactos.org>
00009  */
00010 
00011 #include "mmsys.h"
00012 
00013 struct __APP_MAP__;
00014 
00015 typedef struct __LABEL_MAP__
00016 {
00017     TCHAR * szName;
00018     TCHAR * szDesc;
00019     TCHAR * szIcon;
00020     struct __APP_MAP__ * AppMap;
00021     struct __LABEL_MAP__ * Next;
00022 } LABEL_MAP, *PLABEL_MAP;
00023 
00024 typedef struct __APP_MAP__
00025 {
00026     TCHAR szName[MAX_PATH];
00027     TCHAR szDesc[MAX_PATH];
00028     TCHAR szIcon[MAX_PATH];
00029 
00030     struct __APP_MAP__ *Next;
00031     PLABEL_MAP LabelMap;
00032 } APP_MAP, *PAPP_MAP;
00033 
00034 typedef struct __LABEL_CONTEXT__
00035 {
00036     PLABEL_MAP LabelMap;
00037     PAPP_MAP AppMap;
00038     TCHAR szValue[MAX_PATH];
00039     struct __LABEL_CONTEXT__ *Next;
00040 } LABEL_CONTEXT, *PLABEL_CONTEXT;
00041 
00042 typedef struct __SOUND_SCHEME_CONTEXT__
00043 {
00044     TCHAR szName[MAX_PATH];
00045     TCHAR szDesc[MAX_PATH];
00046     PLABEL_CONTEXT LabelContext;
00047 } SOUND_SCHEME_CONTEXT, *PSOUND_SCHEME_CONTEXT;
00048 
00049 static PLABEL_MAP s_Map = NULL;
00050 static PAPP_MAP s_App = NULL;
00051 
00052 TCHAR szDefault[MAX_PATH];
00053 
00054 
00055 PLABEL_MAP FindLabel(PAPP_MAP pAppMap, TCHAR * szName)
00056 {
00057     PLABEL_MAP pMap = s_Map;
00058 
00059     while (pMap)
00060     {
00061         ASSERT(pMap);
00062         ASSERT(pMap->szName);
00063         if (!_tcscmp(pMap->szName, szName))
00064             return pMap;
00065 
00066         pMap = pMap->Next;
00067     }
00068 
00069     pMap = pAppMap->LabelMap;
00070 
00071     while (pMap)
00072     {
00073         ASSERT(pMap);
00074         ASSERT(pMap->szName);
00075         if (!_tcscmp(pMap->szName, szName))
00076             return pMap;
00077 
00078         pMap = pMap->Next;
00079     }
00080 
00081     pMap = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(LABEL_MAP));
00082     if (!pMap)
00083         return NULL;
00084 
00085     pMap->szName = pMap->szDesc = _tcsdup(szName);
00086     if (!pMap->szName)
00087     {
00088         HeapFree(GetProcessHeap(), 0, pMap);
00089         return NULL;
00090     }
00091 
00092     pMap->AppMap = pAppMap;
00093     pMap->Next = s_Map;
00094     s_Map = pMap;
00095 
00096     return pMap;
00097 }
00098 
00099 
00100 VOID RemoveLabel(PLABEL_MAP pMap)
00101 {
00102     PLABEL_MAP pCurMap = s_Map;
00103 
00104     if (pCurMap == pMap)
00105     {
00106         s_Map = s_Map->Next;
00107         return;
00108     }
00109 
00110     while (pCurMap)
00111     {
00112         if (pCurMap->Next == pMap)
00113         {
00114             pCurMap->Next = pCurMap->Next->Next;
00115             return;
00116         }
00117         pCurMap = pCurMap->Next;
00118     }
00119 }
00120 
00121 
00122 PAPP_MAP FindApp(TCHAR * szName)
00123 {
00124     PAPP_MAP pMap = s_App;
00125 
00126     while (pMap)
00127     {
00128         if (!_tcscmp(pMap->szName, szName))
00129             return pMap;
00130 
00131         pMap = pMap->Next;
00132 
00133     }
00134     return NULL;
00135 }
00136 
00137 
00138 PLABEL_CONTEXT FindLabelContext(PSOUND_SCHEME_CONTEXT pSoundScheme, TCHAR * AppName, TCHAR * LabelName)
00139 {
00140     PLABEL_CONTEXT pLabelContext;
00141 
00142     pLabelContext = pSoundScheme->LabelContext;
00143 
00144     while (pLabelContext)
00145     {
00146         ASSERT(pLabelContext->AppMap);
00147         ASSERT(pLabelContext->LabelMap);
00148 
00149         if (!_tcsicmp(pLabelContext->AppMap->szName, AppName) && !_tcsicmp(pLabelContext->LabelMap->szName, LabelName))
00150         {
00151             return pLabelContext;
00152         }
00153         pLabelContext = pLabelContext->Next;
00154     }
00155 
00156     pLabelContext = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(LABEL_CONTEXT));
00157     if (!pLabelContext)
00158         return NULL;
00159 
00160     pLabelContext->AppMap = FindApp(AppName);
00161     pLabelContext->LabelMap = FindLabel(pLabelContext->AppMap, LabelName);
00162     ASSERT(pLabelContext->AppMap);
00163     ASSERT(pLabelContext->LabelMap);
00164     pLabelContext->szValue[0] = _T('\0');
00165     pLabelContext->Next = pSoundScheme->LabelContext;
00166     pSoundScheme->LabelContext = pLabelContext;
00167 
00168     return pLabelContext;
00169 }
00170 
00171 
00172 BOOL
00173 LoadEventLabel(HKEY hKey, TCHAR * szSubKey)
00174 {
00175     HKEY hSubKey;
00176     DWORD dwData;
00177     DWORD dwDesc;
00178     TCHAR szDesc[MAX_PATH];
00179     TCHAR szData[MAX_PATH];
00180     PLABEL_MAP pMap;
00181 
00182     if (RegOpenKeyEx(hKey,
00183                      szSubKey,
00184                      0,
00185                      KEY_READ,
00186                      &hSubKey) != ERROR_SUCCESS)
00187     {
00188         return FALSE;
00189     }
00190 
00191     dwDesc = sizeof(szDesc) / sizeof(TCHAR);
00192     if (RegQueryValueEx(hSubKey,
00193                       NULL,
00194                       NULL,
00195                       NULL,
00196                       (LPBYTE)szDesc,
00197                       &dwDesc) != ERROR_SUCCESS)
00198     {
00199         RegCloseKey(hSubKey);
00200         return FALSE;
00201     }
00202 
00203     dwData = sizeof(szDesc) / sizeof(TCHAR);
00204     if (RegQueryValueEx(hSubKey,
00205                         _T("DispFileName"),
00206                         NULL,
00207                         NULL,
00208                         (LPBYTE)szData,
00209                         &dwData) != ERROR_SUCCESS)
00210     {
00211         RegCloseKey(hSubKey);
00212         return FALSE;
00213     }
00214 
00215     pMap = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(LABEL_MAP));
00216     if (!pMap)
00217     {
00218         return FALSE;
00219     }
00220     pMap->szName = _tcsdup(szSubKey);
00221     pMap->szDesc = _tcsdup(szDesc);
00222     pMap->szIcon = _tcsdup(szData);
00223 
00224     if (s_Map)
00225     {
00226         pMap->Next = s_Map;
00227         s_Map = pMap;
00228     }
00229     else
00230     {
00231         s_Map = pMap;
00232         s_Map->Next = 0;
00233     }
00234     return TRUE;
00235 }
00236 
00237 
00238 BOOL
00239 LoadEventLabels()
00240 {
00241     HKEY hSubKey;
00242     DWORD dwCurKey;
00243     TCHAR szName[MAX_PATH];
00244     DWORD dwName;
00245     DWORD dwResult;
00246     DWORD dwCount;
00247     if (RegOpenKeyEx(HKEY_CURRENT_USER,
00248                      _T("AppEvents\\EventLabels"),
00249                      0,
00250                      KEY_READ,
00251                      &hSubKey) != ERROR_SUCCESS)
00252     {
00253         return FALSE;
00254     }
00255 
00256     dwCurKey = 0;
00257     dwCount = 0;
00258     do
00259     {
00260         dwName = sizeof(szName) / sizeof(szName[0]);
00261         dwResult = RegEnumKeyEx(hSubKey,
00262                                 dwCurKey,
00263                                 szName,
00264                                 &dwName,
00265                                 NULL,
00266                                 NULL,
00267                                 NULL,
00268                                 NULL);
00269 
00270         if (dwResult == ERROR_SUCCESS)
00271         {
00272             if (LoadEventLabel(hSubKey, szName))
00273             {
00274                 dwCount++;
00275             }
00276         }
00277         dwCurKey++;
00278 
00279     } while (dwResult == ERROR_SUCCESS);
00280 
00281     RegCloseKey(hSubKey);
00282     return (dwCount != 0);
00283 }
00284 
00285 
00286 BOOL
00287 AddSoundProfile(HWND hwndDlg, HKEY hKey, TCHAR * szSubKey, BOOL SetDefault)
00288 {
00289     HKEY hSubKey;
00290     TCHAR szValue[MAX_PATH];
00291     DWORD dwValue, dwResult;
00292 
00293     if (RegOpenKeyEx(hKey,
00294                      szSubKey,
00295                      0,
00296                      KEY_READ,
00297                      &hSubKey) != ERROR_SUCCESS)
00298     {
00299         return FALSE;
00300     }
00301 
00302     dwValue = sizeof(szValue) / sizeof(TCHAR);
00303     dwResult = RegQueryValueEx(hSubKey,
00304                                NULL,
00305                                NULL,
00306                                NULL,
00307                                (LPBYTE)szValue,
00308                                &dwValue);
00309     RegCloseKey(hSubKey);
00310     if (dwResult == ERROR_SUCCESS)
00311     {
00312         LRESULT lResult = SendDlgItemMessage(hwndDlg, IDC_SOUND_SCHEME, CB_ADDSTRING, (WPARAM)0, (LPARAM)szValue);
00313         if (lResult != CB_ERR)
00314         {
00315             PSOUND_SCHEME_CONTEXT pScheme = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(SOUND_SCHEME_CONTEXT));
00316             if (pScheme != NULL)
00317             {
00318                 _tcscpy(pScheme->szDesc, szValue);
00319                 _tcscpy(pScheme->szName, szSubKey);
00320             }
00321 
00322             SendDlgItemMessage(hwndDlg, IDC_SOUND_SCHEME, CB_SETITEMDATA, (WPARAM)lResult, (LPARAM)pScheme);
00323             if (SetDefault)
00324             {
00325                 SendDlgItemMessage(hwndDlg, IDC_SOUND_SCHEME, CB_SETCURSEL, (WPARAM)lResult, (LPARAM)0);
00326             }
00327         }
00328         return TRUE;
00329     }
00330     return FALSE;
00331 }
00332 
00333 
00334 DWORD
00335 EnumerateSoundProfiles(HWND hwndDlg, HKEY hKey)
00336 {
00337     HKEY hSubKey;
00338     DWORD dwName, dwCurKey, dwResult, dwNumSchemes;
00339     TCHAR szName[MAX_PATH];
00340 
00341     dwName = sizeof(szDefault) / sizeof(TCHAR);
00342     if (RegQueryValueEx(hKey,
00343                         NULL,
00344                         NULL,
00345                         NULL,
00346                         (LPBYTE)szDefault,
00347                         &dwName) != ERROR_SUCCESS)
00348     {
00349         return FALSE;
00350     }
00351 
00352 
00353 
00354     if (RegOpenKeyEx(hKey,
00355                      _T("Names"),
00356                      0,
00357                      KEY_READ,
00358                      &hSubKey) != ERROR_SUCCESS)
00359     {
00360         return FALSE;
00361     }
00362 
00363     dwNumSchemes = 0;
00364     dwCurKey = 0;
00365     do
00366     {
00367         dwName = sizeof(szName) / sizeof(szName[0]);
00368         dwResult = RegEnumKeyEx(hSubKey,
00369                                 dwCurKey,
00370                                 szName,
00371                                 &dwName,
00372                                 NULL,
00373                                 NULL,
00374                                 NULL,
00375                                 NULL);
00376 
00377         if (dwResult == ERROR_SUCCESS)
00378         {
00379             if (AddSoundProfile(hwndDlg, hSubKey, szName, (!_tcsicmp(szName, szDefault))))
00380             {
00381                 dwNumSchemes++;
00382             }
00383         }
00384 
00385         dwCurKey++;
00386     } while (dwResult == ERROR_SUCCESS);
00387 
00388     RegCloseKey(hSubKey);
00389     return dwNumSchemes;
00390 }
00391 
00392 
00393 PSOUND_SCHEME_CONTEXT FindSoundProfile(HWND hwndDlg, TCHAR * szName)
00394 {
00395     LRESULT lCount, lIndex, lResult;
00396     PSOUND_SCHEME_CONTEXT pScheme;
00397 
00398     lCount = SendDlgItemMessage(hwndDlg, IDC_SOUND_SCHEME, CB_GETCOUNT, (WPARAM)0, (LPARAM)0);
00399     if (lCount == CB_ERR)
00400     {
00401         return NULL;
00402     }
00403 
00404     for(lIndex = 0; lIndex < lCount; lIndex++)
00405     {
00406         lResult = SendDlgItemMessage(hwndDlg, IDC_SOUND_SCHEME, CB_GETITEMDATA, (WPARAM)lIndex, (LPARAM)0);
00407         if (lResult == CB_ERR)
00408         {
00409             continue;
00410         }
00411 
00412         pScheme = (PSOUND_SCHEME_CONTEXT)lResult;
00413         if (!_tcsicmp(pScheme->szName, szName))
00414         {
00415             return pScheme;
00416         }
00417     }
00418     return NULL;
00419 }
00420 
00421 
00422 BOOL
00423 ImportSoundLabel(HWND hwndDlg, HKEY hKey, TCHAR * szProfile, TCHAR * szLabelName, TCHAR * szAppName, PAPP_MAP AppMap, PLABEL_MAP LabelMap)
00424 {
00425     HKEY hSubKey;
00426     TCHAR szValue[MAX_PATH];
00427     TCHAR szBuffer[MAX_PATH];
00428     DWORD dwValue;
00429     PSOUND_SCHEME_CONTEXT pScheme;
00430     PLABEL_CONTEXT pLabelContext;
00431     BOOL bCurrentProfile, bActiveProfile;
00432 
00433     //MessageBox(hwndDlg, szProfile, szLabelName, MB_OK);
00434 
00435     bCurrentProfile = !_tcsicmp(szProfile, _T(".Current"));
00436     bActiveProfile = !_tcsicmp(szProfile, szDefault);
00437 
00438     if (RegOpenKeyEx(hKey,
00439                      szProfile,
00440                      0,
00441                      KEY_READ,
00442                      &hSubKey) != ERROR_SUCCESS)
00443     {
00444         return FALSE;
00445     }
00446 
00447     dwValue = sizeof(szValue) / sizeof(TCHAR);
00448     if (RegQueryValueEx(hSubKey,
00449                         NULL,
00450                         NULL,
00451                         NULL,
00452                         (LPBYTE)szValue,
00453                         &dwValue) != ERROR_SUCCESS)
00454     {
00455         return FALSE;
00456     }
00457 
00458     if (bCurrentProfile)
00459         pScheme = FindSoundProfile(hwndDlg, szDefault);
00460     else
00461         pScheme = FindSoundProfile(hwndDlg, szProfile);
00462 
00463     if (!pScheme)
00464     {
00465         //MessageBox(hwndDlg, szProfile, _T("no profile!!"), MB_OK);
00466         return FALSE;
00467     }
00468     pLabelContext = FindLabelContext(pScheme, AppMap->szName, LabelMap->szName);
00469 
00470     dwValue = ExpandEnvironmentStrings(szValue, szBuffer, sizeof(szBuffer) / sizeof(TCHAR));
00471     if (dwValue == 0 || dwValue > (sizeof(szBuffer) / sizeof(TCHAR)))
00472     {
00473         /* fixme */
00474         return FALSE;
00475     }
00476 
00477     if (bCurrentProfile)
00478         _tcscpy(pLabelContext->szValue, szBuffer);
00479     else if (!bActiveProfile)
00480         _tcscpy(pLabelContext->szValue, szBuffer);
00481 
00482     return TRUE;
00483 }
00484 
00485 
00486 DWORD
00487 ImportSoundEntry(HWND hwndDlg, HKEY hKey, TCHAR * szLabelName, TCHAR * szAppName, PAPP_MAP pAppMap)
00488 {
00489     HKEY hSubKey;
00490     DWORD dwNumProfiles;
00491     DWORD dwCurKey;
00492     DWORD dwResult;
00493     DWORD dwProfile;
00494     TCHAR szProfile[MAX_PATH];
00495     PLABEL_MAP pLabel;
00496 
00497     if (RegOpenKeyEx(hKey,
00498                      szLabelName,
00499                      0,
00500                      KEY_READ,
00501                      &hSubKey) != ERROR_SUCCESS)
00502     {
00503         return FALSE;
00504     }
00505     pLabel = FindLabel(pAppMap, szLabelName);
00506 
00507     ASSERT(pLabel);
00508     RemoveLabel(pLabel);
00509 
00510     pLabel->AppMap = pAppMap;
00511     pLabel->Next = pAppMap->LabelMap;
00512     pAppMap->LabelMap = pLabel;
00513 
00514     dwNumProfiles = 0;
00515     dwCurKey = 0;
00516     do
00517     {
00518         dwProfile = sizeof(szProfile) / sizeof(TCHAR);
00519         dwResult = RegEnumKeyEx(hSubKey,
00520                                 dwCurKey,
00521                                 szProfile,
00522                                 &dwProfile,
00523                                 NULL,
00524                                 NULL,
00525                                 NULL,
00526                                 NULL);
00527 
00528         if (dwResult == ERROR_SUCCESS)
00529         {
00530             if (ImportSoundLabel(hwndDlg, hSubKey, szProfile, szLabelName, szAppName, pAppMap, pLabel))
00531             {
00532                 dwNumProfiles++;
00533             }
00534         }
00535 
00536         dwCurKey++;
00537     } while (dwResult == ERROR_SUCCESS);
00538 
00539     RegCloseKey(hSubKey);
00540 
00541     return dwNumProfiles;
00542 }
00543 
00544 
00545 DWORD
00546 ImportAppProfile(HWND hwndDlg, HKEY hKey, TCHAR * szAppName)
00547 {
00548     HKEY hSubKey;
00549     TCHAR szDefault[MAX_PATH];
00550     DWORD dwDefault;
00551     DWORD dwCurKey;
00552     DWORD dwResult;
00553     DWORD dwNumEntry;
00554     DWORD dwName;
00555     TCHAR szName[MAX_PATH];
00556     TCHAR szIcon[MAX_PATH];
00557     PAPP_MAP AppMap;
00558 
00559     //MessageBox(hwndDlg, szAppName, _T("Importing...\n"), MB_OK);
00560 
00561     AppMap = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(APP_MAP));
00562     if (!AppMap)
00563         return 0;
00564 
00565     if (RegOpenKeyEx(hKey,
00566                      szAppName,
00567                      0,
00568                      KEY_READ,
00569                      &hSubKey) != ERROR_SUCCESS)
00570     {
00571         HeapFree(GetProcessHeap(), 0, AppMap);
00572         return 0;
00573     }
00574 
00575     dwDefault = sizeof(szDefault) / sizeof(TCHAR);
00576     if (RegQueryValueEx(hSubKey,
00577                         NULL,
00578                         NULL,
00579                         NULL,
00580                         (LPBYTE)szDefault,
00581                         &dwDefault) != ERROR_SUCCESS)
00582     {
00583         RegCloseKey(hSubKey);
00584         HeapFree(GetProcessHeap(), 0, AppMap);
00585         return 0;
00586     }
00587 
00588     dwDefault = sizeof(szIcon) / sizeof(TCHAR);
00589     if (RegQueryValueEx(hSubKey,
00590                         _T("DispFileName"),
00591                         NULL,
00592                         NULL,
00593                         (LPBYTE)szIcon,
00594                         &dwDefault) != ERROR_SUCCESS)
00595     {
00596         szIcon[0] = _T('\0');
00597     }
00598 
00599     /* initialize app map */
00600     _tcscpy(AppMap->szName, szAppName);
00601     _tcscpy(AppMap->szDesc, szDefault);
00602     _tcscpy(AppMap->szIcon, szIcon);
00603 
00604     AppMap->Next = s_App;
00605     s_App = AppMap;
00606 
00607 
00608     dwCurKey = 0;
00609     dwNumEntry = 0;
00610     do
00611     {
00612         dwName = sizeof(szName) / sizeof(TCHAR);
00613         dwResult = RegEnumKeyEx(hSubKey,
00614                               dwCurKey,
00615                               szName,
00616                               &dwName,
00617                               NULL,
00618                               NULL,
00619                               NULL,
00620                               NULL);
00621         if (dwResult == ERROR_SUCCESS)
00622         {
00623             if (ImportSoundEntry(hwndDlg, hSubKey, szName, szAppName, AppMap))
00624             {
00625                 dwNumEntry++;
00626             }
00627         }
00628         dwCurKey++;
00629     } while (dwResult == ERROR_SUCCESS);
00630 
00631     RegCloseKey(hSubKey);
00632     return dwNumEntry;
00633 }
00634 
00635 
00636 BOOL
00637 ImportSoundProfiles(HWND hwndDlg, HKEY hKey)
00638 {
00639     DWORD dwCurKey;
00640     DWORD dwResult;
00641     DWORD dwNumApps;
00642     TCHAR szName[MAX_PATH];
00643     HKEY hSubKey;
00644 
00645     if (RegOpenKeyEx(hKey,
00646                      _T("Apps"),
00647                      0,
00648                      KEY_READ,
00649                      &hSubKey) != ERROR_SUCCESS)
00650     {
00651         return FALSE;
00652     }
00653 
00654     dwNumApps = 0;
00655     dwCurKey = 0;
00656     do
00657     {
00658         dwResult = RegEnumKey(hSubKey,
00659                               dwCurKey,
00660                               szName,
00661                               sizeof(szName) / sizeof(TCHAR));
00662 
00663         if (dwResult == ERROR_SUCCESS)
00664         {
00665             if (ImportAppProfile(hwndDlg, hSubKey, szName))
00666             {
00667                 dwNumApps++;
00668             }
00669         }
00670         dwCurKey++;
00671     } while (dwResult == ERROR_SUCCESS);
00672 
00673     RegCloseKey(hSubKey);
00674 
00675     return (dwNumApps != 0);
00676 }
00677 
00678 
00679 BOOL
00680 LoadSoundProfiles(HWND hwndDlg)
00681 {
00682     HKEY hSubKey;
00683     DWORD dwNumSchemes;
00684 
00685     if (RegOpenKeyEx(HKEY_CURRENT_USER,
00686                      _T("AppEvents\\Schemes"),
00687                      0,
00688                      KEY_READ,
00689                      &hSubKey) != ERROR_SUCCESS)
00690     {
00691         return FALSE;
00692     }
00693 
00694     dwNumSchemes = EnumerateSoundProfiles(hwndDlg, hSubKey);
00695 
00696 
00697     if (dwNumSchemes)
00698     {
00699         //MessageBox(hwndDlg, _T("importing sound profiles..."), NULL, MB_OK);
00700         ImportSoundProfiles(hwndDlg, hSubKey);
00701     }
00702 
00703     RegCloseKey(hSubKey);
00704     return FALSE;
00705 }
00706 
00707 
00708 BOOL
00709 LoadSoundFiles(HWND hwndDlg)
00710 {
00711     WCHAR szPath[MAX_PATH];
00712     WCHAR * ptr;
00713     WIN32_FIND_DATAW FileData;
00714     HANDLE hFile;
00715     LRESULT lResult;
00716     UINT length;
00717 
00718     /* Add no sound listview item */
00719     if (LoadString(hApplet, IDS_NO_SOUND, szPath, MAX_PATH))
00720     {
00721         szPath[(sizeof(szPath)/sizeof(WCHAR))-1] = L'\0';
00722         SendDlgItemMessageW(hwndDlg, IDC_SOUND_LIST, CB_ADDSTRING, (WPARAM)0, (LPARAM)szPath);
00723     }
00724 
00725     /* Load sound files */
00726     length = GetWindowsDirectoryW(szPath, MAX_PATH);
00727     if (length == 0 || length >= MAX_PATH - 9)
00728     {
00729         return FALSE;
00730     }
00731     if (szPath[length-1] != L'\\')
00732     {
00733         szPath[length] = L'\\';
00734         length++;
00735     }
00736     wcscpy(&szPath[length], L"media\\*");
00737     length += 7;
00738 
00739     hFile = FindFirstFileW(szPath, &FileData);
00740     if (hFile == INVALID_HANDLE_VALUE)
00741     {
00742         return FALSE;
00743     }
00744 
00745     do
00746     {
00747         if (FileData.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY)
00748             continue;
00749 
00750         ptr = wcsrchr(FileData.cFileName, L'\\');
00751         if (ptr)
00752         {
00753             ptr++;
00754         }
00755         else
00756         {
00757             ptr = FileData.cFileName;
00758         }
00759         lResult = SendDlgItemMessageW(hwndDlg, IDC_SOUND_LIST, CB_ADDSTRING, (WPARAM)0, (LPARAM)ptr);
00760         if (lResult != CB_ERR)
00761         {
00762             wcscpy(&szPath[length-1], FileData.cFileName);
00763             SendDlgItemMessageW(hwndDlg, IDC_SOUND_LIST, CB_SETITEMDATA, (WPARAM)lResult, (LPARAM)_wcsdup(szPath));
00764         }
00765     } while (FindNextFileW(hFile, &FileData) != 0);
00766 
00767     FindClose(hFile);
00768     return TRUE;
00769 }
00770 
00771 
00772 BOOL
00773 ShowSoundScheme(HWND hwndDlg)
00774 {
00775     LRESULT lIndex;
00776     PSOUND_SCHEME_CONTEXT pScheme;
00777     PAPP_MAP pAppMap;
00778     LV_ITEM listItem;
00779     LV_COLUMN dummy;
00780     HWND hDlgCtrl, hList;
00781     RECT rect;
00782     int ItemIndex;
00783     hDlgCtrl = GetDlgItem(hwndDlg, IDC_SOUND_SCHEME);
00784     hList = GetDlgItem(hwndDlg, IDC_SCHEME_LIST);
00785 
00786     lIndex = SendMessage(hDlgCtrl, CB_GETCURSEL, (WPARAM)0, (LPARAM)0);
00787     if (lIndex == CB_ERR)
00788     {
00789         return FALSE;
00790     }
00791 
00792     lIndex = SendMessage(hDlgCtrl, CB_GETITEMDATA, (WPARAM)lIndex, (LPARAM)0);
00793     if (lIndex == CB_ERR)
00794     {
00795         return FALSE;
00796     }
00797     pScheme = (PSOUND_SCHEME_CONTEXT)lIndex;
00798 
00799     _tcscpy(szDefault, pScheme->szName);
00800 
00801     /*  add column for app */
00802     GetClientRect(hList, &rect);
00803     ZeroMemory(&dummy, sizeof(LV_COLUMN));
00804     dummy.mask      = LVCF_WIDTH;
00805     dummy.iSubItem  = 0;
00806     dummy.cx        = rect.right - rect.left - GetSystemMetrics(SM_CXVSCROLL);
00807     (void)ListView_InsertColumn(hList, 0, &dummy);
00808     ItemIndex = 0;
00809 
00810     pAppMap = s_App;
00811     while (pAppMap)
00812     {
00813         PLABEL_MAP pLabelMap = pAppMap->LabelMap;
00814         while (pLabelMap)
00815         {
00816             ZeroMemory(&listItem, sizeof(LV_ITEM));
00817             listItem.mask       = LVIF_TEXT | LVIF_PARAM | LVIF_IMAGE;
00818             listItem.pszText    = pLabelMap->szDesc;
00819             listItem.lParam     = (LPARAM)FindLabelContext(pScheme, pAppMap->szName, pLabelMap->szName);
00820             listItem.iItem      = ItemIndex;
00821             listItem.iImage     = -1;
00822             (void)ListView_InsertItem(hList, &listItem);
00823             ItemIndex++;
00824 
00825             pLabelMap = pLabelMap->Next;
00826         }
00827         pAppMap = pAppMap->Next;
00828     }
00829     return TRUE;
00830 }
00831 
00832 
00833 BOOL
00834 ApplyChanges(HWND hwndDlg)
00835 {
00836     HKEY hKey, hSubKey;
00837     LRESULT lIndex;
00838     PSOUND_SCHEME_CONTEXT pScheme;
00839     HWND hDlgCtrl;
00840     PLABEL_CONTEXT pLabelContext;
00841     TCHAR Buffer[100];
00842 
00843     hDlgCtrl = GetDlgItem(hwndDlg, IDC_SOUND_SCHEME);
00844 
00845     lIndex = SendMessage(hDlgCtrl, CB_GETCURSEL, (WPARAM)0, (LPARAM)0);
00846     if (lIndex == CB_ERR)
00847     {
00848         return FALSE;
00849     }
00850 
00851     lIndex = SendMessage(hDlgCtrl, CB_GETITEMDATA, (WPARAM)lIndex, (LPARAM)0);
00852     if (lIndex == CB_ERR)
00853     {
00854         return FALSE;
00855     }
00856     pScheme = (PSOUND_SCHEME_CONTEXT)lIndex;
00857 
00858     if (RegOpenKeyEx(HKEY_CURRENT_USER,
00859                      _T("AppEvents\\Schemes"),
00860                      0,
00861                      KEY_WRITE,
00862                      &hKey) != ERROR_SUCCESS)
00863     {
00864         return FALSE;
00865     }
00866 
00867     RegSetValueEx(hKey, NULL, 0, REG_SZ, (LPBYTE)pScheme->szName, (_tcslen(pScheme->szName) +1) * sizeof(TCHAR));
00868     RegCloseKey(hKey);
00869 
00870     if (RegOpenKeyEx(HKEY_CURRENT_USER,
00871                      _T("AppEvents\\Schemes\\Apps"),
00872                      0,
00873                      KEY_WRITE,
00874                      &hKey) != ERROR_SUCCESS)
00875     {
00876         return FALSE;
00877     }
00878 
00879     pLabelContext = pScheme->LabelContext;
00880 
00881     while (pLabelContext)
00882     {
00883         _stprintf(Buffer, _T("%s\\%s\\.Current"), pLabelContext->AppMap->szName, pLabelContext->LabelMap->szName);
00884 
00885         if (RegOpenKeyEx(hKey, Buffer, 0, KEY_WRITE, &hSubKey) == ERROR_SUCCESS)
00886         {
00887             RegSetValueEx(hSubKey, NULL, 0, REG_EXPAND_SZ, (LPBYTE)pLabelContext->szValue, (_tcslen(pLabelContext->szValue) +1) * sizeof(TCHAR));
00888             RegCloseKey(hSubKey);
00889         }
00890 
00891         pLabelContext = pLabelContext->Next;
00892     }
00893     RegCloseKey(hKey);
00894 
00895     SetWindowLong(hwndDlg, DWL_MSGRESULT, (LONG)PSNRET_NOERROR);
00896     return TRUE;
00897 }
00898 
00899 
00900 /* Sounds property page dialog callback */
00901 INT_PTR
00902 CALLBACK
00903 SoundsDlgProc(HWND hwndDlg,
00904               UINT uMsg,
00905               WPARAM wParam,
00906               LPARAM lParam)
00907 {
00908     switch (uMsg)
00909     {
00910         case WM_INITDIALOG:
00911         {
00912             UINT NumWavOut = waveOutGetNumDevs();
00913 
00914             SendMessage(GetDlgItem(hwndDlg, IDC_PLAY_SOUND),
00915                         BM_SETIMAGE,(WPARAM)IMAGE_ICON,
00916                         (LPARAM)(HANDLE)LoadIcon(hApplet, MAKEINTRESOURCE(IDI_PLAY_ICON)));
00917 
00918             LoadEventLabels();
00919             LoadSoundProfiles(hwndDlg);
00920             LoadSoundFiles(hwndDlg);
00921             ShowSoundScheme(hwndDlg);
00922 
00923             if (!NumWavOut)
00924             {
00925                 EnableWindow(GetDlgItem(hwndDlg, IDC_SOUND_SCHEME), FALSE);
00926                 EnableWindow(GetDlgItem(hwndDlg, IDC_SAVEAS_BTN),   FALSE);
00927                 EnableWindow(GetDlgItem(hwndDlg, IDC_DELETE_BTN),   FALSE);
00928                 EnableWindow(GetDlgItem(hwndDlg, IDC_SCHEME_LIST),  FALSE);
00929             }
00930 
00931             if (wParam == (WPARAM)GetDlgItem(hwndDlg, IDC_SOUND_SCHEME))
00932                 return TRUE;
00933             SetFocus(GetDlgItem(hwndDlg, IDC_SOUND_SCHEME));
00934             return FALSE;
00935         }
00936         case WM_COMMAND:
00937         {
00938             switch (LOWORD(wParam))
00939             {
00940                 case IDC_PLAY_SOUND:
00941                 {
00942                     LRESULT lIndex;
00943                     lIndex = SendDlgItemMessage(hwndDlg, IDC_SOUND_LIST, CB_GETCURSEL, (WPARAM)0, (LPARAM)0);
00944                     if (lIndex == CB_ERR)
00945                     {
00946                         break;
00947                     }
00948 
00949                     lIndex = SendDlgItemMessage(hwndDlg, IDC_SOUND_LIST, CB_GETITEMDATA, (WPARAM)lIndex, (LPARAM)0);
00950                     if (lIndex != CB_ERR)
00951                     {
00952                         PlaySound((TCHAR*)lIndex, NULL, SND_FILENAME);
00953                     }
00954                     break;
00955                 }
00956                 case IDC_SOUND_SCHEME:
00957                 {
00958                     if (HIWORD(wParam) == CBN_SELENDOK)
00959                     {
00960                         (void)ListView_DeleteAllItems(GetDlgItem(hwndDlg, IDC_SCHEME_LIST));
00961                         ShowSoundScheme(hwndDlg);
00962                         EnableWindow(GetDlgItem(hwndDlg, IDC_SOUND_LIST), FALSE);
00963                         EnableWindow(GetDlgItem(hwndDlg, IDC_TEXT_SOUND), FALSE);
00964                         EnableWindow(GetDlgItem(hwndDlg, IDC_PLAY_SOUND), FALSE);
00965                         EnableWindow(GetDlgItem(hwndDlg, IDC_BROWSE_SOUND), FALSE);
00966                         PropSheet_Changed(GetParent(hwndDlg), hwndDlg);
00967                     }
00968                     break;
00969                 }
00970                 case IDC_SOUND_LIST:
00971                 {
00972                     if (HIWORD(wParam) == CBN_SELENDOK)
00973                     {
00974                         PLABEL_CONTEXT pLabelContext;
00975                         INT SelCount;
00976                         LVITEM item;
00977                         LRESULT lIndex;
00978                         SelCount = ListView_GetSelectionMark(GetDlgItem(hwndDlg, IDC_SCHEME_LIST));
00979                         if (SelCount == -1)
00980                         {
00981                             break;
00982                         }
00983                         lIndex = SendDlgItemMessage(hwndDlg, IDC_SOUND_LIST, CB_GETCURSEL, (WPARAM)0, (LPARAM)0);
00984                         if (lIndex == CB_ERR)
00985                         {
00986                             break;
00987                         }
00988                         ZeroMemory(&item, sizeof(LVITEM));
00989                         item.mask = LVIF_PARAM;
00990                         item.iItem = SelCount;
00991                         if (ListView_GetItem(GetDlgItem(hwndDlg, IDC_SCHEME_LIST), &item))
00992                         {
00993                             LRESULT lResult;
00994                             pLabelContext = (PLABEL_CONTEXT)item.lParam;
00995 
00996                             lResult = SendDlgItemMessage(hwndDlg, IDC_SOUND_LIST, CB_GETITEMDATA, (WPARAM)lIndex, (LPARAM)0);
00997                             if (lResult == CB_ERR || lResult == 0)
00998                             {
00999                                 if (lIndex != pLabelContext->szValue[0])
01000                                     PropSheet_Changed(GetParent(hwndDlg), hwndDlg);
01001 
01002                                 pLabelContext->szValue[0] = L'\0';
01003                                 break;
01004                             }
01005 
01006                             if (_tcsicmp(pLabelContext->szValue, (TCHAR*)lResult) || (lIndex != pLabelContext->szValue[0]))
01007                             {
01008                                 PropSheet_Changed(GetParent(hwndDlg), hwndDlg);
01012                                _tcscpy(pLabelContext->szValue, (TCHAR*)lResult);
01013                             }
01014                             if (_tcslen((TCHAR*)lResult) && lIndex != 0)
01015                             {
01016                                 EnableWindow(GetDlgItem(hwndDlg, IDC_PLAY_SOUND), TRUE);
01017                             }
01018                             else
01019                             {
01020                                 EnableWindow(GetDlgItem(hwndDlg, IDC_PLAY_SOUND), FALSE);
01021                             }
01022                         }
01023                     }
01024                     break;
01025                 }
01026             }
01027             break;
01028         }
01029         case WM_NOTIFY:
01030         {
01031             LVITEM item;
01032             PLABEL_CONTEXT pLabelContext;
01033             TCHAR * ptr;
01034 
01035             LPNMHDR lpnm = (LPNMHDR)lParam;
01036 
01037             switch(lpnm->code)
01038             {
01039                 case PSN_APPLY:
01040                 {
01041                     ApplyChanges(hwndDlg);
01042                     break;
01043                 }
01044                 case LVN_ITEMCHANGED:
01045                 {
01046                     LPNMLISTVIEW nm = (LPNMLISTVIEW)lParam;
01047 
01048                     if ((nm->uNewState & LVIS_SELECTED) == 0)
01049                     {
01050                         return FALSE;
01051                     }
01052                     ZeroMemory(&item, sizeof(LVITEM));
01053                     item.mask = LVIF_PARAM;
01054                     item.iItem = nm->iItem;
01055 
01056                     if (ListView_GetItem(GetDlgItem(hwndDlg, IDC_SCHEME_LIST), &item))
01057                     {
01058                         LRESULT lCount, lIndex, lResult;
01059                         pLabelContext = (PLABEL_CONTEXT)item.lParam;
01060                         if (!pLabelContext)
01061                         {
01062                             return FALSE;
01063                         }
01064                         EnableWindow(GetDlgItem(hwndDlg, IDC_SOUND_LIST), TRUE);
01065                         EnableWindow(GetDlgItem(hwndDlg, IDC_TEXT_SOUND), TRUE);
01066                         EnableWindow(GetDlgItem(hwndDlg, IDC_BROWSE_SOUND), TRUE);
01067                         if (_tcslen(pLabelContext->szValue) == 0)
01068                         {
01069                             lIndex = SendDlgItemMessage(hwndDlg, IDC_SOUND_LIST, CB_SETCURSEL, (WPARAM)0, (LPARAM)0);
01070                             EnableWindow(GetDlgItem(hwndDlg, IDC_PLAY_SOUND), FALSE);
01071                             break;
01072 
01073                         }
01074                         EnableWindow(GetDlgItem(hwndDlg, IDC_PLAY_SOUND), TRUE);
01075                         lCount = SendDlgItemMessage(hwndDlg, IDC_SOUND_LIST, CB_GETCOUNT, (WPARAM)0, (LPARAM)0);
01076                         for (lIndex = 0; lIndex < lCount; lIndex++)
01077                         {
01078                             lResult = SendDlgItemMessage(hwndDlg, IDC_SOUND_LIST, CB_GETITEMDATA, (WPARAM)lIndex, (LPARAM)0);
01079                             if (lResult == CB_ERR || lResult == 0)
01080                                 continue;
01081 
01082                             if (!_tcscmp((TCHAR*)lResult, pLabelContext->szValue))
01083                             {
01084                                 SendDlgItemMessage(hwndDlg, IDC_SOUND_LIST, CB_SETCURSEL, (WPARAM)lIndex, (LPARAM)0);
01085                                 return FALSE;
01086                             }
01087                         }
01088                         ptr = _tcsrchr(pLabelContext->szValue, _T('\\'));
01089                         if (ptr)
01090                         {
01091                             ptr++;
01092                         }
01093                         else
01094                         {
01095                             ptr = pLabelContext->szValue;
01096                         }
01097                         lIndex = SendDlgItemMessage(hwndDlg, IDC_SOUND_LIST, CB_ADDSTRING, (WPARAM)0, (LPARAM)ptr);
01098                         if (lIndex != CB_ERR)
01099                         {
01100                             SendDlgItemMessage(hwndDlg, IDC_SOUND_LIST, CB_SETITEMDATA, (WPARAM)lIndex, (LPARAM)_tcsdup(pLabelContext->szValue));
01101                             SendDlgItemMessage(hwndDlg, IDC_SOUND_LIST, CB_SETCURSEL, (WPARAM)lIndex, (LPARAM)0);
01102                         }
01103                     }
01104                     break;
01105                 }
01106             }
01107         }
01108         break;
01109     }
01110 
01111     return FALSE;
01112 }

Generated on Sat May 26 2012 04:19:45 for ReactOS by doxygen 1.7.6.1

ReactOS is a registered trademark or a trademark of ReactOS Foundation in the United States and other countries.