win_status.cc 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475
  1. /********************************************************************** <BR>
  2. This file is part of Crack dot Com's free source code release of
  3. Golgotha. <a href="http://www.crack.com/golgotha_release"> <BR> for
  4. information about compiling & licensing issues visit this URL</a>
  5. <PRE> If that doesn't help, contact Jonathan Clark at
  6. golgotha_source@usa.net (Subject should have "GOLG" in it)
  7. ***********************************************************************/
  8. #include "status/status.hh"
  9. enum {MAX_UPDATES=100};
  10. class win32_status_class
  11. {
  12. public:
  13. HWND hwndPB; // handle of progress bar
  14. int last_p;
  15. virtual i4_bool update(float percent)
  16. {
  17. int p=percent*MAX_UPDATES;
  18. while (last_p!=p)
  19. {
  20. last_p++;
  21. SendMessage(hwndPB, PBM_STEPIT, 0, 0);
  22. }
  23. }
  24. win32_status_class(HWND hwndPB) : hwndPB(hwndPB)
  25. {
  26. last_p=0;
  27. }
  28. virtual ~i4_status_class()
  29. {
  30. DestroyWindow(hwndPB);
  31. }
  32. };
  33. // this is operating system dependant
  34. i4_status_class *i4_create_status(const i4_const_str &description)
  35. {
  36. RECT rcClient; // client area of parent window
  37. int cyVScroll; // height of scroll bar arrow
  38. HWND hwndPB; // handle of progress bar
  39. HANDLE hFile; // handle of file
  40. DWORD cb; // size of file and count of bytes read
  41. LPCH pch; // address of data read from file
  42. LPCH pchTmp; // temporary pointer
  43. // Ensure that the common control DLL is loaded and create a
  44. // progress bar along the bottom of the client area of the
  45. // parent window. Base the height of the progress bar on
  46. // the height of a scroll bar arrow.
  47. InitCommonControls();
  48. hwndPB = CreateWindowEx(0, PROGRESS_CLASS, (LPSTR) NULL,
  49. WS_BORDER | WS_VISIBLE, CW_USEDEFAULT, CW_USEDEFAULT,
  50. 320, 20,
  51. 0, (HMENU) 0, i4_win32_instance, NULL);
  52. // Set the range and increment of the progress bar.
  53. SendMessage(hwndPB, PBM_SETRANGE, 0, MAKELPARAM(0, MAX_UPDATES));
  54. SendMessage(hwndPB, PBM_SETSTEP, (WPARAM) 1, 0);
  55. return new win32_status_class(hwndPB);
  56. }