Source code of Windows XP (NT5)
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.

234 lines
6.0 KiB

  1. /****************************************************************************
  2. *
  3. * capmisc.c
  4. *
  5. * Miscellaneous status and error routines.
  6. *
  7. * Microsoft Video for Windows Sample Capture Class
  8. *
  9. * Copyright (c) 1992, 1993 Microsoft Corporation. All Rights Reserved.
  10. *
  11. * You have a royalty-free right to use, modify, reproduce and
  12. * distribute the Sample Files (and/or any modified version) in
  13. * any way you find useful, provided that you agree that
  14. * Microsoft has no warranty obligations or liability for any
  15. * Sample Application Files which are modified.
  16. *
  17. ***************************************************************************/
  18. #include <windows.h>
  19. #include <windowsx.h>
  20. #include <mmsystem.h>
  21. #include <msvideo.h>
  22. #include <drawdib.h>
  23. #include "avicap.h"
  24. #include "avicapi.h"
  25. static char szNull[] = "";
  26. /*
  27. *
  28. * GetKey
  29. * Peek into the message que and get a keystroke
  30. *
  31. */
  32. WORD GetKey(BOOL fWait)
  33. {
  34. MSG msg;
  35. msg.wParam = 0;
  36. if (fWait)
  37. GetMessage(&msg, NULL, WM_KEYFIRST, WM_KEYLAST);
  38. while(PeekMessage(&msg, NULL, WM_KEYFIRST, WM_KEYLAST, PM_REMOVE|PM_NOYIELD))
  39. ;
  40. return msg.wParam;
  41. }
  42. // wID is the string resource, which can be a format string
  43. void FAR _cdecl statusUpdateStatus (LPCAPSTREAM lpcs, WORD wID, ...)
  44. {
  45. char ach[256];
  46. char szFmt[132];
  47. int j, k;
  48. BOOL fHasFormatChars = FALSE;
  49. if (lpcs-> CallbackOnStatus) {
  50. if (wID == NULL) {
  51. if (lpcs->fLastStatusWasNULL) // No need to send NULL twice in a row
  52. return;
  53. lpcs->fLastStatusWasNULL = TRUE;
  54. lstrcpy (ach, szNull);
  55. }
  56. else if (!LoadString(lpcs->hInst, wID, szFmt, sizeof (szFmt))) {
  57. lpcs->fLastStatusWasNULL = FALSE;
  58. MessageBeep (0);
  59. return;
  60. }
  61. else {
  62. lpcs->fLastStatusWasNULL = FALSE;
  63. k = lstrlen (szFmt);
  64. for (j = 0; j < k; j++) {
  65. if (szFmt[j] == '%') {
  66. fHasFormatChars = TRUE;
  67. break;
  68. }
  69. }
  70. if (fHasFormatChars)
  71. wvsprintf(ach, szFmt, (LPSTR)(((WORD FAR *)&wID) + 1));
  72. else
  73. lstrcpy (ach, szFmt);
  74. }
  75. (*(lpcs->CallbackOnStatus)) (lpcs->hwnd, wID, ach);
  76. }
  77. }
  78. // wID is the string resource, which can be a format string
  79. void FAR _cdecl errorUpdateError (LPCAPSTREAM lpcs, WORD wID, ...)
  80. {
  81. char ach[256];
  82. char szFmt[132];
  83. int j, k;
  84. BOOL fHasFormatChars = FALSE;
  85. lpcs->dwReturn = wID;
  86. if (lpcs-> CallbackOnError) {
  87. if (wID == NULL) {
  88. if (lpcs->fLastErrorWasNULL) // No need to send NULL twice in a row
  89. return;
  90. lpcs->fLastErrorWasNULL = TRUE;
  91. lstrcpy (ach, szNull);
  92. }
  93. else if (!LoadString(lpcs->hInst, wID, szFmt, sizeof (szFmt))) {
  94. MessageBeep (0);
  95. lpcs->fLastErrorWasNULL = FALSE;
  96. return;
  97. }
  98. else {
  99. lpcs->fLastErrorWasNULL = FALSE;
  100. k = lstrlen (szFmt);
  101. for (j = 0; j < k; j++) {
  102. if (szFmt[j] == '%') {
  103. fHasFormatChars = TRUE;
  104. break;
  105. }
  106. }
  107. if (fHasFormatChars)
  108. wvsprintf(ach, szFmt, (LPSTR)(((WORD FAR *)&wID) + 1));
  109. else
  110. lstrcpy (ach, szFmt);
  111. }
  112. (*(lpcs->CallbackOnError)) (lpcs->hwnd, wID, ach);
  113. }
  114. }
  115. // Callback client with ID of driver error msg
  116. void errorDriverID (LPCAPSTREAM lpcs, DWORD dwError)
  117. {
  118. char ach[132];
  119. lpcs->fLastErrorWasNULL = FALSE;
  120. lpcs->dwReturn = dwError;
  121. if (lpcs-> CallbackOnError) {
  122. if (!dwError)
  123. lstrcpy (ach, szNull);
  124. else {
  125. videoGetErrorText (lpcs->hVideoIn,
  126. (UINT)dwError, ach, sizeof(ach));
  127. }
  128. (*(lpcs->CallbackOnError)) (lpcs->hwnd, IDS_CAP_DRIVER_ERROR, ach);
  129. }
  130. }
  131. #ifdef _DEBUG
  132. void FAR cdecl dprintf(LPSTR szFormat, ...)
  133. {
  134. char ach[128];
  135. static BOOL fDebug = -1;
  136. if (fDebug == -1)
  137. fDebug = GetProfileInt("Debug", "AVICAP", FALSE);
  138. if (!fDebug)
  139. return;
  140. lstrcpy(ach, "AVICAP: ");
  141. wvsprintf(ach+8,szFormat,(LPSTR)(&szFormat+1));
  142. lstrcat(ach, "\r\n");
  143. OutputDebugString(ach);
  144. }
  145. /* _Assert(fExpr, szFile, iLine)
  146. *
  147. * If <fExpr> is TRUE, then do nothing. If <fExpr> is FALSE, then display
  148. * an "assertion failed" message box allowing the user to abort the program,
  149. * enter the debugger (the "Retry" button), or igore the error.
  150. *
  151. * <szFile> is the name of the source file; <iLine> is the line number
  152. * containing the _Assert() call.
  153. */
  154. #pragma optimize("", off)
  155. BOOL FAR PASCAL
  156. _Assert(BOOL fExpr, LPSTR szFile, int iLine)
  157. {
  158. static char ach[300]; // debug output (avoid stack overflow)
  159. int id;
  160. int iExitCode;
  161. void FAR PASCAL DebugBreak(void);
  162. /* check if assertion failed */
  163. if (fExpr)
  164. return fExpr;
  165. /* display error message */
  166. wsprintf(ach, "File %s, line %d", (LPSTR) szFile, iLine);
  167. MessageBeep(MB_ICONHAND);
  168. id = MessageBox(NULL, ach, "Assertion Failed", MB_SYSTEMMODAL | MB_ICONHAND | MB_ABORTRETRYIGNORE);
  169. /* abort, debug, or ignore */
  170. switch (id)
  171. {
  172. case IDABORT:
  173. /* kill this application */
  174. iExitCode = 0;
  175. #ifndef WIN32
  176. _asm
  177. {
  178. mov ah, 4Ch
  179. mov al, BYTE PTR iExitCode
  180. int 21h
  181. }
  182. #endif // WIN16
  183. break;
  184. case IDRETRY:
  185. /* break into the debugger */
  186. DebugBreak();
  187. break;
  188. case IDIGNORE:
  189. /* ignore the assertion failure */
  190. break;
  191. }
  192. return FALSE;
  193. }
  194. #pragma optimize("", on)
  195. #endif
  196.