+// Win32++ Version 7.3\r
+// Released: 30th November 2011\r
+//\r
+// David Nash\r
+// url: https://sourceforge.net/projects/win32-framework\r
+//\r
+//\r
+// Copyright (c) 2005-2011 David Nash\r
+//\r
+// Permission is hereby granted, free of charge, to\r
+// any person obtaining a copy of this software and\r
+// associated documentation files (the "Software"),\r
+// to deal in the Software without restriction, including\r
+// without limitation the rights to use, copy, modify,\r
+// merge, publish, distribute, sublicense, and/or sell\r
+// copies of the Software, and to permit persons to whom\r
+// the Software is furnished to do so, subject to the\r
+// following conditions:\r
+//\r
+// The above copyright notice and this permission notice\r
+// shall be included in all copies or substantial portions\r
+// of the Software.\r
+//\r
+// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF\r
+// ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED\r
+// TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A\r
+// PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT\r
+// SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR\r
+// ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN\r
+// ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,\r
+// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE\r
+// OR OTHER DEALINGS IN THE SOFTWARE.\r
+//\r
+////////////////////////////////////////////////////////\r
+\r
+\r
+#ifndef _WIN32XX_STATUSBAR_H_\r
+#define _WIN32XX_STATUSBAR_H_\r
+\r
+#include "wincore.h"\r
+\r
+namespace Win32xx\r
+{\r
+\r
+ //////////////////////////////////////\r
+ // Declaration of the CStatusBar class\r
+ //\r
+ class CStatusBar : public CWnd\r
+ {\r
+ public:\r
+ CStatusBar();\r
+ virtual ~CStatusBar() {}\r
+\r
+ // Overridables\r
+ virtual void PreCreate(CREATESTRUCT& cs);\r
+ virtual void PreRegisterClass(WNDCLASS &wc);\r
+\r
+ // Attributes\r
+ int GetParts();\r
+ HICON GetPartIcon(int iPart);\r
+ CRect GetPartRect(int iPart);\r
+ CString GetPartText(int iPart) const;\r
+ BOOL IsSimple();\r
+ BOOL SetPartIcon(int iPart, HICON hIcon);\r
+ BOOL SetPartText(int iPart, LPCTSTR szText, UINT Style = 0) const;\r
+ BOOL SetPartWidth(int iPart, int iWidth) const;\r
+\r
+ // Operations\r
+ CStatusBar(const CStatusBar&); // Disable copy construction\r
+ CStatusBar& operator = (const CStatusBar&); // Disable assignment operator\r
+\r
+ BOOL CreateParts(int iParts, const int iPaneWidths[]) const;\r
+ void SetSimple(BOOL fSimple = TRUE);\r
+ };\r
+\r
+}\r
+\r
+\r
+//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~\r
+\r
+\r
+namespace Win32xx\r
+{\r
+\r
+ //////////////////////////////////////\r
+ // Definitions for the CStatusBar class\r
+ //\r
+ inline CStatusBar::CStatusBar()\r
+ {\r
+ }\r
+\r
+ inline BOOL CStatusBar::CreateParts(int iParts, const int iPaneWidths[]) const\r
+ // Sets the number of parts in a status window and the coordinate of the right edge of each part. \r
+ // If an element of iPaneWidths is -1, the right edge of the corresponding part extends\r
+ // to the border of the window\r
+ {\r
+ assert(::IsWindow(m_hWnd));\r
+ assert(iParts <= 256); \r
+ \r
+ return (BOOL)SendMessage(SB_SETPARTS, iParts, (LPARAM)iPaneWidths); \r
+ }\r
+\r
+ inline int CStatusBar::GetParts()\r
+ {\r
+ assert(::IsWindow(m_hWnd));\r
+ return (int)SendMessage(SB_GETPARTS, 0L, 0L);\r
+ }\r
+\r
+ inline HICON CStatusBar::GetPartIcon(int iPart)\r
+ {\r
+ assert(::IsWindow(m_hWnd));\r
+ return (HICON)SendMessage(SB_GETICON, (WPARAM)iPart, 0L);\r
+ }\r
+\r
+ inline CRect CStatusBar::GetPartRect(int iPart)\r
+ {\r
+ assert(::IsWindow(m_hWnd));\r
+ \r
+ CRect rc;\r
+ SendMessage(SB_GETRECT, (WPARAM)iPart, (LPARAM)&rc);\r
+ return rc;\r
+ }\r
+\r
+ inline CString CStatusBar::GetPartText(int iPart) const\r
+ {\r
+ assert(::IsWindow(m_hWnd));\r
+ CString PaneText;\r
+ \r
+ // Get size of Text array\r
+ int iChars = LOWORD (SendMessage(SB_GETTEXTLENGTH, iPart, 0L));\r
+\r
+ std::vector<TCHAR> Text( iChars +1, _T('\0') );\r
+ TCHAR* pTextArray = &Text[0];\r
+\r
+ SendMessage(SB_GETTEXT, iPart, (LPARAM)pTextArray);\r
+ PaneText = pTextArray; \r
+ return PaneText;\r
+ }\r
+\r
+ inline BOOL CStatusBar::IsSimple()\r
+ {\r
+ assert(::IsWindow(m_hWnd));\r
+ return (BOOL)SendMessage(SB_ISSIMPLE, 0L, 0L);\r
+ }\r
+\r
+ inline void CStatusBar::PreCreate(CREATESTRUCT &cs)\r
+ {\r
+ cs.style = WS_CHILD | WS_VISIBLE | WS_CLIPSIBLINGS | CCS_BOTTOM | SBARS_SIZEGRIP;\r
+ }\r
+\r
+ inline void CStatusBar::PreRegisterClass(WNDCLASS &wc)\r
+ {\r
+ // Set the Window Class\r
+ wc.lpszClassName = STATUSCLASSNAME;\r
+ }\r
+\r
+ inline BOOL CStatusBar::SetPartText(int iPart, LPCTSTR szText, UINT Style) const\r
+ // Available Styles: Combinations of ...\r
+ //0 The text is drawn with a border to appear lower than the plane of the window.\r
+ //SBT_NOBORDERS The text is drawn without borders.\r
+ //SBT_OWNERDRAW The text is drawn by the parent window.\r
+ //SBT_POPOUT The text is drawn with a border to appear higher than the plane of the window.\r
+ //SBT_RTLREADING The text will be displayed in the opposite direction to the text in the parent window.\r
+ {\r
+ assert(::IsWindow(m_hWnd));\r
+ \r
+ BOOL bResult = FALSE;\r
+ if (SendMessage(SB_GETPARTS, 0L, 0L) >= iPart)\r
+ bResult = (BOOL)SendMessage(SB_SETTEXT, iPart | Style, (LPARAM)szText);\r
+\r
+ return bResult;\r
+ }\r
+\r
+ inline BOOL CStatusBar::SetPartIcon(int iPart, HICON hIcon)\r
+ {\r
+ assert(::IsWindow(m_hWnd));\r
+ return (BOOL)SendMessage(SB_SETICON, (WPARAM)iPart, (LPARAM) hIcon);\r
+ }\r
+\r
+ inline BOOL CStatusBar::SetPartWidth(int iPart, int iWidth) const\r
+ {\r
+ // This changes the width of an existing pane, or creates a new pane\r
+ // with the specified width.\r
+ // A width of -1 for the last part sets the width to the border of the window.\r
+\r
+ assert(::IsWindow(m_hWnd));\r
+ assert(iPart >= 0 && iPart <= 255);\r
+\r
+ // Fill the PartWidths vector with the current width of the statusbar parts\r
+ int PartsCount = (int)SendMessage(SB_GETPARTS, 0L, 0L);\r
+ std::vector<int> PartWidths(PartsCount, 0);\r
+ int* pPartWidthArray = &PartWidths[0];\r
+ SendMessage(SB_GETPARTS, PartsCount, (LPARAM)pPartWidthArray);\r
+\r
+ // Fill the NewPartWidths vector with the new width of the statusbar parts\r
+ int NewPartsCount = MAX(iPart+1, PartsCount); \r
+ std::vector<int> NewPartWidths(NewPartsCount, 0);;\r
+ NewPartWidths = PartWidths;\r
+ int* pNewPartWidthArray = &NewPartWidths[0];\r
+ \r
+ if (0 == iPart)\r
+ pNewPartWidthArray[iPart] = iWidth;\r
+ else\r
+ {\r
+ if (iWidth >= 0)\r
+ pNewPartWidthArray[iPart] = pNewPartWidthArray[iPart -1] + iWidth;\r
+ else\r
+ pNewPartWidthArray[iPart] = -1;\r
+ }\r
+\r
+ // Set the statusbar parts with our new parts count and part widths\r
+ BOOL bResult = (BOOL)SendMessage(SB_SETPARTS, NewPartsCount, (LPARAM)pNewPartWidthArray);\r
+\r
+ return bResult;\r
+ }\r
+\r
+ inline void CStatusBar::SetSimple(BOOL fSimple /* = TRUE*/)\r
+ {\r
+ assert(::IsWindow(m_hWnd));\r
+ SendMessage(SB_SIMPLE, (WPARAM)fSimple, 0L);\r
+ }\r
+\r
+} // namespace Win32xx\r
+\r
+#endif // #ifndef _WIN32XX_STATUSBAR_H_\r