home *** CD-ROM | disk | FTP | other *** search
/ Windows Graphics Programming / Feng_Yuan_Win32_GDI_DirectX.iso / Samples / Chapt_16 / EMFScope / PROGRESS.CPP < prev    next >
Encoding:
C/C++ Source or Header  |  2000-05-12  |  2.8 KB  |  119 lines

  1. //-----------------------------------------------------------------------------------//
  2. //              Windows Graphics Programming: Win32 GDI and DirectDraw               //
  3. //                             ISBN  0-13-086985-6                                   //
  4. //                                                                                   //
  5. //  Written            by  Yuan, Feng                             www.fengyuan.com   //
  6. //  Copyright (c) 2000 by  Hewlett-Packard Company                www.hp.com         //
  7. //  Published          by  Prentice Hall PTR, Prentice-Hall, Inc. www.phptr.com      //
  8. //                                                                                   //
  9. //  FileName   : progress.cpp                                                         //
  10. //  Description: Progress dialog box                                                 //
  11. //  Version    : 1.00.000, May 31, 2000                                              //
  12. //-----------------------------------------------------------------------------------//
  13.  
  14. #define STRICT
  15. #include <windows.h>
  16. #include <commctrl.h>
  17. #include <assert.h>
  18.  
  19. #include "Winpp.h"
  20. #include "Progress.h"
  21.  
  22. void KProgress::SetRange(unsigned low, unsigned up)
  23. {
  24.     pos            = low;
  25.     reportedpos = low;
  26.     total        = up - low + 1;
  27.  
  28.     SendDlgItemMessage(m_hWnd, nIdc, PBM_SETRANGE,
  29.             low, MAKELPARAM(0, up));
  30.  
  31.     SendDlgItemMessage(m_hWnd, nIdc, PBM_SETPOS, low, 0);
  32. }
  33.  
  34.  
  35. void KProgress::Move(void)
  36. {
  37.     pos ++;
  38.  
  39.     char temp[32];
  40.     wsprintf(temp, "%d", pos);
  41.     SetDlgItemText(m_hWnd, nIdcNumber, temp);
  42.  
  43.     if ( ((pos-reportedpos)>total/32) || (pos>=(total-1)) )
  44.     {
  45.         reportedpos = pos;
  46.  
  47.     //    char temp[32];
  48.     //    wsprintf(temp, "%d", pos);
  49.     //    SetDlgItemText(m_hWnd, nIdcNumber, temp);
  50.  
  51.         SendDlgItemMessage(m_hWnd, nIdc, PBM_SETPOS, pos, 0);
  52.     }
  53. }
  54.  
  55.  
  56. BOOL KProgress::DlgProc(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
  57. {
  58.     switch (uMsg)
  59.     {
  60.         case WM_INITDIALOG:
  61.             m_hWnd = hWnd;
  62.             ShowWindow(hWnd, SW_NORMAL);
  63.             SetFocus(hWnd);
  64.             UpdateWindow(hWnd);
  65.             return TRUE;
  66.  
  67.         case WM_COMMAND:
  68.             if (LOWORD(wParam)==IDCANCEL)
  69.             {
  70.                 SetAbort();
  71.                 return TRUE;
  72.             }
  73.             break;
  74.     }
  75.  
  76.     return FALSE;
  77. }
  78.  
  79.  
  80. void KProgress::Create(HINSTANCE hInst, HWND hWnd, int idd, int idc, int idcnumber, int delay)
  81. {
  82.     bAbort     = FALSE;
  83.     nDelay     = delay;
  84.     nIdc       = idc;
  85.     nIdcNumber = idcnumber;
  86.  
  87.     Createdialog(hInst, idd, hWnd);
  88. }
  89.  
  90.  
  91. void KProgress::Destroy(void)
  92. {
  93.     if (m_hWnd)
  94.     {
  95.         DestroyWindow(m_hWnd);
  96.         m_hWnd = NULL;
  97.     }
  98. }
  99.  
  100.  
  101. BOOL KProgress::AbortDraw(void)
  102. {
  103.     MSG msg;
  104.  
  105.     if (!m_hWnd)
  106.         return FALSE;
  107.  
  108.     while ( ! bAbort && PeekMessage(&msg, m_hWnd, 0, 0, PM_REMOVE) )
  109.     {
  110.         if ( !IsDialogMessage(m_hWnd, &msg) )
  111.         {
  112.             TranslateMessage(&msg);
  113.             DispatchMessage(&msg);
  114.         }
  115.     }
  116.  
  117.     return bAbort;
  118. }
  119.