home *** CD-ROM | disk | FTP | other *** search
/ PC Administrator / spravce.iso / TaskModule / src / Mydialog.cpp < prev    next >
Encoding:
C/C++ Source or Header  |  2001-08-31  |  3.8 KB  |  119 lines

  1. // MyDialog.cpp: implementation of the CMyDialog class.
  2. //
  3. /*
  4. Copyright 2001 Anish Mistry. All rights reserved.
  5.  
  6. Redistribution and use in source and binary forms, with or without modification,
  7. are permitted provided that the following conditions are met:
  8.  
  9.    1. Redistributions of source code must retain the above copyright notice, 
  10.    this list of conditions and the following disclaimer.
  11.    2. Redistributions in binary form must reproduce the above copyright notice,
  12.    this list of conditions and the following disclaimer in the documentation 
  13.    and/or other materials provided with the distribution.
  14.  
  15. THIS SOFTWARE IS PROVIDED BY ANISH MISTRY ``AS IS'' AND ANY EXPRESS OR IMPLIED 
  16. WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY 
  17. AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS 
  18. OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY,
  19. OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE
  20. GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
  21. CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR
  22. TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
  23. SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  24.  
  25. The views and conclusions contained in the software and documentation are those
  26. of the authors and should not be interpreted as representing official policies,
  27. either expressed or implied, of Anish Mistry or AM Productions.
  28.  
  29. * Variation of the FreeBSD License. http://www.freebsd.org/copyright/freebsd-license.html
  30. */
  31. //////////////////////////////////////////////////////////////////////
  32.  
  33. #include "stdafx.h"
  34. #include "MyDialog.h"
  35.  
  36. //////////////////////////////////////////////////////////////////////
  37. // Construction/Destruction
  38. //////////////////////////////////////////////////////////////////////
  39.  
  40. CMyDialog::CMyDialog()
  41. {// begin CMyDialog #1
  42.     m_hInstance = NULL;
  43.     m_hDlg = NULL;
  44.     // init the ThunkData with the this pointer so that this can be subclassed
  45.     ThunkInit(m_Thunk, this);
  46. }// end CMyDialog #1
  47.  
  48. CMyDialog::~CMyDialog()
  49. {// begin ~CMyDialog
  50.     if(m_hDlg)
  51.         EndDialog(false);
  52.     m_hDlg = NULL;
  53. }// end ~CMyDialog
  54.  
  55. LRESULT CMyDialog::DlgProc(HWND hDlg,UINT nMessage,WPARAM wParam,LPARAM lParam)
  56. {// begin DlgProc
  57.  
  58.     switch (nMessage) 
  59.     {
  60.         case WM_INITDIALOG:
  61.             return OnInitDialog(hDlg);
  62.         case WM_COMMAND:
  63.             return (LRESULT)OnCommand(wParam,lParam);
  64.    }
  65.    return false;
  66.  
  67. }// end DlgProc
  68.  
  69. bool CMyDialog::Init(HINSTANCE hInstance,HWND hParent,unsigned long nTemplateID,bool bDoModal)
  70. {// begin Init
  71.     if(m_hDlg)
  72.         return false;
  73.     // save instance handle
  74.     m_hInstance = hInstance;
  75.     if(bDoModal)
  76.     {// begin create modal dialog box
  77.         if(0 > DialogBox(hInstance,MAKEINTRESOURCE(nTemplateID),hParent,(DLGPROC)(void *)m_Thunk))
  78.             return false;
  79.         return true;
  80.     }// end create modal dialog box
  81.     m_hDlg = CreateDialog(hInstance,MAKEINTRESOURCE(nTemplateID),hParent,(DLGPROC)(void *)m_Thunk);
  82.     ShowWindow(m_hDlg,SW_SHOW);
  83.     if(!m_hDlg)
  84.         return false;
  85.     return true;
  86. }// end Init
  87.  
  88. bool CMyDialog::OnCommand(WPARAM wParam, LPARAM lParam)
  89. {// begin OnCommand
  90.     int nID = LOWORD(wParam); 
  91. //    int nEvent = HIWORD(wParam); 
  92.     // Parse the menu selections:
  93.     switch (nID)
  94.     {// begin parse controls
  95.         case IDOK:
  96.            return EndDialog(nID);
  97.         case IDCANCEL:
  98.            return EndDialog(nID);
  99.         default:
  100.            return true;
  101.     }// end parse controls
  102. }// end OnCommand
  103.  
  104. bool CMyDialog::EndDialog(unsigned long nID)
  105. {// begin EndDialog
  106.     return (bool)::EndDialog(m_hDlg,nID);
  107. }// end EndDialog
  108.  
  109. bool CMyDialog::OnInitDialog(HWND hDlg)
  110. {// begin OnInitDialog
  111.     m_hDlg = hDlg;
  112.     return true;
  113. }// end OnInitDialog
  114.  
  115. HWND CMyDialog::GetSafeHwnd()
  116. {// begin GetSafeHwnd
  117.     return m_hDlg;
  118. }// end GetSafeHwnd
  119.