Source code of Windows XP (NT5)
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

176 lines
4.6 KiB

  1. // File: Progressbar.h
  2. #ifndef _PROGRESSBAR_H_
  3. #define _PROGRESSBAR_H_
  4. #include "GenWindow.h"
  5. #include "GenContainers.h"
  6. // A progress window class. This uses an outer and inner bitmap to show the progress
  7. class // DECLSPEC_UUID("")
  8. CProgressBar : public CGenWindow
  9. {
  10. public:
  11. // Default constructor; inits a few intrinsics
  12. CProgressBar();
  13. // Create the toolbar window; this object now owns the bitmaps passed in
  14. BOOL Create(
  15. HBITMAP hbOuter, // The outside (static) part of the progress bar
  16. HBITMAP hbInner, // The inside part of the progress bar that jumps around
  17. HWND hWndParent // The parent of the toolbar window
  18. );
  19. #if FALSE
  20. HRESULT STDMETHODCALLTYPE QueryInterface(REFGUID riid, LPVOID *ppv)
  21. {
  22. if (__uuidof(CProgressBar) == riid)
  23. {
  24. *ppv = this;
  25. AddRef();
  26. return(S_OK);
  27. }
  28. return(CGenWindow::QueryInterface(riid, ppv));
  29. }
  30. #endif // FALSE
  31. virtual void GetDesiredSize(SIZE *ppt);
  32. // Change the max value displayed by this progress bar
  33. void SetMaxValue(UINT maxVal);
  34. // Return the max value displayed by this progress bar
  35. UINT GetMaxValue() { return(m_maxVal); }
  36. // Change the current value displayed by this progress bar
  37. void SetCurrentValue(UINT curVal);
  38. // Return the current value displayed by this progress bar
  39. UINT GetCurrentValue() { return(m_curVal); }
  40. protected:
  41. virtual ~CProgressBar();
  42. // Forward WM_COMMAND messages to the parent window
  43. virtual LRESULT ProcessMessage(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam);
  44. private:
  45. enum BitmapParts
  46. {
  47. Frame, // The bitmap that displays the control when at 0%
  48. Bar, // The bitmap that gets blasted onto the outer bitmap up to the desired percentage
  49. NumBitmaps
  50. } ;
  51. // The bitmaps that make up the progress bar
  52. HBITMAP m_hbs[NumBitmaps];
  53. // The max progress value
  54. UINT m_maxVal;
  55. // The current progress value
  56. UINT m_curVal;
  57. // Get/set the outer bitmap
  58. void SetFrame(HBITMAP hbFrame) { m_hbs[Frame] = hbFrame; }
  59. HBITMAP GetFrame() { return(m_hbs[Frame]); }
  60. // Get/set the inner bitmap
  61. void SetBar(HBITMAP hbBar) { m_hbs[Bar] = hbBar; }
  62. HBITMAP GetBar() { return(m_hbs[Bar]); }
  63. // Specialized painting function
  64. void OnPaint(HWND hwnd);
  65. } ;
  66. class CProgressTrackbar;
  67. interface IScrollChange : IUnknown
  68. {
  69. virtual void OnScroll(CProgressTrackbar *pTrackbar, UINT code, int pos) = 0;
  70. } ;
  71. // A progress window class. This uses an outer and inner bitmap to show the progress
  72. class // DECLSPEC_UUID("")
  73. CProgressTrackbar : public CFillWindow
  74. {
  75. public:
  76. // Default constructor; inits a few intrinsics
  77. CProgressTrackbar();
  78. // Create the toolbar window; this object now owns the bitmaps passed in
  79. BOOL Create(
  80. HWND hWndParent, // The parent of the toolbar window
  81. INT_PTR nId=0, // The ID of the control
  82. IScrollChange *pNotify=NULL // Object to notify of changes
  83. );
  84. #if FALSE
  85. HRESULT STDMETHODCALLTYPE QueryInterface(REFGUID riid, LPVOID *ppv)
  86. {
  87. if (__uuidof(CProgressTrackbar) == riid)
  88. {
  89. *ppv = this;
  90. AddRef();
  91. return(S_OK);
  92. }
  93. return(CGenWindow::QueryInterface(riid, ppv));
  94. }
  95. #endif // FALSE
  96. virtual void GetDesiredSize(SIZE *ppt);
  97. // Sets the desired size for this control
  98. void SetDesiredSize(SIZE *psize);
  99. // Change the max value displayed by this progress bar
  100. void SetMaxValue(UINT maxVal);
  101. // Return the max value displayed by this progress bar
  102. UINT GetMaxValue();
  103. // Change the current position of the thumb
  104. void SetTrackValue(UINT curVal);
  105. // Return the current position of the thumb
  106. UINT GetTrackValue();
  107. // Change the current value displayed by the channel
  108. void SetProgressValue(UINT curVal);
  109. // Return the current value displayed by the channel
  110. UINT GetProgressValue();
  111. protected:
  112. virtual ~CProgressTrackbar();
  113. // Forward WM_COMMAND messages to the parent window
  114. virtual LRESULT ProcessMessage(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam);
  115. void SchedulePaint()
  116. {
  117. // HACK: SETRANGEMAX is the only way to force the slider to update itself...
  118. SendMessage(GetChild(), TBM_SETRANGEMAX, TRUE, GetMaxValue());
  119. }
  120. private:
  121. // The desired size for the control; defaults to (170,23)
  122. SIZE m_desSize;
  123. // The current channel value
  124. UINT m_nValChannel;
  125. // The object ot notify of changes
  126. IScrollChange *m_pNotify;
  127. // Notify handler for custom draw
  128. LRESULT OnNotify(HWND hwnd, int id, NMHDR *pHdr);
  129. // Send scroll messages to the parent
  130. void OnScroll(HWND hwnd, HWND hwndCtl, UINT code, int pos);
  131. // Set the correct background color
  132. HBRUSH OnCtlColor(HWND hwnd, HDC hdc, HWND hwndChild, int type);
  133. // Free the listener
  134. void OnNCDestroy(HWND hwnd);
  135. // Paint the parts of the slider
  136. LRESULT PaintChannel(LPNMCUSTOMDRAW pCustomDraw);
  137. LRESULT PaintThumb(LPNMCUSTOMDRAW pCustomDraw);
  138. } ;
  139. #endif // _PROGRESSBAR_H_