Leaked source code of windows server 2003
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

402 lines
11 KiB

  1. /************************************************************************/
  2. /*
  3. ** Copyright (c) 1985-1998 Microsoft Corporation
  4. **
  5. ** Title: config.c - Multimedia Systems Media Control Interface
  6. ** waveform audio driver for RIFF wave files.
  7. **
  8. ** Version: 1.00
  9. **
  10. ** Date: 18-Apr-1990
  11. **
  12. ** Author: ROBWI
  13. */
  14. /************************************************************************/
  15. /*
  16. ** Change log:
  17. **
  18. ** DATE REV DESCRIPTION
  19. ** ----------- ----- ------------------------------------------
  20. ** 10-Jan-1992 MikeTri Ported to NT
  21. ** @@@ need to change slash slash comments to slash star
  22. */
  23. /************************************************************************/
  24. #define UNICODE
  25. #define NOGDICAPMASKS
  26. #define NOVIRTUALKEYCODES
  27. #define NOWINSTYLES
  28. #define NOSYSMETRICS
  29. #define NOMENUS
  30. #define NOICONS
  31. #define NOKEYSTATES
  32. #define NOSYSCOMMANDS
  33. #define NORASTEROPS
  34. #define NOSHOWWINDOW
  35. #define OEMRESOURCE
  36. #define NOATOM
  37. #define NOCLIPBOARD
  38. #define NOCOLOR
  39. #define NODRAWTEXT
  40. #define NOGDI
  41. #define NOKERNEL
  42. #define NONLS
  43. #define NOMB
  44. #define NOMEMMGR
  45. #define NOMETAFILE
  46. #define NOOPENFILE
  47. #define NOTEXTMETRIC
  48. #define NOWH
  49. #define NOWINOFFSETS
  50. #define NOCOMM
  51. #define NOKANJI
  52. #define NOPROFILER
  53. #define NODEFERWINDOWPOS
  54. #define NOMMDRV
  55. #define MMNOMMIO
  56. #define MMNOJOY
  57. #define MMNOTIMER
  58. #define MMNOAUX
  59. #define MMNOMIDI
  60. #define MMNOWAVE
  61. #include <windows.h>
  62. #include "mciwave.h"
  63. #include <mmddk.h>
  64. #include "config.h"
  65. #include <mcihlpid.h>
  66. /************************************************************************/
  67. #define MAXINIDRIVER 132
  68. PRIVATE SZCODE aszNULL[] = L"";
  69. PRIVATE SZCODE aszSystemIni[] = L"system.ini";
  70. PRIVATE WCHAR aszWordFormat[] = L"%u";
  71. PRIVATE WCHAR aszTailWordFormat[] = L" %u";
  72. const static DWORD aHelpIds[] = { // Context Help IDs
  73. IDSCROLL, IDH_MCI_WAVEFORM_DRIVER,
  74. (DWORD)-1, IDH_MCI_WAVEFORM_DRIVER,
  75. IDCOUNT, IDH_MCI_WAVEFORM_DRIVER,
  76. 0, 0
  77. };
  78. const static TCHAR cszHelpFile[] = TEXT("MMDRV.HLP");
  79. /************************************************************************/
  80. /*
  81. @doc INTERNAL MCIWAVE
  82. @func SSZ | GetTail |
  83. This function returns a pointer into the given string at the
  84. first non-blank character after the current word. If it fails to find
  85. a second word, a pointer to the terminating NULL character is returned.
  86. @parm SSZ | ssz |
  87. Points to the string whose tail is to be returned.
  88. @rdesc Returns a pointer into the string passed.
  89. */
  90. PRIVATE SSZ PASCAL NEAR GetTail(
  91. SSZ ssz)
  92. {
  93. while (*ssz && *ssz != ' ')
  94. ssz++;
  95. while (*ssz == ' ')
  96. ssz++ ;
  97. return ssz;
  98. }
  99. /************************************************************************/
  100. /*
  101. @doc INTERNAL MCIWAVE
  102. @func UINT | GetCmdParm |
  103. This function retrieves the current audio buffers parameter using
  104. the INI strings contained in the configuration block. The audio
  105. buffers parameter is a number included in the INI entry for this
  106. driver as a parameter.
  107. @parm <t>LPDRVCONFIGINFO<d> | lpdci |
  108. Points to the driver configuration information passed to the
  109. dialog creation function.
  110. @rdesc Returns the current audio buffers.
  111. */
  112. STATICFN UINT PASCAL NEAR GetCmdParm(
  113. LPDRVCONFIGINFO lpdci)
  114. {
  115. WCHAR aszDriver[MAXINIDRIVER];
  116. SSZ pszTail;
  117. // Assume things will go wrong... initialise variables
  118. pszTail = aszDriver;
  119. if (GetPrivateProfileString( lpdci->lpszDCISectionName,
  120. lpdci->lpszDCIAliasName,
  121. aszNULL,
  122. aszDriver,
  123. sizeof(aszDriver) / sizeof(WCHAR),
  124. aszSystemIni))
  125. {
  126. // We have got the name of the driver
  127. // Just in case the user has added the command parameter to the
  128. // end of the name we had better make sure there is only one token
  129. // on the line.
  130. WCHAR parameters[6];
  131. LPWSTR pszDefault;
  132. pszTail = GetTail((SSZ)aszDriver);
  133. pszDefault = pszTail; // Either the number on the end, or NULL
  134. if (*pszTail) {
  135. // RATS!! Not a simple name
  136. while (*--pszTail == L' ') {
  137. }
  138. *++pszTail = L'\0'; // Terminate the string after the DLL name
  139. }
  140. if (GetProfileString(aszDriver, lpdci->lpszDCIAliasName, pszDefault, parameters, sizeof(parameters)/sizeof(WCHAR))) {
  141. pszTail = parameters;
  142. }
  143. } else {
  144. aszDriver[0] = L'\0';
  145. }
  146. return(GetAudioSeconds(pszTail));
  147. }
  148. /************************************************************************/
  149. /*
  150. @doc INTERNAL MCIWAVE
  151. @func UINT | PutCmdParm |
  152. This function saves the current audio buffers parameter using
  153. the INI strings contained in the configuration block.
  154. @parm <t>LPDRVCONFIGINFO<d> | lpdci |
  155. Points to the driver configuration information passed to the
  156. dialog creation function.
  157. @parm UINT | wSeconds |
  158. Contains the audio buffer seconds parameter to save.
  159. @rdesc Nothing.
  160. */
  161. PRIVATE VOID PASCAL NEAR PutCmdParm(
  162. LPDRVCONFIGINFO lpdci,
  163. UINT wSeconds)
  164. {
  165. WCHAR aszDriver[MAXINIDRIVER];
  166. SSZ sszDriverTail;
  167. if (GetPrivateProfileString( lpdci->lpszDCISectionName,
  168. lpdci->lpszDCIAliasName,
  169. aszNULL,
  170. aszDriver,
  171. (sizeof(aszDriver) / sizeof(WCHAR)) - 6,
  172. aszSystemIni)) {
  173. WCHAR parameters[10];
  174. // There might be a command parameter on the end of the DLL name.
  175. // Ensure we only have the first token
  176. sszDriverTail = GetTail((SSZ)aszDriver);
  177. if (*sszDriverTail) {
  178. // RATS!! Not a simple name
  179. while (*--sszDriverTail == L' ') {
  180. }
  181. *++sszDriverTail = L'\0'; // Terminate the string after the DLL name
  182. }
  183. wsprintfW(parameters, aszWordFormat, wSeconds);
  184. WriteProfileString(aszDriver, lpdci->lpszDCIAliasName, parameters);
  185. }
  186. }
  187. /************************************************************************/
  188. /*
  189. @doc INTERNAL MCIWAVE
  190. @func BOOL | ConfigDlgProc |
  191. This function is the message handle for the driver configuration
  192. window.
  193. @parm HWND | hwndDlg |
  194. Window handle to the dialog.
  195. @parm UINT | wMsg |
  196. Current message being sent.
  197. @flag WM_INITDIALOG |
  198. During dialog initialization, the pointer to the configuration
  199. parameter block is saved to a static pointer. Note that there should
  200. only be a single instance of this dialog box at any one time. The
  201. current audio dialog buffer seconds is set from the INI file entry.
  202. @flag WM_HSCROLL |
  203. This responds to the scroll bar by changing the currently displayed
  204. value of audio seconds and updating the scroll bar thumb. To look
  205. nice, the count and scroll bar are only updated if the value actually
  206. changes. Note that the error return for GetDlgItemInt is not checked
  207. because it is initially set to an integer value, so it is always
  208. valid.
  209. @flag WM_CLOSE |
  210. If the close box is used, cancel the dialog, returning DRVCNF_CANCEL.
  211. @flag WM_COMMAND |
  212. If the message is being sent on behalf of the OK button, the current
  213. audio seconds value is saved, and the dialog is terminated, returning
  214. the DRVCNF_OK value to the driver entry. Note that the error return for
  215. GetDlgItemInt is not checked because it is initially set to an integer
  216. value, so it is always valid. If the message is being sent on behalf
  217. of the Cancel button, the dialog is terminated returning the
  218. DRVCNF_CANCEL value.
  219. @parm WPARAM | wParam |
  220. Message parameter.
  221. @parm LPARAM | lParam |
  222. Message parameter.
  223. @rdesc Depends on the message sent.
  224. */
  225. PUBLIC INT_PTR PASCAL ConfigDlgProc(
  226. HWND hwndDlg,
  227. UINT wMsg,
  228. WPARAM wParam,
  229. LPARAM lParam)
  230. {
  231. UINT wSeconds;
  232. UINT wNewSeconds;
  233. BOOL fTranslated;
  234. HWND hwndItem;
  235. static LPDRVCONFIGINFO lpdci;
  236. switch (wMsg) {
  237. case WM_INITDIALOG:
  238. lpdci = (LPDRVCONFIGINFO)lParam;
  239. wSeconds = GetCmdParm(lpdci);
  240. hwndItem = GetDlgItem(hwndDlg, IDSCROLL);
  241. SetScrollRange(hwndItem, SB_CTL, MinAudioSeconds, MaxAudioSeconds, FALSE);
  242. SetScrollPos(hwndItem, SB_CTL, wSeconds, FALSE);
  243. SetDlgItemInt(hwndDlg, IDCOUNT, wSeconds, FALSE);
  244. break;
  245. case WM_HSCROLL:
  246. wSeconds = GetDlgItemInt(hwndDlg, IDCOUNT, &fTranslated, FALSE);
  247. hwndItem = (HWND)lParam;
  248. switch (LOWORD(wParam)) {
  249. case SB_PAGEDOWN:
  250. case SB_LINEDOWN:
  251. wNewSeconds = min(MaxAudioSeconds, wSeconds + 1);
  252. break;
  253. case SB_PAGEUP:
  254. case SB_LINEUP:
  255. wNewSeconds = max(MinAudioSeconds, wSeconds - 1);
  256. break;
  257. case SB_TOP:
  258. wNewSeconds = MinAudioSeconds;
  259. break;
  260. case SB_BOTTOM:
  261. wNewSeconds = MaxAudioSeconds;
  262. break;
  263. case SB_THUMBPOSITION:
  264. case SB_THUMBTRACK:
  265. wNewSeconds = HIWORD(wParam);
  266. break;
  267. default:
  268. return FALSE;
  269. }
  270. if (wNewSeconds != wSeconds) {
  271. SetScrollPos(hwndItem, SB_CTL, wNewSeconds, TRUE);
  272. SetDlgItemInt(hwndDlg, IDCOUNT, wNewSeconds, FALSE);
  273. }
  274. break;
  275. case WM_CLOSE:
  276. EndDialog(hwndDlg, DRVCNF_CANCEL);
  277. break;
  278. case WM_CONTEXTMENU:
  279. WinHelp ((HWND)wParam, cszHelpFile, HELP_CONTEXTMENU, (ULONG_PTR)aHelpIds);
  280. return TRUE;
  281. case WM_HELP:
  282. {
  283. LPHELPINFO lphi = (LPVOID) lParam;
  284. WinHelp (lphi->hItemHandle, cszHelpFile, HELP_WM_HELP, (ULONG_PTR)aHelpIds);
  285. return TRUE;
  286. }
  287. case WM_COMMAND:
  288. switch (LOWORD(wParam)) {
  289. case IDOK:
  290. PutCmdParm(lpdci, GetDlgItemInt(hwndDlg, IDCOUNT, &fTranslated, FALSE));
  291. EndDialog(hwndDlg, DRVCNF_OK);
  292. break;
  293. case IDCANCEL:
  294. EndDialog(hwndDlg, DRVCNF_CANCEL);
  295. break;
  296. }
  297. break;
  298. default:
  299. return FALSE;
  300. }
  301. return TRUE;
  302. }
  303. /************************************************************************/
  304. /*
  305. @doc INTERNAL MCIWAVE
  306. @func int | Config |
  307. This function creates the configuration dialog, and returns the
  308. value from dialog box call.
  309. @parm HWND | hwnd |
  310. Contains the handle of what is to be the parent of the dialog.
  311. @parm <t>LPDRVCONFIGINFO<d> | lpdci |
  312. Points to the driver configuration information passed to the
  313. configuration message.
  314. @parm HINSTANCE | hInstance |
  315. Contains a handle to the module in which the dialog is stored.
  316. @rdesc Returns the dialog box call function return.
  317. */
  318. PUBLIC INT_PTR PASCAL FAR Config(
  319. HWND hwnd,
  320. LPDRVCONFIGINFO lpdci,
  321. HINSTANCE hInstance)
  322. {
  323. return DialogBoxParam(hInstance, MAKEINTRESOURCE(IDD_CONFIG), hwnd, ConfigDlgProc, (LPARAM)lpdci);
  324. }
  325. /************************************************************************/
  326.