home *** CD-ROM | disk | FTP | other *** search
/ Tricks of the Windows Gam…ming Gurus (2nd Edition) / Disc2.iso / msdn_vcb / samples / vc98 / sdk / dbmsg / oledb / tablecopy / progress.cpp < prev    next >
Encoding:
C/C++ Source or Header  |  1998-03-12  |  4.4 KB  |  193 lines

  1. //-----------------------------------------------------------------------------
  2. // Microsoft OLE DB TABLECOPY Sample
  3. // Copyright (C) 1995-1998 Microsoft Corporation
  4. //
  5. // @doc
  6. //
  7. // @module PROGRESS.CPP
  8. //
  9. //-----------------------------------------------------------------------------
  10.  
  11. ////////////////////////////////////////////////////////////////////
  12. // Includes
  13. //
  14. ////////////////////////////////////////////////////////////////////
  15. #include "progress.h"
  16. #include "common.h"
  17.  
  18.  
  19.  
  20. ////////////////////////////////////////////////////////////////////
  21. // CProgress::CProgress
  22. //
  23. ////////////////////////////////////////////////////////////////////
  24. CProgress::CProgress(HWND hWnd, HINSTANCE hInst)
  25.     : CDialogBase(hWnd, hInst)
  26. {
  27. }
  28.  
  29. ////////////////////////////////////////////////////////////////////
  30. // CProgress::~CProgress
  31. //
  32. ////////////////////////////////////////////////////////////////////
  33. CProgress::~CProgress()
  34. {
  35.     Destroy();
  36. }
  37.  
  38.  
  39. ////////////////////////////////////////////////////////////////////
  40. // BOOL WINAPI CProgress::DlgProc
  41. //
  42. ////////////////////////////////////////////////////////////////////
  43. BOOL WINAPI CProgress::DlgProc(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam)
  44. {
  45.     switch(msg) 
  46.     {
  47.         case WM_INITDIALOG:
  48.         {
  49.             //Save the this pointer, since this is a static method
  50.             Busy();
  51.             CProgress* pThis = (CProgress*)lParam;
  52.             SetWindowLong(hWnd, GWL_USERDATA, (LONG)pThis);
  53.  
  54.             //On INIT we know we have a valid hWnd to store
  55.             pThis->m_hWnd = hWnd;
  56.  
  57.             CenterDialog(hWnd);
  58.             return TRUE;
  59.         }
  60.         break;
  61.  
  62.         case WM_COMMAND:
  63.         {
  64.             // All buttons are handled the same way
  65.             //Restore instance pointer, since this is a static function
  66.             CProgress* pThis = (CProgress*)GetWindowLong(hWnd, GWL_USERDATA);
  67.  
  68.             switch(GET_WM_COMMAND_ID(wParam, lParam)) 
  69.             {
  70.                 case IDCANCEL:
  71.                     Busy();
  72.                     pThis->m_fCancel = TRUE;
  73.                     return TRUE;
  74.             }
  75.             return FALSE;
  76.         }
  77.         break;
  78.  
  79.         default:
  80.             return FALSE;
  81.     }
  82. }
  83.  
  84.  
  85. ////////////////////////////////////////////////////////////////////
  86. // ULONG CProgress::Display
  87. //
  88. ////////////////////////////////////////////////////////////////////
  89. ULONG CProgress::Display()
  90. {
  91.     m_fCancel = FALSE;
  92.  
  93.     //Create a ModeLess Dialog Box
  94.     m_hWnd = CreateDialogParam(m_hInst, MAKEINTRESOURCE(IDD_PROGRESS), NULL, DlgProc, (LPARAM)this);
  95.     return TRUE;
  96. }
  97.  
  98.  
  99. ////////////////////////////////////////////////////////////////////
  100. // ULONG CProgress::Destroy
  101. //
  102. ////////////////////////////////////////////////////////////////////
  103. ULONG CProgress::Destroy()
  104. {
  105.     if(m_hWnd) 
  106.     {
  107.         DestroyWindow(m_hWnd);
  108.         m_hWnd = NULL;
  109.     }
  110.     return TRUE;
  111. }
  112.  
  113.  
  114. ////////////////////////////////////////////////////////////////////
  115. // BOOL CProgress::SetHeading
  116. //
  117. ////////////////////////////////////////////////////////////////////
  118. BOOL CProgress::SetHeading(WCHAR* pwszText)
  119. {
  120.     ASSERT(pwszText);
  121.  
  122.     wSetDlgItemText(m_hWnd, IDT_STATUS, pwszText);
  123.     return TRUE;
  124. }
  125.  
  126.  
  127. ////////////////////////////////////////////////////////////////////
  128. // BOOL CProgress::SetText
  129. //
  130. ////////////////////////////////////////////////////////////////////
  131. BOOL CProgress::SetText(WCHAR* pwszText)
  132. {
  133.     ASSERT(pwszText);
  134.     
  135.     wSetDlgItemText(m_hWnd, IDT_STAT_INFO, pwszText);
  136.     return TRUE;
  137. }
  138.  
  139.  
  140. ////////////////////////////////////////////////////////////////////
  141. // BOOL CProgress::Cancel
  142. //
  143. ////////////////////////////////////////////////////////////////////
  144. BOOL CProgress::Cancel()
  145. {
  146.     MSG        msg;
  147.  
  148.     //Must have an existing window to cancel
  149.     if(m_hWnd==NULL)
  150.         return FALSE;
  151.  
  152.     while(PeekMessage(&msg, m_hWnd, 0, 0, PM_REMOVE)) 
  153.     {
  154.         if(!IsDialogMessage(m_hWnd, &msg)) 
  155.         {
  156.             TranslateMessage(&msg);
  157.             DispatchMessage(&msg);
  158.         }
  159.     }
  160.  
  161.     return m_fCancel;
  162. }
  163.  
  164.  
  165. ////////////////////////////////////////////////////////////////////
  166. // BOOL CProgress::Update
  167. //
  168. ////////////////////////////////////////////////////////////////////
  169. BOOL CProgress::Update(WCHAR* pwszText)
  170. {
  171.     ASSERT(pwszText);
  172.  
  173.     //Update the progress text
  174.     SetText(pwszText);
  175.  
  176.     // Now check for a cancel from the user, by checking
  177.     // the messages from the user
  178.     if(Cancel()) 
  179.     {
  180.         if(IDYES == wMessageBox(m_hWnd, MB_TASKMODAL | MB_ICONEXCLAMATION | MB_YESNO, wsz_CANCEL, wsz_CANCEL_OP))
  181.         {
  182.             //Indicate the users wishes to stop 
  183.             return FALSE;
  184.         }
  185.         else 
  186.         {
  187.             m_fCancel = FALSE;
  188.         }    
  189.     }
  190.  
  191.     //Indicate the user wishes to continue
  192.     return TRUE;
  193. }