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.

432 lines
11 KiB

  1. /*****************************************************************************
  2. *
  3. * (C) COPYRIGHT MICROSOFT CORPORATION, 2000
  4. *
  5. * TITLE: WiaVideoTest.cpp
  6. *
  7. * VERSION: 1.0
  8. *
  9. * DATE: 2000/11/14
  10. *
  11. * DESCRIPTION: Creates the dialog used by the app
  12. *
  13. *****************************************************************************/
  14. #include <stdafx.h>
  15. #define INCL_APP_GVAR_OWNERSHIP
  16. #include "WiaVideoTest.h"
  17. ///////////////////////////////
  18. // Constants
  19. //
  20. const UINT WM_CUSTOM_INIT = WM_USER + 100;
  21. /****************************Local Function Prototypes********************/
  22. INT_PTR CALLBACK MainDlgProc(HWND hDlg,
  23. UINT uiMessage,
  24. WPARAM wParam,
  25. LPARAM lParam);
  26. INT_PTR ProcessWMCommand(HWND hWnd,
  27. UINT uiMessage,
  28. WPARAM wParam,
  29. LPARAM lParam);
  30. INT_PTR ProcessWMNotify(HWND hWnd,
  31. UINT uiMessage,
  32. WPARAM wParam,
  33. LPARAM lParam);
  34. BOOL InitApp(HINSTANCE hInstance);
  35. void TermApp(void);
  36. BOOL InitInstance(HINSTANCE hInstance,
  37. int nCmdShow);
  38. void InitDlg(HWND hwndDlg);
  39. void TermDlg(HWND hwndDlg);
  40. int WINAPI WinMain(HINSTANCE hInstance,
  41. HINSTANCE hPrevInstance,
  42. LPSTR lpCmdLine,
  43. int nCmdShow);
  44. ///////////////////////////////
  45. // WinMain
  46. //
  47. int WINAPI WinMain(HINSTANCE hInstance,
  48. HINSTANCE hPrevInstance,
  49. LPSTR lpCmdLine,
  50. int nCmdShow)
  51. {
  52. MSG msg;
  53. BOOL bSuccess = TRUE;
  54. TCHAR *pszBaseDir = NULL;
  55. INITCOMMONCONTROLSEX CommonControls = {0};
  56. lpCmdLine = lpCmdLine;
  57. hPrevInstance = hPrevInstance;
  58. CoInitializeEx(NULL, COINIT_MULTITHREADED);
  59. CommonControls.dwSize = sizeof(CommonControls);
  60. CommonControls.dwICC = ICC_WIN95_CLASSES;
  61. bSuccess = InitCommonControlsEx(&CommonControls);
  62. if (bSuccess)
  63. {
  64. bSuccess =InitApp(hInstance);
  65. }
  66. if (bSuccess)
  67. {
  68. // create the window
  69. bSuccess = InitInstance(hInstance, nCmdShow);
  70. }
  71. if (bSuccess)
  72. {
  73. while (GetMessage(&msg, NULL, 0, 0))
  74. {
  75. if ((APP_GVAR.hwndMainDlg == NULL) ||
  76. (!IsDialogMessage(APP_GVAR.hwndMainDlg, &msg)))
  77. {
  78. TranslateMessage(&msg);
  79. DispatchMessage(&msg);
  80. }
  81. }
  82. }
  83. // Terminate the application.
  84. TermApp();
  85. CoUninitialize();
  86. return 0;
  87. }
  88. ///////////////////////////////
  89. // InitApp(HANDLE)
  90. //
  91. // Initializes window data and
  92. // registers window class
  93. //
  94. BOOL InitApp(HINSTANCE hInstance)
  95. {
  96. BOOL bSuccess = TRUE;
  97. HWND hPrevWnd = NULL;
  98. WNDCLASSEX wc;
  99. if (bSuccess)
  100. {
  101. // Fill in window class structure with parameters that describe
  102. // the main window.
  103. wc.style = 0;
  104. wc.cbSize = sizeof(wc);
  105. wc.lpfnWndProc = (WNDPROC)MainDlgProc;
  106. wc.cbClsExtra = 0;
  107. wc.cbWndExtra = DLGWINDOWEXTRA;
  108. wc.hInstance = hInstance;
  109. wc.hIcon = NULL;
  110. wc.hIconSm = NULL;
  111. wc.hCursor = 0;
  112. wc.hbrBackground = (HBRUSH)(COLOR_WINDOW+1);
  113. wc.lpszMenuName = 0;
  114. wc.lpszClassName = TEXT("WIAVIDEOTEST");
  115. }
  116. if (bSuccess)
  117. {
  118. RegisterClassEx(&wc);
  119. }
  120. return bSuccess;
  121. }
  122. ///////////////////////////////
  123. // InitInstance(HANDLE, int)
  124. //
  125. // Saves instance handle and
  126. // creates main window
  127. //
  128. BOOL InitInstance(HINSTANCE hInstance,
  129. int nCmdShow)
  130. {
  131. BOOL bSuccess = TRUE;
  132. HWND hwnd = NULL;
  133. // create the window and all its controls.
  134. if (bSuccess)
  135. {
  136. // create a modeless dialog box.
  137. hwnd = CreateDialog(hInstance,
  138. MAKEINTRESOURCE(IDD_MAIN_DLG),
  139. HWND_DESKTOP,
  140. NULL);
  141. if (!hwnd)
  142. {
  143. bSuccess = FALSE;
  144. }
  145. }
  146. if (bSuccess)
  147. {
  148. APP_GVAR.hwndMainDlg = hwnd;
  149. ShowWindow(hwnd, nCmdShow);
  150. }
  151. return bSuccess;
  152. }
  153. ///////////////////////////////
  154. // InitDlg(HWND)
  155. //
  156. // Initializes the main dlg
  157. //
  158. void InitDlg(HWND hwndDlg)
  159. {
  160. SetCursor( LoadCursor(NULL, IDC_WAIT));
  161. SetDlgItemInt(APP_GVAR.hwndMainDlg, IDC_EDIT_NUM_STRESS_THREADS,
  162. 0, FALSE);
  163. SetDlgItemInt(APP_GVAR.hwndMainDlg, IDC_EDIT_NUM_PICTURES_TAKEN,
  164. 0, FALSE);
  165. //
  166. // Set the WIA Device List Radio box to checked and the DShow
  167. // Device List Radio box to unchecked.
  168. //
  169. SendDlgItemMessage(APP_GVAR.hwndMainDlg, IDC_RADIO_WIA_DEVICE_LIST,
  170. BM_SETCHECK, BST_CHECKED, 0);
  171. SendDlgItemMessage(APP_GVAR.hwndMainDlg, IDC_RADIO_DSHOW_DEVICE_LIST,
  172. BM_SETCHECK, BST_UNCHECKED, 0);
  173. EnableWindow(GetDlgItem(APP_GVAR.hwndMainDlg, IDC_BUTTON_CREATE_VIDEO_WIA), TRUE);
  174. EnableWindow(GetDlgItem(APP_GVAR.hwndMainDlg, IDC_BUTTON_CREATE_VIDEO_ENUM_POS), FALSE);
  175. EnableWindow(GetDlgItem(APP_GVAR.hwndMainDlg, IDC_BUTTON_CREATE_VIDEO_FRIENDLY_NAME), FALSE);
  176. //
  177. // initialize WiaProc_Init because by default we are in WIA Device List
  178. // Mode.
  179. //
  180. APP_GVAR.bWiaDeviceListMode = TRUE;
  181. WiaProc_Init();
  182. VideoProc_Init();
  183. SetCursor( LoadCursor(NULL, IDC_ARROW));
  184. return;
  185. }
  186. ///////////////////////////////
  187. // TermDlg(HWND)
  188. //
  189. void TermDlg(HWND hwndDlg)
  190. {
  191. SetCursor( LoadCursor(NULL, IDC_WAIT));
  192. VideoProc_Term();
  193. WiaProc_Term();
  194. SetCursor( LoadCursor(NULL, IDC_ARROW));
  195. }
  196. ///////////////////////////////
  197. // TermApp
  198. //
  199. void TermApp(void)
  200. {
  201. }
  202. //////////////////////////////////////////////////////////////////////
  203. // MainDlgProc
  204. //
  205. INT_PTR CALLBACK MainDlgProc(HWND hDlg,
  206. UINT uiMessage,
  207. WPARAM wParam,
  208. LPARAM lParam)
  209. {
  210. INT_PTR iReturn = 0;
  211. switch (uiMessage)
  212. {
  213. case WM_CREATE:
  214. PostMessage(hDlg,
  215. WM_CUSTOM_INIT,
  216. 0,
  217. 0);
  218. return 0;
  219. break;
  220. case WM_CUSTOM_INIT:
  221. InitDlg(hDlg);
  222. break;
  223. //
  224. // Defined in WiaProc.h
  225. //
  226. case WM_CUSTOM_ADD_IMAGE:
  227. ImageLst_AddImageToList((BSTR)lParam);
  228. break;
  229. case WM_CLOSE:
  230. // terminate the dialog subsystems
  231. TermDlg(hDlg);
  232. DestroyWindow(hDlg);
  233. break;
  234. case WM_DESTROY:
  235. // terminate the application
  236. PostQuitMessage(0);
  237. break;
  238. case WM_COMMAND:
  239. iReturn = ProcessWMCommand(hDlg,
  240. uiMessage,
  241. wParam,
  242. lParam);
  243. break;
  244. case WM_NOTIFY:
  245. iReturn = ProcessWMNotify(hDlg,
  246. uiMessage,
  247. wParam,
  248. lParam);
  249. break;
  250. default:
  251. iReturn = DefDlgProc(hDlg,
  252. uiMessage,
  253. wParam,
  254. lParam);
  255. break;
  256. }
  257. return iReturn;
  258. }
  259. ///////////////////////////////
  260. // ProcessWMCommand
  261. //
  262. //
  263. INT_PTR ProcessWMCommand(HWND hWnd,
  264. UINT uiMessage,
  265. WPARAM wParam,
  266. LPARAM lParam)
  267. {
  268. int iId;
  269. int iEvent;
  270. INT_PTR iReturn = 0;
  271. iId = LOWORD(wParam);
  272. iEvent = HIWORD(wParam);
  273. //Parse the menu selections:
  274. switch (iId)
  275. {
  276. case IDC_BUTTON_CREATE_VIDEO_WIA:
  277. case IDC_BUTTON_CREATE_VIDEO_ENUM_POS:
  278. case IDC_BUTTON_CREATE_VIDEO_FRIENDLY_NAME:
  279. case IDC_BUTTON_DESTROY_VIDEO:
  280. case IDC_BUTTON_PLAY:
  281. case IDC_BUTTON_PAUSE:
  282. case IDC_BUTTON_TAKE_PICTURE:
  283. case IDC_BUTTON_TAKE_PICTURE_DRIVER:
  284. case IDC_BUTTON_SHOW_VIDEO_TOGGLE:
  285. case IDC_BUTTON_RESIZE_TOGGLE:
  286. case IDC_BUTTON_TAKE_PICTURE_STRESS:
  287. case IDC_BUTTON_TAKE_PICTURE_MULTIPLE:
  288. VideoProc_ProcessMsg(iId);
  289. break;
  290. case IDC_RADIO_WIA_DEVICE_LIST:
  291. EnableWindow(GetDlgItem(APP_GVAR.hwndMainDlg, IDC_BUTTON_CREATE_VIDEO_WIA), TRUE);
  292. EnableWindow(GetDlgItem(APP_GVAR.hwndMainDlg, IDC_BUTTON_CREATE_VIDEO_ENUM_POS), FALSE);
  293. EnableWindow(GetDlgItem(APP_GVAR.hwndMainDlg, IDC_BUTTON_CREATE_VIDEO_FRIENDLY_NAME), FALSE);
  294. SendDlgItemMessage(APP_GVAR.hwndMainDlg, IDC_RADIO_WIA_DEVICE_LIST,
  295. BM_SETCHECK, BST_CHECKED, 0);
  296. SendDlgItemMessage(APP_GVAR.hwndMainDlg, IDC_RADIO_DSHOW_DEVICE_LIST,
  297. BM_SETCHECK, BST_UNCHECKED, 0);
  298. APP_GVAR.bWiaDeviceListMode = TRUE;
  299. VideoProc_DShowListTerm();
  300. WiaProc_Init();
  301. break;
  302. case IDC_RADIO_DSHOW_DEVICE_LIST:
  303. EnableWindow(GetDlgItem(APP_GVAR.hwndMainDlg, IDC_BUTTON_CREATE_VIDEO_WIA), FALSE);
  304. EnableWindow(GetDlgItem(APP_GVAR.hwndMainDlg, IDC_BUTTON_CREATE_VIDEO_ENUM_POS), TRUE);
  305. EnableWindow(GetDlgItem(APP_GVAR.hwndMainDlg, IDC_BUTTON_CREATE_VIDEO_FRIENDLY_NAME), TRUE);
  306. SendDlgItemMessage(APP_GVAR.hwndMainDlg, IDC_RADIO_WIA_DEVICE_LIST,
  307. BM_SETCHECK, BST_UNCHECKED, 0);
  308. SendDlgItemMessage(APP_GVAR.hwndMainDlg, IDC_RADIO_DSHOW_DEVICE_LIST,
  309. BM_SETCHECK, BST_CHECKED, 0);
  310. APP_GVAR.bWiaDeviceListMode = FALSE;
  311. WiaProc_Term();
  312. VideoProc_DShowListInit();
  313. break;
  314. default:
  315. break;
  316. }
  317. UNREFERENCED_PARAMETER(hWnd);
  318. UNREFERENCED_PARAMETER(uiMessage);
  319. UNREFERENCED_PARAMETER(lParam);
  320. return iReturn;
  321. }
  322. ///////////////////////////////
  323. // ProcessWMNotify
  324. //
  325. INT_PTR ProcessWMNotify(HWND hWnd,
  326. UINT uiMessage,
  327. WPARAM wParam,
  328. LPARAM lParam)
  329. {
  330. INT_PTR iReturn = 0;
  331. NMHDR *pNotifyHdr = NULL;
  332. UINT uiNotifyCode = 0;
  333. int iIDCtrl = 0;
  334. // iIDCtrl = wParam;
  335. //
  336. // pNotifyHdr = (LPNMHDR) lParam;
  337. // uiNotifyCode = pNotifyHdr->code;
  338. // switch (uiNotifyCode)
  339. // {
  340. // default:
  341. // break;
  342. // }
  343. UNREFERENCED_PARAMETER(hWnd);
  344. UNREFERENCED_PARAMETER(uiMessage);
  345. return iReturn;
  346. }