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.

442 lines
15 KiB

  1. /****************************************************************************
  2. * @doc INTERNAL DIALOGS
  3. *
  4. * @module WDMDialg.cpp | Source file for <c CWDMDialog> class used to display
  5. * video settings and camera controls dialog for WDM devices.
  6. *
  7. * @comm This code is based on the VfW to WDM mapper code written by
  8. * FelixA and E-zu Wu. The original code can be found on
  9. * \\redrum\slmro\proj\wdm10\\src\image\vfw\win9x\raytube.
  10. *
  11. * Documentation by George Shaw on kernel streaming can be found in
  12. * \\popcorn\razzle1\src\spec\ks\ks.doc.
  13. *
  14. * WDM streaming capture is discussed by Jay Borseth in
  15. * \\blues\public\jaybo\WDMVCap.doc.
  16. ***************************************************************************/
  17. #include "Precomp.h"
  18. // Globals
  19. extern HINSTANCE g_hInst;
  20. /****************************************************************************
  21. * @doc INTERNAL CWDMDIALOGMETHOD
  22. *
  23. * @mfunc HPROPSHEETPAGE | CWDMDialog | Create | This function creates a new
  24. * page for a property sheet.
  25. *
  26. * @rdesc Returns the handle to the new property sheet if successful, or
  27. * NULL otherwise.
  28. ***************************************************************************/
  29. HPROPSHEETPAGE CWDMDialog::Create()
  30. {
  31. PROPSHEETPAGE psp;
  32. psp.dwSize = sizeof(psp);
  33. psp.dwFlags = PSP_USEREFPARENT;
  34. psp.hInstance = g_hInst;
  35. psp.pszTemplate = MAKEINTRESOURCE(m_DlgID);
  36. psp.pfnDlgProc = BaseDlgProc;
  37. psp.pcRefParent = 0;
  38. psp.pfnCallback = (LPFNPSPCALLBACK)NULL;
  39. psp.lParam = (LPARAM)this;
  40. return CreatePropertySheetPage(&psp);
  41. }
  42. /****************************************************************************
  43. * @doc INTERNAL CWDMDIALOGMETHOD
  44. *
  45. * @mfunc BOOL | CWDMDialog | BaseDlgProc | This function implements
  46. * the dialog box procedure for the page of a property sheet.
  47. *
  48. * @parm HWND | hDlg | Handle to dialog box.
  49. *
  50. * @parm UINT | uMessage | Message sent to the dialog box.
  51. *
  52. * @parm WPARAM | wParam | First message parameter.
  53. *
  54. * @parm LPARAM | lParam | Second message parameter.
  55. *
  56. * @rdesc Except in response to the WM_INITDIALOG message, the dialog box
  57. * procedure returns nonzero if it processes the message, and zero if it
  58. * does not.
  59. ***************************************************************************/
  60. INT_PTR CALLBACK CWDMDialog::BaseDlgProc(HWND hDlg, UINT uMessage, WPARAM wParam, LPARAM lParam)
  61. {
  62. CWDMDialog * pSV = (CWDMDialog*)GetWindowLongPtr(hDlg,DWLP_USER);
  63. FX_ENTRY("CWDMDialog::BaseDlgProc");
  64. switch (uMessage)
  65. {
  66. case WM_HELP:
  67. if (pSV->m_pdwHelp)
  68. WinHelp((HWND)((LPHELPINFO)lParam)->hItemHandle, TEXT("conf.hlp"), HELP_WM_HELP, (DWORD_PTR)pSV->m_pdwHelp);
  69. break;
  70. case WM_CONTEXTMENU:
  71. if (pSV->m_pdwHelp)
  72. WinHelp((HWND)wParam, TEXT("conf.hlp"), HELP_CONTEXTMENU, (DWORD_PTR)pSV->m_pdwHelp);
  73. break;
  74. case WM_INITDIALOG:
  75. {
  76. LPPROPSHEETPAGE psp=(LPPROPSHEETPAGE)lParam;
  77. pSV=(CWDMDialog*)psp->lParam;
  78. pSV->m_hDlg = hDlg;
  79. SetWindowLongPtr(hDlg,DWLP_USER,(LPARAM)pSV);
  80. pSV->m_bInit = FALSE;
  81. pSV->m_bChanged = FALSE;
  82. return TRUE;
  83. }
  84. break;
  85. case WM_COMMAND:
  86. if (pSV)
  87. {
  88. int iRet = pSV->DoCommand(LOWORD(wParam), HIWORD(wParam));
  89. if (!iRet && pSV->m_bInit)
  90. {
  91. PropSheet_Changed(GetParent(pSV->m_hDlg), pSV->m_hDlg);
  92. pSV->m_bChanged = TRUE;
  93. }
  94. return iRet;
  95. }
  96. break;
  97. case WM_HSCROLL:
  98. if (pSV && pSV->m_pCWDMPin && pSV->m_pPC)
  99. {
  100. HWND hwndControl = (HWND) lParam;
  101. HWND hwndSlider;
  102. ULONG i;
  103. TCHAR szTemp[32];
  104. for (i = 0 ; i < pSV->m_dwNumControls ; i++)
  105. {
  106. hwndSlider = GetDlgItem(pSV->m_hDlg, pSV->m_pPC[i].uiSlider);
  107. // find matching slider
  108. if (hwndSlider == hwndControl)
  109. {
  110. LONG lValue = (LONG)SendMessage(GetDlgItem(pSV->m_hDlg, pSV->m_pPC[i].uiSlider), TBM_GETPOS, 0, 0);
  111. pSV->m_pCWDMPin->SetPropertyValue(pSV->m_guidPropertySet, pSV->m_pPC[i].uiProperty, lValue, KSPROPERTY_FLAGS_MANUAL, pSV->m_pPC[i].ulCapabilities);
  112. pSV->m_pPC[i].lCurrentValue = lValue;
  113. wsprintf(szTemp,"%d", lValue);
  114. SetWindowText(GetDlgItem(pSV->m_hDlg, pSV->m_pPC[i].uiCurrent), szTemp);
  115. break;
  116. }
  117. }
  118. }
  119. break;
  120. case WM_NOTIFY:
  121. if (pSV)
  122. {
  123. switch (((NMHDR FAR *)lParam)->code)
  124. {
  125. case PSN_SETACTIVE:
  126. {
  127. // We call out here specially so we can mark this page as having been init'd.
  128. int iRet = pSV->SetActive();
  129. pSV->m_bInit = TRUE;
  130. return iRet;
  131. }
  132. break;
  133. case PSN_APPLY:
  134. // Since we apply the changes on the fly when the user moves the slide bars,
  135. // there isn't much left to do on PSN_APPLY...
  136. if (pSV->m_bChanged)
  137. pSV->m_bChanged = FALSE;
  138. return FALSE;
  139. break;
  140. case PSN_QUERYCANCEL:
  141. return pSV->QueryCancel();
  142. break;
  143. default:
  144. break;
  145. }
  146. }
  147. break;
  148. default:
  149. return FALSE;
  150. }
  151. return TRUE;
  152. }
  153. /****************************************************************************
  154. * @doc INTERNAL CWDMDIALOGMETHOD
  155. *
  156. * @mfunc void | CWDMDialog | CWDMDialog | Property page class constructor.
  157. *
  158. * @parm int | DlgId | Resource ID of the property page dialog.
  159. *
  160. * @parm DWORD | dwNumControls | Number of controls to display in the page.
  161. *
  162. * @parm GUID | guidPropertySet | GUID of the KS property set we are showing in
  163. * the property page.
  164. *
  165. * @parm PPROPSLIDECONTROL | pPC | Pointer to the list of slider controls
  166. * to be displayed in the property page.
  167. *
  168. * @parm PDWORD | pdwHelp | Pointer to the list of help IDs to be displayed
  169. * in the property page.
  170. *
  171. * @parm CWDMPin * | pCWDMPin | Pointer to the kernel streaming object
  172. * we will query the property on.
  173. ***************************************************************************/
  174. CWDMDialog::CWDMDialog(int DlgId, DWORD dwNumControls, GUID guidPropertySet, PPROPSLIDECONTROL pPC, PDWORD pdwHelp, CWDMPin *pCWDMPin)
  175. {
  176. FX_ENTRY("CWDMDialog::CWDMDialog");
  177. ASSERT(dwNumControls);
  178. ASSERT(pPC);
  179. m_DlgID = DlgId;
  180. m_pdwHelp = pdwHelp;
  181. m_pCWDMPin = pCWDMPin;
  182. m_dwNumControls = dwNumControls;
  183. m_guidPropertySet = guidPropertySet;
  184. m_pPC = pPC;
  185. }
  186. /****************************************************************************
  187. * @doc INTERNAL CWDMDIALOGMETHOD
  188. *
  189. * @mfunc int | CWDMDialog | SetActive | This function handles
  190. * PSN_SETACTIVE by intializing all the property page controls.
  191. *
  192. * @rdesc Always returns 0.
  193. ***************************************************************************/
  194. int CWDMDialog::SetActive()
  195. {
  196. FX_ENTRY("CWDMDialog::SetActive");
  197. DEBUGMSG(ZONE_DIALOGS, ("%s()\n", _fx_));
  198. if (!m_pCWDMPin || !m_pPC)
  199. return 0;
  200. // Returns zero to accept the activation or
  201. // -1 to activate the next or previous page
  202. // (depending on whether the user chose the Next or Back button)
  203. LONG i;
  204. EnableWindow(m_hDlg, TRUE);
  205. if (m_bInit)
  206. return 0;
  207. LONG j, lValue, lMin, lMax, lStep;
  208. ULONG ulCapabilities, ulFlags;
  209. TCHAR szDisplay[256];
  210. for (i = j = 0 ; i < (LONG)m_dwNumControls; i++)
  211. {
  212. // Get the current value
  213. if (m_pCWDMPin->GetPropertyValue(m_guidPropertySet, m_pPC[i].uiProperty, &lValue, &ulFlags, &ulCapabilities))
  214. {
  215. LoadString(g_hInst, m_pPC[i].uiString, szDisplay, sizeof(szDisplay));
  216. DEBUGMSG(ZONE_DIALOGS, ("%s: szDisplay = %s\n", _fx_, szDisplay));
  217. SetWindowText(GetDlgItem(m_hDlg, m_pPC[i].uiStatic), szDisplay);
  218. // Get the Range of Values possible.
  219. if (m_pCWDMPin->GetRangeValues(m_guidPropertySet, m_pPC[i].uiProperty, &lMin, &lMax, &lStep))
  220. {
  221. HWND hTB = GetDlgItem(m_hDlg, m_pPC[i].uiSlider);
  222. DEBUGMSG(ZONE_DIALOGS, ("(%d, %d) / %d = %d \n", lMin, lMax, lStep, (lMax-lMin)/lStep));
  223. SendMessage(hTB, TBM_SETTICFREQ, (lMax-lMin)/lStep, 0);
  224. SendMessage(hTB, TBM_SETRANGE, 0, MAKELONG(lMin, lMax));
  225. }
  226. else
  227. {
  228. ERRORMESSAGE(("%s:Cannot get range values for this property ID = %d\n", _fx_, m_pPC[j].uiProperty));
  229. }
  230. // Save these value for Cancel
  231. m_pPC[i].lLastValue = m_pPC[i].lCurrentValue = lValue;
  232. m_pPC[i].lMin = lMin;
  233. m_pPC[i].lMax = lMax;
  234. m_pPC[i].ulCapabilities = ulCapabilities;
  235. EnableWindow(GetDlgItem(m_hDlg, m_pPC[i].uiSlider), TRUE);
  236. EnableWindow(GetDlgItem(m_hDlg, m_pPC[i].uiStatic), TRUE);
  237. EnableWindow(GetDlgItem(m_hDlg, m_pPC[i].uiAuto), TRUE);
  238. SendMessage(GetDlgItem(m_hDlg, m_pPC[i].uiSlider), TBM_SETPOS, TRUE, lValue);
  239. wsprintf(szDisplay,"%d", lValue);
  240. SetWindowText(GetDlgItem(m_hDlg, m_pPC[i].uiCurrent), szDisplay);
  241. DEBUGMSG(ZONE_DIALOGS, ("%s: Capability = 0x%08lX; Flags=0x%08lX; lValue=%d\r\n", _fx_, ulCapabilities, ulFlags, lValue));
  242. DEBUGMSG(ZONE_DIALOGS, ("%s: switch(%d): \n", _fx_, ulCapabilities & (KSPROPERTY_FLAGS_MANUAL | KSPROPERTY_FLAGS_AUTO)));
  243. switch (ulCapabilities & (KSPROPERTY_FLAGS_MANUAL | KSPROPERTY_FLAGS_AUTO))
  244. {
  245. case KSPROPERTY_FLAGS_MANUAL:
  246. EnableWindow(GetDlgItem(m_hDlg, m_pPC[i].uiAuto), FALSE); // Disable auto
  247. break;
  248. case KSPROPERTY_FLAGS_AUTO:
  249. EnableWindow(GetDlgItem(m_hDlg, m_pPC[i].uiSlider), FALSE); // Disable slider;
  250. // always auto!
  251. SendMessage (GetDlgItem(m_hDlg, m_pPC[i].uiAuto),BM_SETCHECK, 1, 0);
  252. EnableWindow(GetDlgItem(m_hDlg, m_pPC[i].uiAuto), FALSE); // Disable auto (greyed out)
  253. break;
  254. case (KSPROPERTY_FLAGS_MANUAL | KSPROPERTY_FLAGS_AUTO):
  255. // Set flags
  256. if (ulFlags & KSPROPERTY_FLAGS_AUTO)
  257. {
  258. DEBUGMSG(ZONE_DIALOGS, ("%s: Auto (checked) and slider disabled\n", _fx_));
  259. // Set auto check box; greyed out slider
  260. SendMessage (GetDlgItem(m_hDlg, m_pPC[i].uiAuto),BM_SETCHECK, 1, 0);
  261. EnableWindow(GetDlgItem(m_hDlg, m_pPC[i].uiSlider), FALSE);
  262. }
  263. else
  264. {
  265. // Unchecked auto; enable slider
  266. SendMessage (GetDlgItem(m_hDlg, m_pPC[i].uiAuto),BM_SETCHECK, 0, 0);
  267. EnableWindow(GetDlgItem(m_hDlg, m_pPC[i].uiSlider), TRUE);
  268. }
  269. break;
  270. case 0:
  271. default:
  272. EnableWindow(GetDlgItem(m_hDlg, m_pPC[i].uiSlider), FALSE); // Disable slider; always auto!
  273. EnableWindow(GetDlgItem(m_hDlg, m_pPC[i].uiAuto), FALSE); // Disable auto (greyed out)
  274. break;
  275. }
  276. j++;
  277. }
  278. else
  279. {
  280. EnableWindow(GetDlgItem(m_hDlg, m_pPC[i].uiSlider), FALSE);
  281. EnableWindow(GetDlgItem(m_hDlg, m_pPC[i].uiStatic), FALSE);
  282. EnableWindow(GetDlgItem(m_hDlg, m_pPC[i].uiAuto), FALSE);
  283. }
  284. }
  285. // Disable the "default" push button;
  286. // or inform user that no control is enabled.
  287. if (j == 0)
  288. EnableWindow(GetDlgItem(m_hDlg, IDC_DEFAULT), FALSE);
  289. return 0;
  290. }
  291. /****************************************************************************
  292. * @doc INTERNAL CWDMDIALOGMETHOD
  293. *
  294. * @mfunc int | CWDMDialog | DoCommand | This function handles WM_COMMAND. This
  295. * is where a click on the Default button or one of the Auto checkboxes
  296. * is handled
  297. *
  298. * @parm WORD | wCmdID | Command ID.
  299. *
  300. * @parm WORD | hHow | Notification code.
  301. *
  302. * @rdesc Always returns 1.
  303. ***************************************************************************/
  304. int CWDMDialog::DoCommand(WORD wCmdID, WORD hHow)
  305. {
  306. // If a user select default settings of the video format
  307. if (wCmdID == IDC_DEFAULT)
  308. {
  309. if (m_pCWDMPin && m_pPC)
  310. {
  311. HWND hwndSlider;
  312. LONG lDefValue;
  313. TCHAR szTemp[32];
  314. for (ULONG i = 0 ; i < m_dwNumControls ; i++)
  315. {
  316. hwndSlider = GetDlgItem(m_hDlg, m_pPC[i].uiSlider);
  317. if (IsWindowEnabled(hwndSlider))
  318. {
  319. if (m_pCWDMPin->GetDefaultValue(m_guidPropertySet, m_pPC[i].uiProperty, &lDefValue))
  320. {
  321. if (lDefValue != m_pPC[i].lCurrentValue)
  322. {
  323. m_pCWDMPin->SetPropertyValue(m_guidPropertySet,m_pPC[i].uiProperty, lDefValue, KSPROPERTY_FLAGS_MANUAL, m_pPC[i].ulCapabilities);
  324. SendMessage(hwndSlider, TBM_SETPOS, TRUE, lDefValue);
  325. wsprintf(szTemp,"%d", lDefValue);
  326. SetWindowText(GetDlgItem(m_hDlg, m_pPC[i].uiCurrent), szTemp);
  327. m_pPC[i].lCurrentValue = lDefValue;
  328. }
  329. }
  330. }
  331. }
  332. }
  333. return 1;
  334. }
  335. else if (hHow == BN_CLICKED)
  336. {
  337. if (m_pCWDMPin && m_pPC)
  338. {
  339. for (ULONG i = 0 ; i < m_dwNumControls ; i++)
  340. {
  341. // find matching slider
  342. if (m_pPC[i].uiAuto == wCmdID)
  343. {
  344. if (BST_CHECKED == SendMessage (GetDlgItem(m_hDlg, m_pPC[i].uiAuto),BM_GETCHECK, 1, 0))
  345. {
  346. m_pCWDMPin->SetPropertyValue(m_guidPropertySet,m_pPC[i].uiProperty, m_pPC[i].lCurrentValue, KSPROPERTY_FLAGS_AUTO, m_pPC[i].ulCapabilities);
  347. EnableWindow(GetDlgItem(m_hDlg, m_pPC[i].uiSlider), FALSE);
  348. }
  349. else
  350. {
  351. m_pCWDMPin->SetPropertyValue(m_guidPropertySet,m_pPC[i].uiProperty, m_pPC[i].lCurrentValue, KSPROPERTY_FLAGS_MANUAL, m_pPC[i].ulCapabilities);
  352. EnableWindow(GetDlgItem(m_hDlg, m_pPC[i].uiSlider), TRUE);
  353. }
  354. break;
  355. }
  356. }
  357. }
  358. }
  359. return 1;
  360. }
  361. /****************************************************************************
  362. * @doc INTERNAL CWDMDIALOGMETHOD
  363. *
  364. * @mfunc int | CWDMDialog | QueryCancel | This function handles
  365. * PSN_QUERYCANCEL by resetting the values of the controls.
  366. *
  367. * @rdesc Always returns 0.
  368. ***************************************************************************/
  369. int CWDMDialog::QueryCancel()
  370. {
  371. if (m_pCWDMPin && m_pPC)
  372. {
  373. for (ULONG i = 0 ; i < m_dwNumControls ; i++)
  374. {
  375. if (IsWindowEnabled(GetDlgItem(m_hDlg, m_pPC[i].uiSlider)))
  376. {
  377. if (m_pPC[i].lLastValue != m_pPC[i].lCurrentValue)
  378. m_pCWDMPin->SetPropertyValue(m_guidPropertySet,m_pPC[i].uiProperty, m_pPC[i].lLastValue, KSPROPERTY_FLAGS_MANUAL, m_pPC[i].ulCapabilities);
  379. }
  380. }
  381. }
  382. return 0;
  383. }