1 // Win32++ Version 7.3
\r
2 // Released: 30th November 2011
\r
6 // url: https://sourceforge.net/projects/win32-framework
\r
9 // Copyright (c) 2005-2011 David Nash
\r
11 // Permission is hereby granted, free of charge, to
\r
12 // any person obtaining a copy of this software and
\r
13 // associated documentation files (the "Software"),
\r
14 // to deal in the Software without restriction, including
\r
15 // without limitation the rights to use, copy, modify,
\r
16 // merge, publish, distribute, sublicense, and/or sell
\r
17 // copies of the Software, and to permit persons to whom
\r
18 // the Software is furnished to do so, subject to the
\r
19 // following conditions:
\r
21 // The above copyright notice and this permission notice
\r
22 // shall be included in all copies or substantial portions
\r
25 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF
\r
26 // ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED
\r
27 // TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A
\r
28 // PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT
\r
29 // SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR
\r
30 // ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
\r
31 // ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
\r
32 // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE
\r
33 // OR OTHER DEALINGS IN THE SOFTWARE.
\r
35 ////////////////////////////////////////////////////////
\r
38 #ifndef _WIN32XX_STATUSBAR_H_
\r
39 #define _WIN32XX_STATUSBAR_H_
\r
41 #include "wincore.h"
\r
46 //////////////////////////////////////
\r
47 // Declaration of the CStatusBar class
\r
49 class CStatusBar : public CWnd
\r
53 virtual ~CStatusBar() {}
\r
56 virtual void PreCreate(CREATESTRUCT& cs);
\r
57 virtual void PreRegisterClass(WNDCLASS &wc);
\r
61 HICON GetPartIcon(int iPart);
\r
62 CRect GetPartRect(int iPart);
\r
63 CString GetPartText(int iPart) const;
\r
65 BOOL SetPartIcon(int iPart, HICON hIcon);
\r
66 BOOL SetPartText(int iPart, LPCTSTR szText, UINT Style = 0) const;
\r
67 BOOL SetPartWidth(int iPart, int iWidth) const;
\r
70 CStatusBar(const CStatusBar&); // Disable copy construction
\r
71 CStatusBar& operator = (const CStatusBar&); // Disable assignment operator
\r
73 BOOL CreateParts(int iParts, const int iPaneWidths[]) const;
\r
74 void SetSimple(BOOL fSimple = TRUE);
\r
80 //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
\r
86 //////////////////////////////////////
\r
87 // Definitions for the CStatusBar class
\r
89 inline CStatusBar::CStatusBar()
\r
93 inline BOOL CStatusBar::CreateParts(int iParts, const int iPaneWidths[]) const
\r
94 // Sets the number of parts in a status window and the coordinate of the right edge of each part.
\r
95 // If an element of iPaneWidths is -1, the right edge of the corresponding part extends
\r
96 // to the border of the window
\r
98 assert(::IsWindow(m_hWnd));
\r
99 assert(iParts <= 256);
\r
101 return (BOOL)SendMessage(SB_SETPARTS, iParts, (LPARAM)iPaneWidths);
\r
104 inline int CStatusBar::GetParts()
\r
106 assert(::IsWindow(m_hWnd));
\r
107 return (int)SendMessage(SB_GETPARTS, 0L, 0L);
\r
110 inline HICON CStatusBar::GetPartIcon(int iPart)
\r
112 assert(::IsWindow(m_hWnd));
\r
113 return (HICON)SendMessage(SB_GETICON, (WPARAM)iPart, 0L);
\r
116 inline CRect CStatusBar::GetPartRect(int iPart)
\r
118 assert(::IsWindow(m_hWnd));
\r
121 SendMessage(SB_GETRECT, (WPARAM)iPart, (LPARAM)&rc);
\r
125 inline CString CStatusBar::GetPartText(int iPart) const
\r
127 assert(::IsWindow(m_hWnd));
\r
130 // Get size of Text array
\r
131 int iChars = LOWORD (SendMessage(SB_GETTEXTLENGTH, iPart, 0L));
\r
133 std::vector<TCHAR> Text( iChars +1, _T('\0') );
\r
134 TCHAR* pTextArray = &Text[0];
\r
136 SendMessage(SB_GETTEXT, iPart, (LPARAM)pTextArray);
\r
137 PaneText = pTextArray;
\r
141 inline BOOL CStatusBar::IsSimple()
\r
143 assert(::IsWindow(m_hWnd));
\r
144 return (BOOL)SendMessage(SB_ISSIMPLE, 0L, 0L);
\r
147 inline void CStatusBar::PreCreate(CREATESTRUCT &cs)
\r
149 cs.style = WS_CHILD | WS_VISIBLE | WS_CLIPSIBLINGS | CCS_BOTTOM | SBARS_SIZEGRIP;
\r
152 inline void CStatusBar::PreRegisterClass(WNDCLASS &wc)
\r
154 // Set the Window Class
\r
155 wc.lpszClassName = STATUSCLASSNAME;
\r
158 inline BOOL CStatusBar::SetPartText(int iPart, LPCTSTR szText, UINT Style) const
\r
159 // Available Styles: Combinations of ...
\r
160 //0 The text is drawn with a border to appear lower than the plane of the window.
\r
161 //SBT_NOBORDERS The text is drawn without borders.
\r
162 //SBT_OWNERDRAW The text is drawn by the parent window.
\r
163 //SBT_POPOUT The text is drawn with a border to appear higher than the plane of the window.
\r
164 //SBT_RTLREADING The text will be displayed in the opposite direction to the text in the parent window.
\r
166 assert(::IsWindow(m_hWnd));
\r
168 BOOL bResult = FALSE;
\r
169 if (SendMessage(SB_GETPARTS, 0L, 0L) >= iPart)
\r
170 bResult = (BOOL)SendMessage(SB_SETTEXT, iPart | Style, (LPARAM)szText);
\r
175 inline BOOL CStatusBar::SetPartIcon(int iPart, HICON hIcon)
\r
177 assert(::IsWindow(m_hWnd));
\r
178 return (BOOL)SendMessage(SB_SETICON, (WPARAM)iPart, (LPARAM) hIcon);
\r
181 inline BOOL CStatusBar::SetPartWidth(int iPart, int iWidth) const
\r
183 // This changes the width of an existing pane, or creates a new pane
\r
184 // with the specified width.
\r
185 // A width of -1 for the last part sets the width to the border of the window.
\r
187 assert(::IsWindow(m_hWnd));
\r
188 assert(iPart >= 0 && iPart <= 255);
\r
190 // Fill the PartWidths vector with the current width of the statusbar parts
\r
191 int PartsCount = (int)SendMessage(SB_GETPARTS, 0L, 0L);
\r
192 std::vector<int> PartWidths(PartsCount, 0);
\r
193 int* pPartWidthArray = &PartWidths[0];
\r
194 SendMessage(SB_GETPARTS, PartsCount, (LPARAM)pPartWidthArray);
\r
196 // Fill the NewPartWidths vector with the new width of the statusbar parts
\r
197 int NewPartsCount = MAX(iPart+1, PartsCount);
\r
198 std::vector<int> NewPartWidths(NewPartsCount, 0);;
\r
199 NewPartWidths = PartWidths;
\r
200 int* pNewPartWidthArray = &NewPartWidths[0];
\r
203 pNewPartWidthArray[iPart] = iWidth;
\r
207 pNewPartWidthArray[iPart] = pNewPartWidthArray[iPart -1] + iWidth;
\r
209 pNewPartWidthArray[iPart] = -1;
\r
212 // Set the statusbar parts with our new parts count and part widths
\r
213 BOOL bResult = (BOOL)SendMessage(SB_SETPARTS, NewPartsCount, (LPARAM)pNewPartWidthArray);
\r
218 inline void CStatusBar::SetSimple(BOOL fSimple /* = TRUE*/)
\r
220 assert(::IsWindow(m_hWnd));
\r
221 SendMessage(SB_SIMPLE, (WPARAM)fSimple, 0L);
\r
224 } // namespace Win32xx
\r
226 #endif // #ifndef _WIN32XX_STATUSBAR_H_
\r