test: dialog.h Source File

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

# dialog.h

Go to the documentation of this file.

    00001 /******************************************************************************
    00002
    00003   Header File:  Dialog.H
    00004
    00005   This defines the C++ class used to encapsulate dialogs.  It supports both
    00006   modal and modeless styles.  This class uses a static method for the dialog
    00007   procedure, which automatically caches the "this" pointer for the class in the
    00008   DWL_USER field of the window's internal structure for the dialog.  This
    00009   hand-off is accomplished by setting the lParam parameter on a DialogBoxParam
    00010   or CreateDialogParam call to the "this" pointer.  It also saves the dialog
    00011   handle in a protected member for easy access from derived classes.
    00012
    00013   To create a C++ class for any specific dialog, derive the class from this
    00014   class, providing the dialog ID and instance handle needed to get the dialog
    00015   resource in the derived class constructor.  Also provide the parent window
    00016   handle, if there is one.
    00017
    00018   The dialog procedure then provides virtual functions for Windows messages
    00019   of interest.  I've added these as needed.  If I were going to a truly
    00020   universal class of this sort, I'd just as well go to MFC, and save the
    00021   debugging time, so this approach seems reasonable to me.
    00022
    00023   12-11-96- to support the hook procedure used in the application UI, I've
    00024   added two protected members to allow this support to be in the base class.
    00025   If there is a hook procedure, it gets first chance at all messages except
    00026   WM_INITDIALOG.  If it returns TRUE, we do no further processing, otherwise
    00027   we will call the various overrides, if applicable.
    00028
    00029   For WM_INITDIALOG, we call any overrides first.  The derived class' OnInit
    00030   procedure can then supply an LPARAM for the hook procedure (e.g., a pointer
    00031   to some relevant class member), if desired.  We handle the returns from the
    00032   calls so that if either an override or the hook procedure states it has
    00033   altered the focus, we return the appropriate value.  This is pretty standard
    00034   handling for dialog hooks, so it should serve well, and it's almost 0 code.
    00035
    00036   Copyright (c) 1996 by Microsoft Corporation
    00037
    00038   A Pretty Penny Enterprises Production
    00039
    00040   Change History:
    00041
    00042   11-01-96  a-robkj@microsoft.com- original version
    00043   12-11-96  a-robkj@microsoft.com   Added hook procedure support
    00044
    00045 ******************************************************************************/
    00046
    00047 #if !defined(DIALOG_STUFF)
    00048
    00049 #define DIALOG_STUFF
    00050
    00051 class CDialog {
    00052
    00053     static INT_PTR CALLBACK    DialogProc(HWND hwndPage, UINT uMsg, WPARAM wp,
    00054                                        LPARAM lp);
    00055     int         m_idMain;
    00056     BOOL        m_bIsModal;
    00057
    00058 protected:
    00059
    00060     //  These should be protected (accessible only from derived classes)
    00061     //  The instance is available for string table or other resource access
    00062
    00063     HWND        m_hwndParent;
    00064     HWND        m_hwnd;
    00065     HINSTANCE   m_hiWhere;
    00066     DLGPROC     m_dpHook;       //  Dialog Hook Procedure
    00067     LPARAM      m_lpHook;       //  LPARAM for Hook WM_INITDIALOG call
    00068
    00069 public:
    00070
    00071     //  Our constructor requires the resource ID and instance.  Not
    00072     //  unreasonable for this project.
    00073
    00074     CDialog(HINSTANCE hiWhere, int id, HWND hwndParent = NULL);
    00075     CDialog(CDialog& cdOwner, int id);
    00076     ~CDialog();
    00077
    00078     //  Modal dialog box operation
    00079
    00080     LONG    DoModal();
    00081
    00082     //  Modeless dialog boxes- create and destroy.  We only allow one
    00083     //  modeless DB per instance of this class.
    00084
    00085     void    Create();   //  For modeless boxes
    00086     void    Destroy();
    00087
    00088     //  This allows us to adjust the position of a dialog in its parent window.
    00089     //  We use only the left and top members of the given rectangle.
    00090
    00091     void    Adjust(RECT& rc);
    00092
    00093     //  Windows message overrides
    00094
    00095     //  WM_COMMAND- control notifications.  We assure you can always get out
    00096     //  of a modal dialog by pressing any button to make prototyping easy.
    00097
    00098     virtual BOOL OnCommand(WORD wNotifyCode, WORD wid, HWND hwndCtl) {
    00099         //  Call EndDialog for all BN_CLICKED messages on Modal boxes
    00100         if  (m_bIsModal && wNotifyCode == BN_CLICKED)
    00101             EndDialog(m_hwnd, wid);
    00102         return  FALSE;
    00103     }
    00104
    00105     //  WM_NOTIFY- common control notifications
    00106
    00107     virtual BOOL    OnNotify(int idCtrl, LPNMHDR pnmh) {
    00108         return  FALSE;
    00109     }
    00110
    00111     //  WM_INITDIALOG- before being called, this and m_hwnd will be valid.
    00112
    00113     virtual BOOL    OnInit() { return TRUE; }
    00114
    00115     //  WM_HELP and WM_CONTEXTMENU- for context-sensitive help.
    00116
    00117     virtual BOOL    OnHelp(LPHELPINFO pHelp) { return TRUE; }
    00118     virtual BOOL    OnContextMenu(HWND hwnd) { return TRUE; }
    00119 };
    00120
    00121 #endif