WTL Controls
Back to the WTL Controls Home Page.
StatusBarPlus.cpp
Go to the documentation of this file.
1 #include "stdafx.h"
2 //--------------------------------------------------------------------------------------
3 //--------------------------------------------------------------------------------------
4 //
5 //
6 // WTL Control Library
7 // by
8 // Bright Ideas Software®
9 // Copyright © 2018 by Bright Ideas Software.
10 //
11 //
12 //
13 //--------------------------------------------------------------------------------------
14 //--------------------------------------------------------------------------------------
15 
16 
17 namespace BIS_WTL_CONTROLS
18 {
19 
20 //----------------------------------------------------------------------------------------------
22  {
25  }
26  //----------------------------------------------------------------------------------------------
28  {
29 
30  }
31  //----------------------------------------------------------------------------------------------
47  BOOL CStatusBarPlus::SubclassStatusBar(HWND hStatusBar, UINT ProgressBarCtlID, UINT style_flags)
48  {
49  static int nPanes[] =
50  {
51  ID_DEFAULT_PANE, // ID_DEFAULT_PANE is #defined as 0
52  1,
53  2
54  };
55 
56 
57  BOOL result = SubclassWindow(hStatusBar);
58 
59  if (result == FALSE)
60  return(result);
61 
62  //
63  // Add panes to the status bar.
64  //
65  SetPanes(nPanes, 3, false);
66 
67 
68  //
69  // Place a progress control in the rightmost pane.
70  //
71  CRect rect;
72  GetPaneRect(m_iProgressBarPane, &rect);
73 
74  UINT window_style = WS_CHILD | WS_VISIBLE ;
75  window_style |= style_flags;
76 
77  m_ProgressBar.Create(m_hWnd, rect, NULL, window_style, 0, ProgressBarCtlID);
78 
79  result = m_ProgressBar.ShowWindow(FALSE);
80 
81 
82  return (result);
83  }
84  //----------------------------------------------------------------------------------------------
93  {
94  m_ProgressBar.DestroyWindow();
95  UnsubclassWindow();
96  }
97  //----------------------------------------------------------------------------------------------
105  CProgressBarCtrl& CStatusBarPlus::ProgressBar()
106  {
107  return(m_ProgressBar);
108  }
109  //----------------------------------------------------------------------------------------------
127  BOOL CStatusBarPlus::SetPaneStyle(int pane_index, UINT flags)
128  {
129 
130  std::basic_string<TCHAR> text = _T("");
131 
132  int l = GetTextLength(pane_index, NULL);
133 
134  if (l > 0)
135  {
136 
137  l++;
138 
139  TCHAR* chars = new TCHAR[l];
140 
141  for (int i = 0; i < l; i++)
142  chars[i] = TCHAR('\0');
143 
144  GetText(pane_index, chars, NULL);
145  text = chars;
146 
147  delete[] chars;
148 
149  }
150 
151  BOOL result = SetText(pane_index, text.c_str(), flags);
152 
153  return(result);
154  }
155  //----------------------------------------------------------------------------------------------
156  //----------------------------------------------------------------------------------------------
169  {
170  m_iProgressBarMargin = margin;
171  }
172  //----------------------------------------------------------------------------------------------
182  {
183  return(m_iProgressBarMargin);
184  }
185  //----------------------------------------------------------------------------------------------
186  //----------------------------------------------------------------------------------------------
198  {
199  m_iProgressBarPane = pane_index;
200  }
201  //----------------------------------------------------------------------------------------------
211  {
212  return(m_iProgressBarPane);
213  }
214  //----------------------------------------------------------------------------------------------
215  //----------------------------------------------------------------------------------------------
216  //
217  // Message Handlers
218  //
219  //----------------------------------------------------------------------------------------------
220  //----------------------------------------------------------------------------------------------
221  LRESULT CStatusBarPlus::OnSize(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled)
222  {
223 
224 
225  LRESULT res = CMultiPaneStatusBarCtrl::OnSize(uMsg, wParam, lParam, bHandled);
226 
227  CRect rect;
228  GetPaneRect(m_iProgressBarPane, &rect);
229 
230  if (m_ProgressBar.IsWindow())
231  m_ProgressBar.SetWindowPos(m_hWnd, rect.left + m_iProgressBarMargin, rect.top + m_iProgressBarMargin,
232  rect.Width() - (2 * m_iProgressBarMargin), rect.Height() - (2 * m_iProgressBarMargin), SWP_NOZORDER);
233 
234 
235 
236  return(res);
237  }
238  //----------------------------------------------------------------------------------------------
239  //----------------------------------------------------------------------------------------------
240 }
int GetProgressBarPane() const
Default : 2.
void SetProgressBarPane(int pane_index)
Select the pane to contain the embedded CProgressBarCtrl.
int GetTextLength(CString str, HFONT font)
Measure the length, in pixels, of a string using a given font.
virtual BOOL SubclassStatusBar(HWND hFrameWnd, UINT ProgressBarCtlID, UINT style_flags=0)
SubclassStatusBar subclasses a pre-existing status bar and creates a default 3 panes with a progress ...
BOOL SetPaneStyle(int pane_index, UINT flags)
Valid style flags are 0 (sunken - no longer works on Win10), SBT_NOBORDERS, SBT_OWNERDRAW, SBT_POPOUT, SBT_RTLREADING and SBT_NOTABPARSING. Specify only one per pane; see the MSDN documentation for the SB_SETTEXT message for more detail.
CProgressBarCtrl & ProgressBar()
Returns a reference to the embedded CProgressBarCtrl.
virtual void UnSubclassStatusBar()
Release the status bar and destroy the embedded progress bar control.
int GetProgressBarMargin() const
Default : 2.
void SetProgressBarMargin(int margin)
Defines the margin around the embedded CProgressBarCtrl, within the pane client area. Make sure not to make this value too big.