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.

121 lines
4.5 KiB

  1. /******************************************************************************
  2. Header File: Dialog.H
  3. This defines the C++ class used to encapsulate dialogs. It supports both
  4. modal and modeless styles. This class uses a static method for the dialog
  5. procedure, which automatically caches the "this" pointer for the class in the
  6. DWL_USER field of the window's internal structure for the dialog. This
  7. hand-off is accomplished by setting the lParam parameter on a DialogBoxParam
  8. or CreateDialogParam call to the "this" pointer. It also saves the dialog
  9. handle in a protected member for easy access from derived classes.
  10. To create a C++ class for any specific dialog, derive the class from this
  11. class, providing the dialog ID and instance handle needed to get the dialog
  12. resource in the derived class constructor. Also provide the parent window
  13. handle, if there is one.
  14. The dialog procedure then provides virtual functions for Windows messages
  15. of interest. I've added these as needed. If I were going to a truly
  16. universal class of this sort, I'd just as well go to MFC, and save the
  17. debugging time, so this approach seems reasonable to me.
  18. 12-11-96- to support the hook procedure used in the application UI, I've
  19. added two protected members to allow this support to be in the base class.
  20. If there is a hook procedure, it gets first chance at all messages except
  21. WM_INITDIALOG. If it returns TRUE, we do no further processing, otherwise
  22. we will call the various overrides, if applicable.
  23. For WM_INITDIALOG, we call any overrides first. The derived class' OnInit
  24. procedure can then supply an LPARAM for the hook procedure (e.g., a pointer
  25. to some relevant class member), if desired. We handle the returns from the
  26. calls so that if either an override or the hook procedure states it has
  27. altered the focus, we return the appropriate value. This is pretty standard
  28. handling for dialog hooks, so it should serve well, and it's almost 0 code.
  29. Copyright (c) 1996 by Microsoft Corporation
  30. A Pretty Penny Enterprises Production
  31. Change History:
  32. 11-01-96 a-robkj@microsoft.com- original version
  33. 12-11-96 a-robkj@microsoft.com Added hook procedure support
  34. ******************************************************************************/
  35. #if !defined(DIALOG_STUFF)
  36. #define DIALOG_STUFF
  37. class CDialog {
  38. static INT_PTR CALLBACK DialogProc(HWND hwndPage, UINT uMsg, WPARAM wp,
  39. LPARAM lp);
  40. int m_idMain;
  41. BOOL m_bIsModal;
  42. protected:
  43. // These should be protected (accessible only from derived classes)
  44. // The instance is available for string table or other resource access
  45. HWND m_hwndParent;
  46. HWND m_hwnd;
  47. HINSTANCE m_hiWhere;
  48. DLGPROC m_dpHook; // Dialog Hook Procedure
  49. LPARAM m_lpHook; // LPARAM for Hook WM_INITDIALOG call
  50. public:
  51. // Our constructor requires the resource ID and instance. Not
  52. // unreasonable for this project.
  53. CDialog(HINSTANCE hiWhere, int id, HWND hwndParent = NULL);
  54. CDialog(CDialog& cdOwner, int id);
  55. ~CDialog();
  56. // Modal dialog box operation
  57. LONG DoModal();
  58. // Modeless dialog boxes- create and destroy. We only allow one
  59. // modeless DB per instance of this class.
  60. void Create(); // For modeless boxes
  61. void Destroy();
  62. // This allows us to adjust the position of a dialog in its parent window.
  63. // We use only the left and top members of the given rectangle.
  64. void Adjust(RECT& rc);
  65. // Windows message overrides
  66. // WM_COMMAND- control notifications. We assure you can always get out
  67. // of a modal dialog by pressing any button to make prototyping easy.
  68. virtual BOOL OnCommand(WORD wNotifyCode, WORD wid, HWND hwndCtl) {
  69. // Call EndDialog for all BN_CLICKED messages on Modal boxes
  70. if (m_bIsModal && wNotifyCode == BN_CLICKED)
  71. EndDialog(m_hwnd, wid);
  72. return FALSE;
  73. }
  74. // WM_NOTIFY- common control notifications
  75. virtual BOOL OnNotify(int idCtrl, LPNMHDR pnmh) {
  76. return FALSE;
  77. }
  78. // WM_INITDIALOG- before being called, this and m_hwnd will be valid.
  79. virtual BOOL OnInit() { return TRUE; }
  80. // WM_HELP and WM_CONTEXTMENU- for context-sensitive help.
  81. virtual BOOL OnHelp(LPHELPINFO pHelp) { return TRUE; }
  82. virtual BOOL OnContextMenu(HWND hwnd) { return TRUE; }
  83. };
  84. #endif