1 /* 2 * 3 * PROJECT: ReactOS Multimedia Control Panel 4 * FILE: lib/cpl/mmsys/mmsys.c 5 * PURPOSE: ReactOS Multimedia Control Panel 6 * PROGRAMMER: Thomas Weidenmueller <w3seek@reactos.com> 7 * Johannes Anderwald <janderwald@reactos.com> 8 * Dmitry Chapyshev <dmitry@reactos.org> 9 */ 10 11 #include <windows.h> 12 #include <commctrl.h> 13 #include <cpl.h> 14 #include <tchar.h> 15 #include <stdio.h> 16 #include "mmsys.h" 17 #include "resource.h" 18 19 20 VOID 21 InitAudioDlg(HWND hwnd) 22 { 23 WAVEOUTCAPSW waveOutputPaps; 24 WAVEINCAPS waveInputPaps; 25 MIDIOUTCAPS midiOutCaps; 26 TCHAR szNoDevices[256]; 27 UINT DevsNum; 28 UINT uIndex; 29 HWND hCB; 30 LRESULT Res; 31 32 LoadString(hApplet, IDS_NO_DEVICES, szNoDevices, sizeof(szNoDevices) / sizeof(TCHAR)); 33 34 // Init sound playback devices list 35 hCB = GetDlgItem(hwnd, IDC_DEVICE_PLAY_LIST); 36 37 DevsNum = waveOutGetNumDevs(); 38 if (DevsNum < 1) 39 { 40 Res = SendMessage(hCB, CB_ADDSTRING, 0, (LPARAM)szNoDevices); 41 SendMessage(hCB, CB_SETCURSEL, (WPARAM) Res, 0); 42 } 43 else 44 { 45 WCHAR DefaultDevice[MAX_PATH] = {0}; 46 HKEY hKey; 47 DWORD dwSize = sizeof(DefaultDevice); 48 UINT DefaultIndex = 0; 49 50 if (RegOpenKeyExW(HKEY_CURRENT_USER, L"Software\\Microsoft\\Multimedia\\Sound Mapper", 0, KEY_READ, &hKey) == ERROR_SUCCESS) 51 { 52 RegQueryValueExW(hKey, L"Playback", NULL, NULL, (LPBYTE)DefaultDevice, &dwSize); 53 DefaultDevice[MAX_PATH-1] = L'\0'; 54 RegCloseKey(hKey); 55 } 56 57 for (uIndex = 0; uIndex < DevsNum; uIndex++) 58 { 59 if (waveOutGetDevCapsW(uIndex, &waveOutputPaps, sizeof(waveOutputPaps))) 60 continue; 61 62 Res = SendMessageW(hCB, CB_ADDSTRING, 0, (LPARAM) waveOutputPaps.szPname); 63 64 if (CB_ERR != Res) 65 { 66 SendMessage(hCB, CB_SETITEMDATA, Res, (LPARAM) uIndex); 67 if (!wcsicmp(waveOutputPaps.szPname, DefaultDevice)) 68 DefaultIndex = Res; 69 } 70 } 71 SendMessage(hCB, CB_SETCURSEL, (WPARAM) DefaultIndex, 0); 72 } 73 74 // Init sound recording devices list 75 hCB = GetDlgItem(hwnd, IDC_DEVICE_REC_LIST); 76 77 DevsNum = waveInGetNumDevs(); 78 if (DevsNum < 1) 79 { 80 Res = SendMessage(hCB, CB_ADDSTRING, 0, (LPARAM)szNoDevices); 81 SendMessage(hCB, CB_SETCURSEL, (WPARAM) Res, 0); 82 } 83 else 84 { 85 WCHAR DefaultDevice[MAX_PATH] = {0}; 86 HKEY hKey; 87 DWORD dwSize = sizeof(DefaultDevice); 88 UINT DefaultIndex = 0; 89 90 if (RegOpenKeyExW(HKEY_CURRENT_USER, L"Software\\Microsoft\\Multimedia\\Sound Mapper", 0, KEY_READ, &hKey) == ERROR_SUCCESS) 91 { 92 RegQueryValueExW(hKey, L"Record", NULL, NULL, (LPBYTE)DefaultDevice, &dwSize); 93 DefaultDevice[MAX_PATH-1] = L'\0'; 94 RegCloseKey(hKey); 95 } 96 97 98 for (uIndex = 0; uIndex < DevsNum; uIndex++) 99 { 100 if (waveInGetDevCaps(uIndex, &waveInputPaps, sizeof(waveInputPaps))) 101 continue; 102 103 Res = SendMessage(hCB, CB_ADDSTRING, 0, (LPARAM) waveInputPaps.szPname); 104 105 if (CB_ERR != Res) 106 { 107 SendMessage(hCB, CB_SETITEMDATA, Res, (LPARAM) uIndex); 108 if (!wcsicmp(waveInputPaps.szPname, DefaultDevice)) 109 DefaultIndex = Res; 110 } 111 } 112 SendMessage(hCB, CB_SETCURSEL, (WPARAM) DefaultIndex, 0); 113 } 114 115 // Init MIDI devices list 116 hCB = GetDlgItem(hwnd, IDC_DEVICE_MIDI_LIST); 117 118 DevsNum = midiOutGetNumDevs(); 119 if (DevsNum < 1) 120 { 121 Res = SendMessage(hCB, CB_ADDSTRING, 0, (LPARAM)szNoDevices); 122 SendMessage(hCB, CB_SETCURSEL, (WPARAM) Res, 0); 123 } 124 else 125 { 126 for (uIndex = 0; uIndex < DevsNum; uIndex++) 127 { 128 if (midiOutGetDevCaps(uIndex, &midiOutCaps, sizeof(midiOutCaps))) 129 continue; 130 131 Res = SendMessage(hCB, CB_ADDSTRING, 0, (LPARAM) midiOutCaps.szPname); 132 133 if (CB_ERR != Res) 134 { 135 SendMessage(hCB, CB_SETITEMDATA, Res, (LPARAM) uIndex); 136 // TODO: Getting default device 137 SendMessage(hCB, CB_SETCURSEL, (WPARAM) Res, 0); 138 } 139 } 140 } 141 } 142 143 static UINT 144 GetDevNum(HWND hControl, DWORD Id) 145 { 146 int iCurSel; 147 UINT DevNum; 148 149 iCurSel = SendMessage(hControl, CB_GETCURSEL, 0, 0); 150 151 if (iCurSel == CB_ERR) 152 return 0; 153 154 DevNum = (UINT) SendMessage(hControl, CB_GETITEMDATA, iCurSel, 0); 155 if (DevNum == (UINT) CB_ERR) 156 return 0; 157 158 if (mixerGetID((HMIXEROBJ)IntToPtr(DevNum), &DevNum, Id) != MMSYSERR_NOERROR) 159 return 0; 160 161 return DevNum; 162 } 163 164 /* Audio property page dialog callback */ 165 INT_PTR CALLBACK 166 AudioDlgProc(HWND hwndDlg, 167 UINT uMsg, 168 WPARAM wParam, 169 LPARAM lParam) 170 { 171 UNREFERENCED_PARAMETER(lParam); 172 UNREFERENCED_PARAMETER(wParam); 173 UNREFERENCED_PARAMETER(hwndDlg); 174 175 switch(uMsg) 176 { 177 case WM_INITDIALOG: 178 { 179 UINT NumWavOut = waveOutGetNumDevs(); 180 181 InitAudioDlg(hwndDlg); 182 183 if (!NumWavOut) 184 { 185 EnableWindow(GetDlgItem(hwndDlg, IDC_DEVICE_PLAY_LIST), FALSE); 186 EnableWindow(GetDlgItem(hwndDlg, IDC_DEVICE_REC_LIST), FALSE); 187 EnableWindow(GetDlgItem(hwndDlg, IDC_DEVICE_MIDI_LIST), FALSE); 188 EnableWindow(GetDlgItem(hwndDlg, IDC_DEFAULT_DEV_CHECKBOX), FALSE); 189 EnableWindow(GetDlgItem(hwndDlg, IDC_VOLUME1_BTN), FALSE); 190 EnableWindow(GetDlgItem(hwndDlg, IDC_ADV2_BTN), FALSE); 191 EnableWindow(GetDlgItem(hwndDlg, IDC_VOLUME2_BTN), FALSE); 192 EnableWindow(GetDlgItem(hwndDlg, IDC_ADV1_BTN), FALSE); 193 EnableWindow(GetDlgItem(hwndDlg, IDC_VOLUME3_BTN), FALSE); 194 EnableWindow(GetDlgItem(hwndDlg, IDC_ADV3_BTN), FALSE); 195 } 196 } 197 break; 198 199 case WM_COMMAND: 200 { 201 STARTUPINFO si; 202 PROCESS_INFORMATION pi; 203 WCHAR szPath[MAX_PATH]; 204 205 switch(LOWORD(wParam)) 206 { 207 case IDC_VOLUME1_BTN: 208 { 209 wsprintf(szPath, L"sndvol32.exe -d %d", 210 GetDevNum(GetDlgItem(hwndDlg, IDC_DEVICE_PLAY_LIST), MIXER_OBJECTF_WAVEOUT)); 211 212 ZeroMemory(&si, sizeof(si)); 213 si.cb = sizeof(si); 214 si.wShowWindow = SW_SHOW; 215 216 CreateProcess(NULL, szPath, NULL, NULL, FALSE, 0, NULL, NULL, &si, &pi); 217 } 218 break; 219 220 case IDC_ADV2_BTN: 221 { 222 223 } 224 break; 225 226 case IDC_VOLUME2_BTN: 227 { 228 wsprintf(szPath, L"sndvol32.exe -r -d %d", 229 GetDevNum(GetDlgItem(hwndDlg, IDC_DEVICE_REC_LIST), MIXER_OBJECTF_WAVEIN)); 230 231 ZeroMemory(&si, sizeof(si)); 232 si.cb = sizeof(si); 233 si.wShowWindow = SW_SHOW; 234 235 CreateProcess(NULL, szPath, NULL, NULL, FALSE, 0, NULL, NULL, &si, &pi); 236 } 237 break; 238 239 case IDC_ADV1_BTN: 240 { 241 242 } 243 break; 244 245 case IDC_VOLUME3_BTN: 246 { 247 wsprintf(szPath, L"sndvol32.exe -d %d", 248 GetDevNum(GetDlgItem(hwndDlg, IDC_DEVICE_MIDI_LIST), MIXER_OBJECTF_MIDIOUT)); 249 250 ZeroMemory(&si, sizeof(si)); 251 si.cb = sizeof(si); 252 si.wShowWindow = SW_SHOW; 253 254 CreateProcess(NULL, szPath, NULL, NULL, FALSE, 0, NULL, NULL, &si, &pi); 255 } 256 break; 257 258 case IDC_ADV3_BTN: 259 { 260 261 } 262 break; 263 } 264 } 265 break; 266 } 267 268 return FALSE; 269 } 270