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.

339 lines
7.0 KiB

  1. /*++
  2. Copyright (C) Microsoft Corporation, 1998 - 1998
  3. All rights reserved.
  4. Module Name:
  5. devmgrpp.cxx
  6. Abstract:
  7. Holds Device Manager Printer properties.
  8. Author:
  9. Steve Kiraly (SteveKi) 01-Jan-1999
  10. Revision History:
  11. --*/
  12. #include "precomp.hxx"
  13. #pragma hdrstop
  14. #include "devmgrpp.hxx"
  15. /*++
  16. Name:
  17. PrinterPropPageProvider
  18. Routine Description:
  19. Entry-point for adding additional device manager property
  20. sheet pages. This entry-point gets called only when the Device
  21. Manager asks for additional property pages.
  22. Arguments:
  23. pinfo - points to PROPSHEETPAGE_REQUEST, see setupapi.h
  24. pfnAdd - function ptr to call to add sheet.
  25. lParam - add sheet functions private data handle.
  26. Return Value:
  27. BOOL: FALSE if pages could not be added, TRUE on success
  28. --*/
  29. BOOL APIENTRY
  30. PrinterPropPageProvider(
  31. LPVOID pInfo,
  32. LPFNADDPROPSHEETPAGE pfnAdd,
  33. LPARAM lParam
  34. )
  35. {
  36. DBGMSG( DBG_TRACE, ( "PrinterPropPageProvider.\n" ) );
  37. TStatusB bStatus;
  38. PSP_PROPSHEETPAGE_REQUEST pReq = (PSP_PROPSHEETPAGE_REQUEST)pInfo;
  39. //
  40. // Tell the device manager we have already added our driver
  41. // page. This is just a hack to get device manager from
  42. // adding the default device page, which make no sense
  43. // for printers.
  44. //
  45. TDevInfo DevInfo( pReq->DeviceInfoSet );
  46. bStatus DBGCHK = DevInfo.TurnOnDiFlags( pReq->DeviceInfoData, DI_DRIVERPAGE_ADDED );
  47. //
  48. // Bring up the property pages.
  49. //
  50. return bCreateDevMgrPrinterPropPages( pfnAdd, lParam );
  51. }
  52. /*++
  53. Name:
  54. bCreateDevMgrPrinterPropPages
  55. Routine Description:
  56. Creates the device manager printer property pages.
  57. Arguments:
  58. pfnAdd - function ptr to call to add sheet.
  59. lParam - add sheet functions private data handle.
  60. Return Value:
  61. FALSE if pages could not be added, TRUE on success
  62. --*/
  63. BOOL
  64. bCreateDevMgrPrinterPropPages(
  65. IN LPFNADDPROPSHEETPAGE pfnAdd,
  66. IN LPARAM lParam
  67. )
  68. {
  69. TStatusB bStatus;
  70. bStatus DBGNOCHK = FALSE;
  71. HPROPSHEETPAGE hPage = NULL;
  72. TDevMgrPrinterProp *pProp = new TDevMgrPrinterProp;
  73. if( VALID_PTR( pProp ) )
  74. {
  75. PROPSHEETPAGE psp = {0};
  76. psp.dwSize = sizeof(PROPSHEETPAGE);
  77. psp.dwFlags = PSP_USECALLBACK;
  78. psp.hInstance = ghInst;
  79. psp.pszTemplate = MAKEINTRESOURCE(DLG_DEVMGR_SETTINGS);
  80. psp.pfnDlgProc = MGenericProp::SetupDlgProc;
  81. psp.lParam = reinterpret_cast<LPARAM>( reinterpret_cast<MGenericProp*>( pProp ) );
  82. psp.pfnCallback = MGenericProp::CallbackProc;
  83. hPage = CreatePropertySheetPage( &psp );
  84. bStatus DBGCHK = pfnAdd( hPage, lParam );
  85. }
  86. //
  87. // Cleanup if something failed.
  88. //
  89. if( !bStatus )
  90. {
  91. if( hPage )
  92. {
  93. DestroyPropertySheetPage( hPage );
  94. }
  95. delete pProp;
  96. }
  97. return bStatus;
  98. }
  99. /********************************************************************
  100. Device Manager printer property pages class.
  101. ********************************************************************/
  102. TDevMgrPrinterProp::
  103. TDevMgrPrinterProp(
  104. VOID
  105. )
  106. {
  107. DBGMSG( DBG_TRACE, ( "TDevMgrPrinterProp::ctor.\n" ) );
  108. }
  109. TDevMgrPrinterProp::
  110. ~TDevMgrPrinterProp(
  111. VOID
  112. )
  113. {
  114. DBGMSG( DBG_TRACE, ( "TDevMgrPrinterProp::dtor.\n" ) );
  115. }
  116. BOOL
  117. TDevMgrPrinterProp::
  118. bHandleMessage(
  119. IN UINT uMsg,
  120. IN WPARAM wParam,
  121. IN LPARAM lParam
  122. )
  123. {
  124. BOOL bRetval = TRUE;
  125. switch( uMsg )
  126. {
  127. case WM_INITDIALOG:
  128. DBGMSG( DBG_TRACE, ( "TDevMgrPrinterProp::bHandleMessage WM_INITDIALOG.\n" ) );
  129. break;
  130. case WM_HELP:
  131. case WM_CONTEXTMENU:
  132. bRetval = PrintUIHelp( uMsg, _hDlg, wParam, lParam );
  133. break;
  134. case WM_COMMAND:
  135. switch( GET_WM_COMMAND_ID( wParam, lParam ))
  136. {
  137. case IDC_PRINTERS_FOLDER:
  138. vStartPrintersFolder( _hDlg );
  139. break;
  140. default:
  141. bRetval = FALSE;
  142. break;
  143. }
  144. break;
  145. default:
  146. bRetval = FALSE;
  147. break;
  148. }
  149. return bRetval;
  150. }
  151. BOOL
  152. TDevMgrPrinterProp::
  153. bCreate(
  154. VOID
  155. )
  156. {
  157. DBGMSG( DBG_TRACE, ( "TDevMgrPrinterProp::bCreate.\n" ) );
  158. return TRUE;
  159. }
  160. VOID
  161. TDevMgrPrinterProp::
  162. vDestroy(
  163. VOID
  164. )
  165. {
  166. DBGMSG( DBG_TRACE, ( "TDevMgrPrinterProp::vDestroy.\n" ) );
  167. delete this;
  168. }
  169. VOID
  170. TDevMgrPrinterProp::
  171. vStartPrintersFolder(
  172. IN HWND hwnd
  173. )
  174. {
  175. DBGMSG( DBG_TRACE, ( "TDevMgrPrinterProp::vStartPrintersFolder.\n" ) );
  176. LPITEMIDLIST pidl = NULL;
  177. HRESULT hres = SHGetSpecialFolderLocation( hwnd, CSIDL_PRINTERS, &pidl );
  178. if (SUCCEEDED(hres))
  179. {
  180. SHELLEXECUTEINFO ei = {0};
  181. ei.cbSize = sizeof(SHELLEXECUTEINFO);
  182. ei.fMask = SEE_MASK_IDLIST;
  183. ei.hwnd = hwnd;
  184. ei.lpIDList = (LPVOID)pidl;
  185. ei.nShow = SW_SHOWNORMAL;
  186. ShellExecuteEx(&ei);
  187. }
  188. }
  189. /********************************************************************
  190. Device info class simplifies calling setup apis.
  191. ********************************************************************/
  192. TDevInfo::
  193. TDevInfo(
  194. HDEVINFO hDevInfo
  195. ) : _hDevInfo( hDevInfo ),
  196. _pfDiSetDeviceInstallParams ( NULL ),
  197. _pfDiGetDeviceInstallParams( NULL ),
  198. _pLib( NULL ),
  199. _bValid( FALSE )
  200. {
  201. DBGMSG( DBG_TRACE, ( "TDevInfo::ctor.\n" ) );
  202. _pLib = new TLibrary( TEXT("setupapi.dll") );
  203. if( VALID_PTR( _pLib ) )
  204. {
  205. _pfDiGetDeviceInstallParams = reinterpret_cast<pfSetupDiGetDeviceInstallParams>( _pLib->pfnGetProc( "SetupDiGetDeviceInstallParamsW") );
  206. _pfDiSetDeviceInstallParams = reinterpret_cast<pfSetupDiSetDeviceInstallParams>( _pLib->pfnGetProc( "SetupDiSetDeviceInstallParamsW" ) );
  207. if( _pfDiGetDeviceInstallParams && _pfDiSetDeviceInstallParams )
  208. {
  209. _bValid = TRUE;
  210. }
  211. }
  212. }
  213. TDevInfo::
  214. ~TDevInfo(
  215. VOID
  216. )
  217. {
  218. DBGMSG( DBG_TRACE, ( "TDevInfo::dtor.\n" ) );
  219. delete _pLib;
  220. }
  221. BOOL
  222. TDevInfo::
  223. bValid(
  224. VOID
  225. )
  226. {
  227. DBGMSG( DBG_TRACE, ( "TDevInfo::bValid.\n" ) );
  228. return _bValid;
  229. }
  230. BOOL
  231. TDevInfo::
  232. TurnOnDiFlags(
  233. IN PSP_DEVINFO_DATA DevData,
  234. IN DWORD dwDiFlags
  235. )
  236. {
  237. DBGMSG( DBG_TRACE, ( "TDevInfo::TurnOnDiFlags.\n" ) );
  238. BOOL bRetval = FALSE;
  239. if( bValid() )
  240. {
  241. SP_DEVINSTALL_PARAMS dip = {0};
  242. dip.cbSize = sizeof(dip);
  243. bRetval = _pfDiGetDeviceInstallParams( _hDevInfo, DevData, &dip );
  244. if( bRetval )
  245. {
  246. dip.Flags |= dwDiFlags;
  247. }
  248. bRetval = _pfDiSetDeviceInstallParams( _hDevInfo, DevData, &dip );
  249. }
  250. return bRetval;
  251. }