test: proppage.cpp Source File

Main Page | Class Hierarchy | Class List | File List | Class Members | File Members

# proppage.cpp

Go to the documentation of this file.

    00001 /******************************************************************************
    00002
    00003   Source File:  Property Page.CPP
    00004
    00005   Implements the CPropertyPage class.  See the associated header file for
    00006   details.
    00007
    00008   Copyright (c) 1996 by Microsoft Corporation
    00009
    00010   A Pretty Penny Enterprises Production
    00011
    00012   Change History:
    00013
    00014   11-01-96  a-robkj@microsoft.com- original version
    00015   12-04-96  a-robkj@microsoft.com   retrieve handle to sheet, Create a derived
    00016                                     class for shell extension pages
    00017
    00018 ******************************************************************************/
    00019
    00020 #include    "ICMUI.H"
    00021
    00022 //  CPropertyPage member functions
    00023
    00024 //  Class constructor- basic initializations.  Any remaining PROPSHEETPAGE
    00025 //  initializations are expected to be done by the derived class.
    00026
    00027 CPropertyPage::CPropertyPage() {
    00028     m_psp.dwSize = sizeof m_psp;
    00029     m_psp.pfnDlgProc = (DLGPROC) DialogProc;
    00030     m_psp.lParam = (LPARAM) this;
    00031     m_psp.dwFlags = PSP_DEFAULT;    //  Can be overriden later
    00032         m_hpsp = NULL;
    00033     m_bChanged = FALSE;
    00034 }
    00035
    00036 //  Handle retrieval- I'll admit an addiction to one-liners
    00037
    00038 HPROPSHEETPAGE  CPropertyPage::Handle() {
    00039     return m_hpsp = (m_hpsp ? m_hpsp : CreatePropertySheetPage(&m_psp));
    00040 }
    00041
    00042 //  Dialog Procedure
    00043
    00044 BOOL CALLBACK   CPropertyPage::DialogProc(HWND hwndPage, UINT uMsg, WPARAM wp,
    00045                                           LPARAM lp) {
    00046
    00047     CPropertyPage   *pcppMe =
    00048         (CPropertyPage *) GetWindowLongPtr(hwndPage, DWLP_USER);
    00049
    00050     switch  (uMsg) {
    00051
    00052         case    WM_INITDIALOG:
    00053
    00054             //  In this case, lp points to the PROPSHEETHEADER that created
    00055             //  us.  We look into its lParam member for our this pointer,
    00056             //  and store this in the dialog's private data.  This lets us
    00057             //  use the pointer to get at all of our overridable functions.
    00058
    00059             pcppMe = (CPropertyPage *) ((LPPROPSHEETPAGE) lp) -> lParam;
    00060
    00061             SetWindowLongPtr(hwndPage, DWLP_USER, (LONG_PTR) pcppMe);
    00062             pcppMe -> m_hwnd = hwndPage;
    00063
    00064             //  Now, see if the derived class has any initialization needs
    00065
    00066             return  pcppMe -> OnInit();
    00067
    00068         //  Overridable processing for standard control notifications
    00069
    00070         case    WM_COMMAND:
    00071
    00072             return  pcppMe -> OnCommand(HIWORD(wp), LOWORD(wp), (HWND) lp);
    00073
    00074         case    WM_DESTROY:
    00075
    00076             return  pcppMe -> OnDestroy();
    00077
    00078         case    WM_HELP:
    00079
    00080             return  pcppMe -> OnHelp((LPHELPINFO) lp);
    00081
    00082         case    WM_CONTEXTMENU:
    00083
    00084             return  pcppMe -> OnContextMenu((HWND) wp);
    00085
    00086         //  Overridable processing for common control notifications
    00087
    00088         case    WM_NOTIFY:  {
    00089
    00090             //  If the message is PSM_SETACTIVE, note the property sheet hwnd
    00091
    00092             LPNMHDR pnmh = (LPNMHDR) lp;
    00093
    00094             if  (pnmh -> code == PSN_SETACTIVE)
    00095                 pcppMe -> m_hwndSheet = pnmh -> hwndFrom;
    00096             return  pcppMe -> OnNotify((int) wp, pnmh);
    00097         }
    00098
    00099     }
    00100
    00101     return  FALSE;  //  We didn't handle the message.
    00102 }
    00103
    00104 //  CShellExtensionPage class member methods
    00105
    00106 CShellExtensionPage *CShellExtensionPage::m_pcsepAnchor = NULL;
    00107
    00108 //  We enable reference counting, partially because on NT, the Window handle
    00109 //  sometimes appears invalid even while the dialog is up.  However, we also
    00110 //  keep the chaining mechanism, as this is the only sane way we have of
    00111 //  freeing up the object instances we've created.
    00112
    00113 CShellExtensionPage::CShellExtensionPage() {
    00114
    00115     if  (m_pcsepAnchor) {
    00116
    00117         // If there is a cell other than anchor, update its list.
    00118         if (m_pcsepAnchor -> m_pcsepNext)
    00119             m_pcsepAnchor -> m_pcsepNext -> m_pcsepPrevious = this;
    00120         // Insert this cell right after the anchor.
    00121         m_pcsepPrevious = m_pcsepAnchor;
    00122         m_pcsepNext = m_pcsepAnchor -> m_pcsepNext;
    00123         m_pcsepAnchor -> m_pcsepNext = this;
    00124     }
    00125     else {
    00126
    00127         m_pcsepAnchor = this;
    00128         m_pcsepNext = m_pcsepPrevious = NULL;
    00129     }
    00130
    00131     m_psp.pcRefParent = (UINT *) &CGlobals::ReferenceCounter();
    00132     m_psp.dwFlags |= PSP_USEREFPARENT;
    00133 }
    00134
    00135 CShellExtensionPage::~CShellExtensionPage() {
    00136
    00137     if  (this == m_pcsepAnchor) {
    00138         m_pcsepAnchor = m_pcsepNext;
    00139         if (m_pcsepAnchor) {
    00140             // Anchor never has previous.
    00141             m_pcsepAnchor -> m_pcsepPrevious = NULL;
    00142         }
    00143     }
    00144     else {
    00145         m_pcsepPrevious -> m_pcsepNext = m_pcsepNext;
    00146         // If there is other cell following this, update it.
    00147         if (m_pcsepNext)
    00148             m_pcsepNext -> m_pcsepPrevious = m_pcsepPrevious;
    00149     }
    00150 }
    00151
    00152 //  This little ditty lets us decide when it's safe to unload the DLL- it also
    00153 //  guarantees all class destructors are called as sheets get closed by the
    00154 //  various potential callers.
    00155
    00156 BOOL    CShellExtensionPage::OKToClose() {
    00157
    00158     while   (m_pcsepAnchor) {
    00159         if  (IsWindow(m_pcsepAnchor -> m_hwnd))
    00160             return  FALSE;  //  This page is still alive!
    00161
    00162         delete  m_pcsepAnchor;  //  Page isn't alive, delete it...
    00163     }
    00164
    00165     return  TRUE;   //  No more pages allocated
    00166 }