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.

204 lines
5.6 KiB

  1. /*++
  2. Copyright (C) 1997-1999 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. if (PromptForRestart(NULL, RestartFlags) == IDNO) {
  84. if (m_pClass->m_pMachine->m_ParentMachine) {
  85. m_pClass->m_pMachine->m_ParentMachine->ScheduleRefresh();
  86. } else {
  87. m_pClass->m_pMachine->ScheduleRefresh();
  88. }
  89. }
  90. }
  91. // notify CPropSheetData that the property sheet is going away
  92. m_pClass->m_psd.PageDestroyNotify(m_hDlg);
  93. if (RestartFlags & DI_PROPERTIES_CHANGE)
  94. {
  95. // Class properties changed. We need to refresh the machine.
  96. // Since we are running in a separate thread, we can not
  97. // call the refresh function, instead, we schedule it.
  98. // This must be done before enabling refresh.
  99. //
  100. m_pClass->m_pMachine->ScheduleRefresh();
  101. }
  102. }
  103. //
  104. // Destory the CMachine.
  105. //
  106. CMachine* pMachine;
  107. pMachine = m_pClass->m_pMachine;
  108. if (pMachine->ShouldPropertySheetDestroy()) {
  109. delete pMachine;
  110. }
  111. return CPropSheetPage::DestroyCallback();
  112. }
  113. void
  114. CClassGeneralPage::UpdateControls(
  115. LPARAM lParam
  116. )
  117. {
  118. if (lParam)
  119. m_pClass = (CClass*)lParam;
  120. HICON hClassIcon = m_pClass->LoadIcon();
  121. if (hClassIcon)
  122. {
  123. HICON hIconOld;
  124. m_IDCicon = IDC_CLSGEN_ICON; // Save for cleanup in OnDestroy.
  125. hIconOld = (HICON)SendDlgItemMessage(m_hDlg, IDC_CLSGEN_ICON, STM_SETICON,
  126. (WPARAM)hClassIcon,
  127. 0
  128. );
  129. if (NULL != hIconOld)
  130. DestroyIcon(hIconOld);
  131. }
  132. SetDlgItemText(m_hDlg, IDC_CLSGEN_NAME, m_pClass->GetDisplayName());
  133. }
  134. HPROPSHEETPAGE
  135. CClassGeneralPage::Create(
  136. CClass* pClass
  137. )
  138. {
  139. m_pClass = pClass;
  140. m_psp.lParam = (LPARAM) this;
  141. return CreatePage();
  142. }
  143. BOOL
  144. CClassGeneralPage::OnHelp(
  145. LPHELPINFO pHelpInfo
  146. )
  147. {
  148. WinHelp((HWND)pHelpInfo->hItemHandle, DEVMGR_HELP_FILE_NAME, HELP_WM_HELP,
  149. (ULONG_PTR)g_a108HelpIDs);
  150. return FALSE;
  151. }
  152. BOOL
  153. CClassGeneralPage::OnContextMenu(
  154. HWND hWnd,
  155. WORD xPos,
  156. WORD yPos
  157. )
  158. {
  159. WinHelp(hWnd, DEVMGR_HELP_FILE_NAME, HELP_CONTEXTMENU,
  160. (ULONG_PTR)g_a108HelpIDs);
  161. return FALSE;
  162. }