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.

332 lines
10 KiB

  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 *SHOWMMCPLPROPSHEETW)(
  41. HWND hwndParent,
  42. LPCWSTR szPropSheetID,
  43. LPWSTR szTabName,
  44. LPWSTR 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. RegCloseKey(hkVideoOpt);
  78. return dwOpt;
  79. }
  80. DWORD FAR PASCAL ReadConfigInfo(void)
  81. {
  82. DWORD dwOptions = 0L;
  83. dwOptions = ReadOptionsFromReg();
  84. //
  85. // ask the display device if it can do 256 color.
  86. //
  87. #ifndef _WIN32
  88. int i;
  89. /*
  90. ** Bugbug - not apparently used, so why do it ?!?
  91. **
  92. HDC hdc;
  93. hdc = GetDC(NULL);
  94. i = GetDeviceCaps(hdc, BITSPIXEL) * GetDeviceCaps(hdc, PLANES);
  95. ReleaseDC(NULL, hdc);
  96. **
  97. **
  98. */
  99. i = mmGetProfileInt(szIni, szDEFAULTVIDEO,
  100. (i < 8 && (GetWinFlags() & WF_CPU286)) ? 240 : 0);
  101. if (i >= 200)
  102. dwOptions |= MCIAVIO_USEVGABYDEFAULT;
  103. #endif
  104. ////if (mmGetProfileInt(szIni, szSEEKEXACT, 1))
  105. // Note: We always want this option.
  106. dwOptions |= MCIAVIO_SEEKEXACT;
  107. // if (mmGetProfileInt(szIni, szZOOMBY2, 0))
  108. // dwOptions |= MCIAVIO_ZOOMBY2;
  109. ////if (mmGetProfileInt(szIni, szFAILIFNOWAVE, 0))
  110. //// dwOptions |= MCIAVIO_FAILIFNOWAVE;
  111. // if (mmGetProfileInt(szIni, szSTUPIDMODE, 0))
  112. // dwOptions |= MCIAVIO_STUPIDMODE;
  113. // Note: These settings are still in WIN.INI, not the registry
  114. // I know.
  115. if (mmGetProfileInt(szIni, szSKIPFRAMES, 1))
  116. dwOptions |= MCIAVIO_SKIPFRAMES;
  117. if (mmGetProfileInt(szIni, szUSEAVIFILE, 0))
  118. dwOptions |= MCIAVIO_USEAVIFILE;
  119. if (mmGetProfileInt(szIni, szNOSOUND, 0))
  120. dwOptions |= MCIAVIO_NOSOUND;
  121. if (mmGetProfileInt(szDrawDib, szDVA, TRUE))
  122. dwOptions |= MCIAVIO_USEDCI;
  123. return dwOptions;
  124. }
  125. void FAR PASCAL WriteConfigInfo(DWORD dwOptions)
  126. {
  127. #ifndef _WIN32
  128. // !!! This shouldn't get written out if it is the default!
  129. mmWriteProfileString(szIni, szDEFAULTVIDEO,
  130. (dwOptions & MCIAVIO_USEVGABYDEFAULT) ? szVIDEO240 : szVIDEOWINDOW);
  131. #endif
  132. ////mmWriteProfileInt(szIni, szSEEKEXACT,
  133. //// (dwOptions & MCIAVIO_SEEKEXACT) ? sz1 : sz0);
  134. // mmWriteProfileInt(szIni, szZOOMBY2,
  135. // (dwOptions & MCIAVIO_ZOOMBY2) ? sz1 : sz0);
  136. mmWriteProfileInt(szDrawDib, szDVA,
  137. (dwOptions & MCIAVIO_USEDCI) ? sz1 : sz0);
  138. ////mmWriteProfileInt(szIni, szFAILIFNOWAVE,
  139. //// (dwOptions & MCIAVIO_FAILIFNOWAVE) ? sz1 : sz0);
  140. // mmWriteProfileInt(szIni, szSTUPIDMODE,
  141. // (dwOptions & MCIAVIO_STUPIDMODE) ? sz1 : sz0);
  142. mmWriteProfileInt(szIni, szSKIPFRAMES,
  143. (dwOptions & MCIAVIO_SKIPFRAMES) ? sz1 : sz0);
  144. mmWriteProfileInt(szIni, szUSEAVIFILE,
  145. (dwOptions & MCIAVIO_USEAVIFILE) ? sz1 : sz0);
  146. mmWriteProfileInt(szIni, szNOSOUND,
  147. (dwOptions & MCIAVIO_NOSOUND) ? sz1 : sz0);
  148. }
  149. BOOL FAR PASCAL ConfigDialog(HWND hWnd, NPMCIGRAPHIC npMCI)
  150. {
  151. #define MAX_WINDOWS 10
  152. HWND hWndActive[MAX_WINDOWS];
  153. BOOL fResult = FALSE;
  154. INT ii;
  155. HWND hWndTop;
  156. HINSTANCE hInst;
  157. SHOWMMCPLPROPSHEETW fnShow;
  158. DWORD dwOptionFlags;
  159. WCHAR szCaptionW[128];
  160. WCHAR szTabW[40];
  161. UINT cchLen;
  162. LoadStringW(ghModule, IDS_VIDEOCAPTION, szCaptionW, ARRAYSIZE(szCaptionW));
  163. //Maybe the user is trying to get this dialog back because it is lost somewhere on
  164. //his/her desktop. Bring back to the top. (SetFocus does not work across threads).
  165. if (ghwndConfig)
  166. {
  167. BringWindowToTop(FindWindowW(NULL, szCaptionW));
  168. return FALSE;
  169. }
  170. if (hWnd == NULL)
  171. hWnd = GetActiveWindow();
  172. //
  173. // Enumerate all the Top level windows of this task and disable them!
  174. //
  175. for (hWndTop = GetWindow(GetDesktopWindow(), GW_CHILD), ii=0;
  176. hWndTop && ii < MAX_WINDOWS;
  177. hWndTop = GetWindow(hWndTop, GW_HWNDNEXT)) {
  178. if (IsWindowEnabled(hWndTop) &&
  179. IsWindowVisible(hWndTop) &&
  180. (HTASK)GetWindowTask(hWndTop) == GetCurrentTask() &&
  181. hWndTop != hWnd)
  182. {
  183. // don't disable our parent
  184. hWndActive[ii++] = hWndTop;
  185. EnableWindow(hWndTop, FALSE);
  186. }
  187. }
  188. //
  189. // Don't let anyone try to bring up another config sheet
  190. //
  191. if (hWnd)
  192. ghwndConfig = hWnd;
  193. else
  194. ghwndConfig = (HWND)0x800; // just in case - make sure it's non-zero
  195. //
  196. // Bring up the MCIAVI configure sheet from inside mmsys.cpl
  197. //
  198. hInst = LoadLibrary (TEXT ("mmsys.cpl"));
  199. if (hInst)
  200. {
  201. fnShow = (SHOWMMCPLPROPSHEETW)GetProcAddress(hInst, "ShowMMCPLPropertySheetW");
  202. if (fnShow)
  203. {
  204. // Note: This string is not localizable
  205. static const WCHAR szVideoW[] = L"VIDEO";
  206. LoadStringW(ghModule, IDS_VIDEO, szTabW, ARRAYSIZE(szTabW));
  207. fResult = fnShow(hWnd, szVideoW, szTabW, szCaptionW);
  208. //
  209. // Make sure the dialog changes get picked up right away
  210. // Only change those possibly affected by the dialog.
  211. // !!! This is a little hacky; knowing which ones get changed
  212. //
  213. if (npMCI && fResult)
  214. {
  215. dwOptionFlags = ReadConfigInfo();
  216. npMCI->dwOptionFlags &= ~MCIAVIO_WINDOWSIZEMASK;
  217. npMCI->dwOptionFlags &= ~MCIAVIO_ZOOMBY2;
  218. npMCI->dwOptionFlags &= ~MCIAVIO_USEVGABYDEFAULT;
  219. npMCI->dwOptionFlags |= dwOptionFlags &
  220. (MCIAVIO_WINDOWSIZEMASK | MCIAVIO_ZOOMBY2 |
  221. MCIAVIO_USEVGABYDEFAULT);
  222. }
  223. }
  224. FreeLibrary(hInst);
  225. }
  226. //
  227. // Restore all windows
  228. //
  229. while (ii-- > 0)
  230. EnableWindow(hWndActive[ii], TRUE);
  231. if (hWnd)
  232. SetActiveWindow(hWnd);
  233. ghwndConfig = NULL;
  234. return fResult;
  235. }
  236. // This function should be called only to verify that we should be using
  237. //
  238. //
  239. //
  240. #ifdef _WIN32
  241. TCHAR szWow32[] = TEXT("wow32.dll");
  242. CHAR szWOWUseMciavi16Proc[] = "WOWUseMciavi16";
  243. typedef BOOL (*PFNWOWUSEMCIAVI16PROC)(VOID);
  244. BOOL FAR PASCAL WowUseMciavi16(VOID)
  245. {
  246. HMODULE hWow32;
  247. BOOL fUseMciavi16 = FALSE;
  248. PFNWOWUSEMCIAVI16PROC pfnWOWUseMciavi16Proc;
  249. if (NULL != (hWow32 = GetModuleHandle(szWow32))) {
  250. pfnWOWUseMciavi16Proc = (PFNWOWUSEMCIAVI16PROC)GetProcAddress(hWow32, szWOWUseMciavi16Proc);
  251. if (NULL != pfnWOWUseMciavi16Proc) {
  252. fUseMciavi16 = (*pfnWOWUseMciavi16Proc)();
  253. }
  254. }
  255. return(fUseMciavi16);
  256. }
  257. #endif
  258.