Windows NT 4.0 source code leak
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.

308 lines
8.2 KiB

4 years ago
  1. /******************************************************************************
  2. Copyright (C) Microsoft Corporation 1985-1995. All rights reserved.
  3. Title: config.c - Multimedia Systems Media Control Interface
  4. driver for AVI - configuration dialog.
  5. *****************************************************************************/
  6. #include "graphic.h"
  7. #ifndef ARRAYSIZE
  8. #define ARRAYSIZE(x) (sizeof((x))/sizeof((x)[0]))
  9. #endif
  10. /*
  11. #ifndef _WIN32
  12. #define SZCODE char _based(_segname("_CODE"))
  13. #else
  14. #define SZCODE const TCHAR
  15. #endif
  16. */
  17. SZCODE szDEFAULTVIDEO[] = TEXT ("DefaultVideo");
  18. SZCODE szSEEKEXACT[] = TEXT ("AccurateSeek");
  19. SZCODE szZOOMBY2[] = TEXT ("ZoomBy2");
  20. //SZCODE szSTUPIDMODE[] = TEXT ("DontBufferOffscreen");
  21. SZCODE szSKIPFRAMES[] = TEXT ("SkipFrames");
  22. SZCODE szUSEAVIFILE[] = TEXT ("UseAVIFile");
  23. SZCODE szNOSOUND[] = TEXT("NoSound");
  24. const TCHAR szIni[] = TEXT ("MCIAVI");
  25. SZCODE gszMCIAVIOpt[] = TEXT ("Software\\Microsoft\\Multimedia\\Video For Windows\\MCIAVI");
  26. SZCODE gszDefVideoOpt[] = TEXT ("DefaultOptions");
  27. #ifdef _WIN32
  28. /* Registry values are stored as REG_DWORD */
  29. int sz1 = 1;
  30. int sz0 = 0;
  31. #else
  32. SZCODE sz1[] = TEXT("1");
  33. SZCODE sz0[] = TEXT("0");
  34. #endif
  35. SZCODE szIntl[] = TEXT ("Intl");
  36. SZCODE szDecimal[] = TEXT ("sDecimal");
  37. SZCODE szThousand[] = TEXT ("sThousand");
  38. SZCODE szDrawDib[] = TEXT("DrawDib");
  39. SZCODE szDVA[] = TEXT("DVA");
  40. typedef BOOL (WINAPI *SHOWMMCPLPROPSHEET)(
  41. HWND hwndParent,
  42. LPCSTR szPropSheetID,
  43. LPSTR szTabName,
  44. LPSTR szCaption);
  45. /* Make sure we only have one configure box up at a time.... */
  46. HWND ghwndConfig = NULL;
  47. // Converts a Wide byte character string to a single byte character string
  48. BOOL FAR PASCAL UnicodeToAnsi (
  49. char * pszDest,
  50. TCHAR * pszSrc,
  51. UINT cchMaxLen)
  52. {
  53. if ((pszDest == NULL) ||
  54. (pszSrc == NULL) ||
  55. (cchMaxLen == 0))
  56. return FALSE;
  57. WideCharToMultiByte (CP_ACP, 0, pszSrc, -1,
  58. pszDest, cchMaxLen,
  59. NULL, NULL);
  60. return TRUE;
  61. }
  62. DWORD ReadOptionsFromReg(void)
  63. {
  64. HKEY hkVideoOpt;
  65. DWORD dwType;
  66. DWORD dwOpt;
  67. DWORD cbSize;
  68. if (RegCreateKey(HKEY_CURRENT_USER, (LPTSTR)gszMCIAVIOpt, &hkVideoOpt))
  69. return 0;
  70. cbSize = sizeof(DWORD);
  71. if (RegQueryValueEx(hkVideoOpt,(LPTSTR)gszDefVideoOpt,
  72. NULL, &dwType, (LPBYTE)&dwOpt, &cbSize))
  73. {
  74. dwOpt = 0;
  75. RegSetValueEx(hkVideoOpt, (LPTSTR)gszDefVideoOpt, 0, REG_DWORD,(LPBYTE)&dwOpt, sizeof(DWORD));
  76. }
  77. return dwOpt;
  78. }
  79. DWORD FAR PASCAL ReadConfigInfo(void)
  80. {
  81. DWORD dwOptions = 0L;
  82. dwOptions = ReadOptionsFromReg();
  83. //
  84. // ask the display device if it can do 256 color.
  85. //
  86. #ifndef _WIN32
  87. int i;
  88. /*
  89. ** Bugbug - not apparently used, so why do it ?!?
  90. **
  91. HDC hdc;
  92. hdc = GetDC(NULL);
  93. i = GetDeviceCaps(hdc, BITSPIXEL) * GetDeviceCaps(hdc, PLANES);
  94. ReleaseDC(NULL, hdc);
  95. **
  96. **
  97. */
  98. i = mmGetProfileInt(szIni, szDEFAULTVIDEO,
  99. (i < 8 && (GetWinFlags() & WF_CPU286)) ? 240 : 0);
  100. if (i >= 200)
  101. dwOptions |= MCIAVIO_USEVGABYDEFAULT;
  102. #endif
  103. ////if (mmGetProfileInt(szIni, szSEEKEXACT, 1))
  104. // Note: We always want this option.
  105. dwOptions |= MCIAVIO_SEEKEXACT;
  106. // if (mmGetProfileInt(szIni, szZOOMBY2, 0))
  107. // dwOptions |= MCIAVIO_ZOOMBY2;
  108. ////if (mmGetProfileInt(szIni, szFAILIFNOWAVE, 0))
  109. //// dwOptions |= MCIAVIO_FAILIFNOWAVE;
  110. // if (mmGetProfileInt(szIni, szSTUPIDMODE, 0))
  111. // dwOptions |= MCIAVIO_STUPIDMODE;
  112. // Note: These settings are still in WIN.INI, not the registry
  113. // I know, we're stupid.
  114. if (mmGetProfileInt(szIni, szSKIPFRAMES, 1))
  115. dwOptions |= MCIAVIO_SKIPFRAMES;
  116. if (mmGetProfileInt(szIni, szUSEAVIFILE, 0))
  117. dwOptions |= MCIAVIO_USEAVIFILE;
  118. if (mmGetProfileInt(szIni, szNOSOUND, 0))
  119. dwOptions |= MCIAVIO_NOSOUND;
  120. if (mmGetProfileInt(szDrawDib, szDVA, TRUE))
  121. dwOptions |= MCIAVIO_USEDCI;
  122. return dwOptions;
  123. }
  124. void FAR PASCAL WriteConfigInfo(DWORD dwOptions)
  125. {
  126. #ifndef _WIN32
  127. // !!! This shouldn't get written out if it is the default!
  128. mmWriteProfileString(szIni, szDEFAULTVIDEO,
  129. (dwOptions & MCIAVIO_USEVGABYDEFAULT) ? szVIDEO240 : szVIDEOWINDOW);
  130. #endif
  131. ////mmWriteProfileInt(szIni, szSEEKEXACT,
  132. //// (dwOptions & MCIAVIO_SEEKEXACT) ? sz1 : sz0);
  133. // mmWriteProfileInt(szIni, szZOOMBY2,
  134. // (dwOptions & MCIAVIO_ZOOMBY2) ? sz1 : sz0);
  135. mmWriteProfileInt(szDrawDib, szDVA,
  136. (dwOptions & MCIAVIO_USEDCI) ? sz1 : sz0);
  137. ////mmWriteProfileInt(szIni, szFAILIFNOWAVE,
  138. //// (dwOptions & MCIAVIO_FAILIFNOWAVE) ? sz1 : sz0);
  139. // mmWriteProfileInt(szIni, szSTUPIDMODE,
  140. // (dwOptions & MCIAVIO_STUPIDMODE) ? sz1 : sz0);
  141. mmWriteProfileInt(szIni, szSKIPFRAMES,
  142. (dwOptions & MCIAVIO_SKIPFRAMES) ? sz1 : sz0);
  143. mmWriteProfileInt(szIni, szUSEAVIFILE,
  144. (dwOptions & MCIAVIO_USEAVIFILE) ? sz1 : sz0);
  145. mmWriteProfileInt(szIni, szNOSOUND,
  146. (dwOptions & MCIAVIO_NOSOUND) ? sz1 : sz0);
  147. }
  148. BOOL FAR PASCAL ConfigDialog(HWND hWnd, NPMCIGRAPHIC npMCI)
  149. {
  150. #define MAX_WINDOWS 10
  151. HWND hWndActive[MAX_WINDOWS];
  152. BOOL fResult = FALSE;
  153. INT ii;
  154. HWND hWndTop;
  155. HINSTANCE hInst;
  156. SHOWMMCPLPROPSHEET fnShow;
  157. DWORD dwOptionFlags;
  158. TCHAR szBuffer[128];
  159. char szCaption[128];
  160. char szTab[40];
  161. UINT cchLen;
  162. // Bugbug: Remove UnicodeToAnsi Gymnastics as soon as MMSYS.CPL is
  163. // completely Unicode Enabled
  164. LoadString(ghModule, IDS_VIDEOCAPTION, szBuffer, ARRAYSIZE(szBuffer));
  165. if (! UnicodeToAnsi (szCaption, szBuffer, ARRAYSIZE(szCaption)))
  166. return FALSE;
  167. //Maybe the user is trying to get this dialog back because it is lost somewhere on
  168. //his/her desktop. Bring back to the top. (SetFocus does not work across threads).
  169. if (ghwndConfig)
  170. {
  171. BringWindowToTop(FindWindow(NULL, (LPCTSTR)szBuffer));
  172. return FALSE;
  173. }
  174. if (hWnd == NULL)
  175. hWnd = GetActiveWindow();
  176. //
  177. // Enumerate all the Top level windows of this task and disable them!
  178. //
  179. for (hWndTop = GetWindow(GetDesktopWindow(), GW_CHILD), ii=0;
  180. hWndTop && ii < MAX_WINDOWS;
  181. hWndTop = GetWindow(hWndTop, GW_HWNDNEXT)) {
  182. if (IsWindowEnabled(hWndTop) &&
  183. IsWindowVisible(hWndTop) &&
  184. (HTASK)GetWindowTask(hWndTop) == GetCurrentTask() &&
  185. hWndTop != hWnd)
  186. {
  187. // don't disable our parent
  188. hWndActive[ii++] = hWndTop;
  189. EnableWindow(hWndTop, FALSE);
  190. }
  191. }
  192. //
  193. // Don't let anyone try to bring up another config sheet
  194. //
  195. if (hWnd)
  196. ghwndConfig = hWnd;
  197. else
  198. ghwndConfig = (HWND)0x800; // just in case - make sure it's non-zero
  199. //
  200. // Bring up the MCIAVI configure sheet from inside mmsys.cpl
  201. //
  202. hInst = LoadLibrary (TEXT ("mmsys.cpl"));
  203. if (hInst)
  204. {
  205. fnShow = (SHOWMMCPLPROPSHEET)GetProcAddress(hInst, "ShowMMCPLPropertySheet");
  206. if (fnShow)
  207. {
  208. // Note: This string is not localizable
  209. static const char szVideo[] = "VIDEO";
  210. // Bugbug: Remove UnicodeToAnsi Gymnastics as soon as MMSYS.CPL is
  211. // completely Unicode Enabled
  212. LoadString(ghModule, IDS_VIDEO, szBuffer, ARRAYSIZE(szBuffer));
  213. if (UnicodeToAnsi (szTab, szBuffer, ARRAYSIZE(szTab)))
  214. {
  215. fResult = fnShow(hWnd, (LPSTR)szVideo, (LPSTR)szTab, (LPSTR)szCaption);
  216. //
  217. // Make sure the dialog changes get picked up right away
  218. // Only change those possibly affected by the dialog.
  219. // !!! This is a little hacky; knowing which ones get changed
  220. //
  221. if (npMCI && fResult)
  222. {
  223. dwOptionFlags = ReadConfigInfo();
  224. npMCI->dwOptionFlags &= ~MCIAVIO_WINDOWSIZEMASK;
  225. npMCI->dwOptionFlags &= ~MCIAVIO_ZOOMBY2;
  226. npMCI->dwOptionFlags &= ~MCIAVIO_USEVGABYDEFAULT;
  227. npMCI->dwOptionFlags |= dwOptionFlags &
  228. (MCIAVIO_WINDOWSIZEMASK | MCIAVIO_ZOOMBY2 |
  229. MCIAVIO_USEVGABYDEFAULT);
  230. }
  231. }
  232. }
  233. FreeLibrary(hInst);
  234. }
  235. //
  236. // Restore all windows
  237. //
  238. while (ii-- > 0)
  239. EnableWindow(hWndActive[ii], TRUE);
  240. if (hWnd)
  241. SetActiveWindow(hWnd);
  242. ghwndConfig = NULL;
  243. return fResult;
  244. }