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.

145 lines
4.9 KiB

  1. /******************************************************************************
  2. Header File: Property Page.H
  3. This defines the C++ class used to encapsulate property pages. This class
  4. has a static method for the dialog procedure, which automatically caches the
  5. "this" pointer for the class in the DWL_USER field of the windows internal
  6. structure for the dialog used for the property page. This hand-off is
  7. accomplished by setting the lParam field of the PROPSHEETPAGE structure to
  8. the "this" pointer. It also saves the dialog handle in a protected member
  9. for easy access from derived classes.
  10. To create a C++ class for any specific property sheet, derive the class
  11. from this class, providing the dialog ID and instance handle needed to get
  12. the resource in the m_psp member.
  13. The dialog procedure then provides virtual functions for Windows messages
  14. of interest. I've added these as needed. If I were going to a truly
  15. universal class of this sort, I'd just as well go to MFC, and save the
  16. debugging time, so this approach seems reasonable to me.
  17. Copyright (c) 1996 by Microsoft Corporation
  18. A Pretty Penny Enterprises Production
  19. Change History:
  20. 11-01-96 a-robkj@microsoft.com- original version
  21. ******************************************************************************/
  22. #if !defined(PROPERTY_PAGE)
  23. #define PROPERTY_PAGE
  24. // CPropertyPage class- abstracts a property page for us
  25. class CPropertyPage {
  26. // Basic dialog procedure for all derived classes
  27. static INT_PTR CALLBACK DialogProc(HWND hwndPage, UINT uMsg, WPARAM wp,
  28. LPARAM lp);
  29. // These elements should be protected (only available to derived classes)
  30. protected:
  31. PROPSHEETPAGE m_psp;
  32. HWND m_hwnd, m_hwndSheet;
  33. HPROPSHEETPAGE m_hpsp;
  34. BOOL m_bChanged;
  35. public:
  36. CPropertyPage(); // Default Constructor
  37. virtual ~CPropertyPage() {}
  38. HPROPSHEETPAGE Handle(); // Calls CreatePropertySheetPage, if needed
  39. VOID EnableApplyButton() {
  40. SendMessage(m_hwndSheet, PSM_CHANGED, (WPARAM) m_hwnd, 0);
  41. }
  42. VOID DisableApplyButton() {
  43. SendMessage(m_hwndSheet, PSM_UNCHANGED, (WPARAM) m_hwnd, 0);
  44. }
  45. BOOL SettingChanged() {
  46. return m_bChanged;
  47. }
  48. VOID SettingChanged(BOOL b) {
  49. m_bChanged = b;
  50. }
  51. // virtual functions- these get redefined on an as needed basis for
  52. // any specialized handling desired by any derived classes.
  53. // The default handling allows one to initially display the sheet with
  54. // no coding beyond the constructor for the derived class
  55. virtual BOOL OnCommand(WORD wNotifyCode, WORD wid, HWND hwndCtl) {
  56. return FALSE;
  57. }
  58. virtual BOOL OnNotify(int idCtrl, LPNMHDR pnmh) {
  59. return FALSE;
  60. }
  61. virtual BOOL OnInit() { return TRUE; }
  62. virtual BOOL OnDestroy() { return FALSE; }
  63. virtual BOOL OnHelp(LPHELPINFO pHelp) { return TRUE; }
  64. virtual BOOL OnContextMenu(HWND hwnd) { return TRUE; }
  65. };
  66. /******************************************************************************
  67. Shell Extension property page class
  68. Noteworthy details:
  69. These pages are displayed by the shell. The thread of execution is such that
  70. we create the page, then return to the shell. The shell will then attempt to
  71. unload the extension. It will query CanDllUnloadNow to do this. Since
  72. freeing the library frees the page template and dialog procedure, we can't
  73. allow this to happen while any instances of this class exist.
  74. However, the shell doesn't know this is a class, so it won't destroy it.
  75. What I've done is build a circular chain of all of the instances of this
  76. class, anchored in a private static class member. A public static method
  77. (OKToClose) then walks the chain. If an instance's window handle is no
  78. longer valid, then the shell has finished with it, and we delete it. The
  79. criterion for closing then becomes not finding a valid handle (so we don't
  80. delay unloading by any lazy evaluation, such as requiring an empty chain
  81. on entry).
  82. All Property pages displayed by a property sheet extension should be derived
  83. from this class.
  84. While a mechanism is provided by property sheets for a reference count
  85. maintenance mechanism, this mechanism will not call any class destructor-
  86. this could lead to memory leaks, which is why I've chosen this method.
  87. ******************************************************************************/
  88. class CShellExtensionPage: public CPropertyPage {
  89. static CShellExtensionPage *m_pcsepAnchor; // Anchor the chain of these
  90. CShellExtensionPage *m_pcsepPrevious, *m_pcsepNext;
  91. public:
  92. CShellExtensionPage();
  93. ~CShellExtensionPage();
  94. static BOOL OKToClose();
  95. };
  96. #endif // Keep us from getting multiply defined