home *** CD-ROM | disk | FTP | other *** search
/ DP Tool Club 19 / CD_ASCQ_19_010295.iso / vrac / dlgcbr.zip / MODELESS.CPP < prev    next >
C/C++ Source or Header  |  1994-06-30  |  3KB  |  110 lines

  1. /*****************************************************************************
  2.   MODELESS.CPP
  3.  
  4.   Purpose:  
  5.       Implements CModelessDialog, a reusable class for creating modeless
  6.       dialogs.
  7.  
  8.   Functions:
  9.       CModelessDialog::CModelessDialog()        -- constructor
  10.       CModelessDialog::~CModelessDialog()        -- destructor
  11.       CModelessDialog::Create()                -- creates dialog window
  12.       CModelessDialog::OnCancel()                -- WM_COMMAND IDCANCEL handler
  13.       CModelessDialog::OnOK()                    -- WM_COMMAND IDOK handler
  14.       CModelessDialog::PostNcDestroy()        -- called after WM_NCDESTROY
  15.  
  16.   Development Team:
  17.       Mary Kirtland
  18.  
  19.   Written by Microsoft Product Support Services, Premier ISV Support
  20.   Copyright (c) 1994 Microsoft Corporation. All rights reserved.
  21. \****************************************************************************/
  22.  
  23. #include "stdafx.h"
  24. #include "modeless.h"
  25.  
  26. #ifdef _DEBUG
  27.     #undef THIS_FILE
  28.     static char BASED_CODE THIS_FILE[] = __FILE__;
  29. #endif
  30.  
  31. /////////////////////////////////////////////////////////////////////////////
  32. // CModelessDialog 
  33.  
  34. IMPLEMENT_DYNAMIC(CModelessDialog, CDialog)
  35.  
  36. BEGIN_MESSAGE_MAP(CModelessDialog, CDialog)
  37.     //{{AFX_MSG_MAP(CModelessDialog)
  38.     //}}AFX_MSG_MAP
  39. END_MESSAGE_MAP()
  40.  
  41. /////////////////////////////////////////////////////////////////////////////
  42. // CModelessDialog Construction/Destruction
  43.  
  44. CModelessDialog::CModelessDialog() 
  45. {
  46. }
  47.         
  48. CModelessDialog::~CModelessDialog()
  49. {
  50. }
  51.   
  52. void CModelessDialog::PostNcDestroy()
  53. {
  54.     delete this;
  55. }
  56.  
  57. /////////////////////////////////////////////////////////////////////////////
  58. // CModelessDialog::Create
  59. //        CDialog::Create is a protected function, so we derive our own
  60. //        public function to allow creation of CModelessDialog objects
  61. //        without deriving a new class.
  62.         
  63. BOOL CModelessDialog::Create(UINT nIDTemplate, CWnd* pParentWnd) 
  64. {  
  65.     BOOL bSuccess = CDialog::Create(nIDTemplate, pParentWnd);
  66.     if (!bSuccess)
  67.         TRACE("Unable to create dialog using template ID %d\n", nIDTemplate);
  68.     return bSuccess;
  69. }
  70.  
  71. BOOL CModelessDialog::Create(LPCSTR lpszTemplateName, CWnd* pParentWnd) 
  72. {
  73.     ASSERT(lpszTemplateName != NULL);
  74.     
  75.     BOOL bSuccess = CDialog::Create(lpszTemplateName, pParentWnd);
  76.     if (!bSuccess)
  77.         TRACE("Unable to create dialog using template %s\n", lpszTemplateName);
  78.     return bSuccess;
  79. }       
  80.  
  81. /////////////////////////////////////////////////////////////////////////////
  82. // CModelessDialog::OnCancel
  83. //        Modeless dialogs must not call EndDialog(), as CDialog::OnCancel()
  84. //        does.  All we need to do is destroy the window.
  85.  
  86. void CModelessDialog::OnCancel() 
  87. {
  88.     DestroyWindow();
  89. }
  90.  
  91. /////////////////////////////////////////////////////////////////////////////
  92. // CModelessDialog::OnOK
  93. //        Modeless dialogs must not call EndDialog(), as CDialog::OnOK() does
  94. //        We retrieve data from the controls using DDX, then destroy the 
  95. //        window.
  96.  
  97. void CModelessDialog::OnOK() 
  98. {
  99.     if (!UpdateData(TRUE)) 
  100.     {
  101.         TRACE0("UpdateData failed -- modeless dialog terminate\n");
  102.         return;
  103.     }
  104.     DestroyWindow();
  105. }
  106.  
  107.  
  108.  
  109.  
  110.