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.

109 lines
3.0 KiB

  1. //+-------------------------------------------------------------------------
  2. //
  3. // Microsoft Windows
  4. //
  5. // Copyright (C) Microsoft Corporation, 1998 - 2001
  6. //
  7. // File: secondaryProppages.h
  8. //
  9. //--------------------------------------------------------------------------
  10. ////////////////////////////////////////////////////////////////////////////////
  11. // CSecondaryPagesManager
  12. template <class TCOOKIE> class CSecondaryPagesManager
  13. {
  14. public:
  15. ~CSecondaryPagesManager()
  16. {
  17. ASSERT(m_secondaryPagesCookies.IsEmpty());
  18. }
  19. HRESULT CreateSheet(HWND hWndParent,
  20. LPCONSOLE pIConsole,
  21. IUnknown* pUnkComponentData,
  22. TCOOKIE* pCookie,
  23. IDataObject* pDataObject,
  24. LPCWSTR lpszTitle)
  25. {
  26. ASSERT(pIConsole != NULL);
  27. ASSERT(pDataObject != NULL);
  28. ASSERT(pUnkComponentData != NULL);
  29. // get an interface to a sheet provider
  30. CComPtr<IPropertySheetProvider> spSheetProvider;
  31. HRESULT hr = pIConsole->QueryInterface(IID_IPropertySheetProvider,(void**)&spSheetProvider);
  32. ASSERT(SUCCEEDED(hr));
  33. ASSERT(spSheetProvider != NULL);
  34. // get an interface to a sheet callback
  35. CComPtr<IPropertySheetCallback> spSheetCallback;
  36. hr = pIConsole->QueryInterface(IID_IPropertySheetCallback,(void**)&spSheetCallback);
  37. ASSERT(SUCCEEDED(hr));
  38. ASSERT(spSheetCallback != NULL);
  39. ASSERT(pDataObject != NULL);
  40. // get a sheet
  41. MMC_COOKIE cookie = reinterpret_cast<MMC_COOKIE>(pCookie);
  42. hr = spSheetProvider->CreatePropertySheet(lpszTitle, TRUE, cookie,
  43. pDataObject, 0x0 /*dwOptions*/);
  44. ASSERT(SUCCEEDED(hr));
  45. hr = spSheetProvider->AddPrimaryPages(pUnkComponentData,
  46. FALSE /*bCreateHandle*/,
  47. hWndParent,
  48. FALSE /* bScopePane*/);
  49. hr = spSheetProvider->AddExtensionPages();
  50. ASSERT(SUCCEEDED(hr));
  51. hr = spSheetProvider->Show(reinterpret_cast<LONG_PTR>(hWndParent), 0);
  52. ASSERT(SUCCEEDED(hr));
  53. if (pCookie->IsSheetLocked())
  54. {
  55. // we created the sheet correctly,
  56. // add it to the list of cookies
  57. m_secondaryPagesCookies.AddTail(pCookie);
  58. }
  59. return hr;
  60. }
  61. BOOL IsCookiePresent(TCOOKIE* pCookie)
  62. {
  63. return (m_secondaryPagesCookies.Find(pCookie) != NULL);
  64. }
  65. template <class CMP> TCOOKIE* FindCookie(CMP compare)
  66. {
  67. for (POSITION pos = m_secondaryPagesCookies.GetHeadPosition(); pos != NULL; )
  68. {
  69. TCOOKIE* pCookie = m_secondaryPagesCookies.GetNext(pos);
  70. if (compare(pCookie))
  71. {
  72. // found
  73. return pCookie;
  74. }
  75. }
  76. return NULL;
  77. }
  78. void OnSheetClose(TCOOKIE* pCookie)
  79. {
  80. // remove from the list of cookies and delete memory
  81. POSITION pos = m_secondaryPagesCookies.Find(pCookie);
  82. if (pos != NULL)
  83. {
  84. ASSERT(!pCookie->IsSheetLocked());
  85. m_secondaryPagesCookies.RemoveAt(pos);
  86. delete pCookie;
  87. }
  88. }
  89. private:
  90. CList <TCOOKIE *, TCOOKIE*> m_secondaryPagesCookies;
  91. };