home *** CD-ROM | disk | FTP | other *** search
/ Tricks of the Windows Gam…ming Gurus (2nd Edition) / Disc2.iso / msdn_vcb / samples / vc98 / mfc / general / dlgcbr32 / modeless.cpp < prev    next >
Encoding:
C/C++ Source or Header  |  1998-03-27  |  2.6 KB  |  94 lines

  1. // Modeless.cpp : implementation file
  2. //
  3.  
  4. // This is a part of the Microsoft Foundation Classes C++ library.
  5. // Copyright (C) 1992-1998 Microsoft Corporation
  6. // All rights reserved.
  7. //
  8. // This source code is only intended as a supplement to the
  9. // Microsoft Foundation Classes Reference and related
  10. // electronic documentation provided with the library.
  11. // See these sources for detailed information regarding the
  12. // Microsoft Foundation Classes product.
  13.  
  14. /*****************************************************************************
  15.   Purpose:
  16.     Implements CModelessDialog, a reusable class for creating modeless
  17.     dialogs.
  18.  
  19.   Functions:
  20.     CModelessDialog::CModelessDialog()      -- constructor
  21.     CModelessDialog::~CModelessDialog()     -- destructor
  22.     CModelessDialog::OnCancel()             -- WM_COMMAND IDCANCEL handler
  23.     CModelessDialog::OnOK()                 -- WM_COMMAND IDOK handler
  24.     CModelessDialog::PostNcDestroy()        -- called after WM_NCDESTROY
  25.  
  26.   Development Team:
  27.     Mary Kirtland
  28.   Ported to 32-bit by:
  29.     Mike Hedley
  30.   Created by Microsoft Product Support Services, Premier ISV Support
  31.   Copyright (c) 1998 Microsoft Corporation. All rights reserved.
  32. \****************************************************************************/
  33.  
  34. #include "stdafx.h"
  35. #include "modeless.h"
  36.  
  37. #ifdef _DEBUG
  38. #define new DEBUG_NEW
  39. #undef THIS_FILE
  40. static char THIS_FILE[] = __FILE__;
  41. #endif
  42.  
  43. /////////////////////////////////////////////////////////////////////////////
  44. // CModelessDialog
  45.  
  46. IMPLEMENT_DYNAMIC(CModelessDialog, CDialog)
  47.  
  48. BEGIN_MESSAGE_MAP(CModelessDialog, CDialog)
  49.     //{{AFX_MSG_MAP(CModelessDialog)
  50.     //}}AFX_MSG_MAP
  51. END_MESSAGE_MAP()
  52.  
  53. /////////////////////////////////////////////////////////////////////////////
  54. // CModelessDialog Construction/Destruction
  55.  
  56. CModelessDialog::CModelessDialog()
  57. {
  58. }
  59.  
  60. CModelessDialog::~CModelessDialog()
  61. {
  62. }
  63.  
  64. void CModelessDialog::PostNcDestroy()
  65. {
  66.     delete this;
  67. }
  68.  
  69. /////////////////////////////////////////////////////////////////////////////
  70. // CModelessDialog::OnCancel
  71. //      Modeless dialogs must not call EndDialog(), as CDialog::OnCancel()
  72. //      does.  All we need to do is destroy the window.
  73.  
  74. void CModelessDialog::OnCancel()
  75. {
  76.     DestroyWindow();
  77. }
  78.  
  79. /////////////////////////////////////////////////////////////////////////////
  80. // CModelessDialog::OnOK
  81. //      Modeless dialogs must not call EndDialog(), as CDialog::OnOK() does
  82. //      We retrieve data from the controls using DDX, then destroy the
  83. //      window.
  84.  
  85. void CModelessDialog::OnOK()
  86. {
  87.     if (!UpdateData(TRUE))
  88.     {
  89.         TRACE0("UpdateData failed -- modeless dialog terminate\n");
  90.         return;
  91.     }
  92.     DestroyWindow();
  93. }
  94.