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.

214 lines
6.4 KiB

  1. /*++
  2. Copyright (C) Microsoft Corporation
  3. Module Name:
  4. clsgenpg.cpp
  5. Abstract:
  6. This module implements CClassGeneralPage -- class general property page
  7. Author:
  8. William Hsieh (williamh) created
  9. Revision History:
  10. --*/
  11. // clsgenpg.cpp : implementation file
  12. //
  13. #include "devmgr.h"
  14. #include "clsgenpg.h"
  15. // help topic ids
  16. const DWORD g_a108HelpIDs[]=
  17. {
  18. IDC_CLSGEN_DESC, IDH_DISABLEHELP,
  19. IDC_CLSGEN_ICON, IDH_DISABLEHELP,
  20. IDC_CLSGEN_NAME, IDH_DISABLEHELP,
  21. 0, 0,
  22. };
  23. BOOL
  24. CClassGeneralPage::OnInitDialog(
  25. LPPROPSHEETPAGE ppsp
  26. )
  27. {
  28. // notify CPropSheetData about the page creation
  29. // the controls will be initialize in UpdateControls virtual function.
  30. m_pClass->m_psd.PageCreateNotify(m_hDlg);
  31. return CPropSheetPage::OnInitDialog(ppsp);
  32. }
  33. UINT
  34. CClassGeneralPage::DestroyCallback()
  35. {
  36. // the property sheet is going away, consolidate the changes on the
  37. // device.
  38. // We do this because this is the page we are sure will be created --
  39. // this page is ALWAYS the first page.
  40. //
  41. // The DevInfoList returned from GetDevInfoList() function
  42. // is maintained by the class object during its lifetime.
  43. // we must NOT release the object.
  44. CDevInfoList* pClassDevInfo = m_pClass->GetDevInfoList();
  45. if (pClassDevInfo)
  46. {
  47. if (pClassDevInfo->DiGetExFlags(NULL) & DI_FLAGSEX_PROPCHANGE_PENDING)
  48. {
  49. //
  50. // property change pending, issue a DICS_PROPERTYCHANGE to the
  51. // class installer. A DICS_PROPCHANGE would basically remove the
  52. // device subtree and reenumerate it. If each property page issues
  53. // its own DICS_PROPCHANGE command, the device subtree would
  54. // be removed/reenumerate several times even though one is enough.
  55. // A property page sets DI_FLAGEX_PROPCHANGE_PENDING when it needs
  56. // a DICS_PROPCHANGE command to be issued.
  57. //
  58. SP_PROPCHANGE_PARAMS pcp;
  59. pcp.ClassInstallHeader.cbSize = sizeof(SP_CLASSINSTALL_HEADER);
  60. pcp.ClassInstallHeader.InstallFunction = DIF_PROPERTYCHANGE;
  61. pcp.Scope = DICS_FLAG_GLOBAL;
  62. pcp.StateChange = DICS_PROPCHANGE;
  63. pClassDevInfo->DiSetClassInstallParams(NULL,
  64. &pcp.ClassInstallHeader,
  65. sizeof(pcp)
  66. );
  67. pClassDevInfo->DiCallClassInstaller(DIF_PROPERTYCHANGE, NULL);
  68. pClassDevInfo->DiTurnOnDiFlags(NULL, DI_PROPERTIES_CHANGE);
  69. pClassDevInfo->DiTurnOffDiExFlags(NULL, DI_FLAGSEX_PROPCHANGE_PENDING);
  70. }
  71. DWORD RestartFlags = pClassDevInfo->DiGetFlags();
  72. //
  73. // Do not use our window handle(or its parent) as the parent
  74. // to the newly create dialog because they are in "detroyed state".
  75. // WM_CLOSE does not help either.
  76. // NULL window handle(Desktop) should be okay here.
  77. //
  78. // We only want to prompt for a reboot if device manager is connected
  79. // to the local machine.
  80. //
  81. if (RestartFlags && m_pClass->m_pMachine->IsLocal())
  82. {
  83. //
  84. // First try and send a MMCPropertyChangeNotify message to our
  85. // CComponent so that it can prompt for a reboot inside the
  86. // device manager thread instead of our thread. If this is not
  87. // done then the property sheet will hang around after device
  88. // manager has gone away...which will cause a "hung app" dialog
  89. // to appear.
  90. //
  91. CNotifyRebootRequest* pNRR = new CNotifyRebootRequest(NULL, RestartFlags, 0);
  92. if (!m_pClass->m_psd.PropertyChangeNotify(reinterpret_cast<LONG_PTR>(pNRR))) {
  93. //
  94. // There isn't a CComponent around, so this is just a property
  95. // sheet running outside of MMC.
  96. //
  97. pNRR->Release();
  98. PromptForRestart(NULL, RestartFlags);
  99. }
  100. }
  101. // notify CPropSheetData that the property sheet is going away
  102. m_pClass->m_psd.PageDestroyNotify(m_hDlg);
  103. if (RestartFlags & DI_PROPERTIES_CHANGE)
  104. {
  105. // Class properties changed. We need to refresh the machine.
  106. // Since we are running in a separate thread, we can not
  107. // call the refresh function, instead, we schedule it.
  108. // This must be done before enabling refresh.
  109. //
  110. m_pClass->m_pMachine->ScheduleRefresh();
  111. }
  112. }
  113. //
  114. // Destory the CMachine.
  115. //
  116. CMachine* pMachine;
  117. pMachine = m_pClass->m_pMachine;
  118. if (pMachine->ShouldPropertySheetDestroy()) {
  119. delete pMachine;
  120. }
  121. return CPropSheetPage::DestroyCallback();
  122. }
  123. void
  124. CClassGeneralPage::UpdateControls(
  125. LPARAM lParam
  126. )
  127. {
  128. if (lParam)
  129. m_pClass = (CClass*)lParam;
  130. HICON hClassIcon = m_pClass->LoadIcon();
  131. if (hClassIcon)
  132. {
  133. HICON hIconOld;
  134. m_IDCicon = IDC_CLSGEN_ICON; // Save for cleanup in OnDestroy.
  135. hIconOld = (HICON)SendDlgItemMessage(m_hDlg, IDC_CLSGEN_ICON, STM_SETICON,
  136. (WPARAM)hClassIcon,
  137. 0
  138. );
  139. if (NULL != hIconOld)
  140. DestroyIcon(hIconOld);
  141. }
  142. SetDlgItemText(m_hDlg, IDC_CLSGEN_NAME, m_pClass->GetDisplayName());
  143. }
  144. HPROPSHEETPAGE
  145. CClassGeneralPage::Create(
  146. CClass* pClass
  147. )
  148. {
  149. m_pClass = pClass;
  150. m_psp.lParam = (LPARAM) this;
  151. return CreatePage();
  152. }
  153. BOOL
  154. CClassGeneralPage::OnHelp(
  155. LPHELPINFO pHelpInfo
  156. )
  157. {
  158. WinHelp((HWND)pHelpInfo->hItemHandle, DEVMGR_HELP_FILE_NAME, HELP_WM_HELP,
  159. (ULONG_PTR)g_a108HelpIDs);
  160. return FALSE;
  161. }
  162. BOOL
  163. CClassGeneralPage::OnContextMenu(
  164. HWND hWnd,
  165. WORD xPos,
  166. WORD yPos
  167. )
  168. {
  169. UNREFERENCED_PARAMETER(xPos);
  170. UNREFERENCED_PARAMETER(yPos);
  171. WinHelp(hWnd, DEVMGR_HELP_FILE_NAME, HELP_CONTEXTMENU,
  172. (ULONG_PTR)g_a108HelpIDs);
  173. return FALSE;
  174. }