|
|
1.1 root 1: // bar.cpp : Defines a standard "chiseled" window, and a status bar window.
2: //
3: // This is a part of the Microsoft Foundation Classes C++ library.
4: // Copyright (C) 1992 Microsoft Corporation
5: // All rights reserved.
6: //
7: // This source code is only intended as a supplement to the
8: // Microsoft Foundation Classes Reference and Microsoft
9: // QuickHelp documentation provided with the library.
10: // See these sources for detailed information regarding the
11: // Microsoft Foundation Classes product.
12:
13: #include "multipad.h"
14:
1.1.1.2 ! root 15: #ifndef _NTWIN
1.1 root 16: #pragma code_seg("_MPTEXT")
1.1.1.2 ! root 17: #endif
1.1 root 18:
19: /////////////////////////////////////////////////////////////////////////////
20: // CBarWnd
21: // See bar.h for details.
22:
23: BEGIN_MESSAGE_MAP(CBarWnd, CWnd)
24: ON_WM_NCPAINT()
25: ON_WM_NCCALCSIZE()
26: END_MESSAGE_MAP()
27:
28: /*static*/ HCURSOR CBarWnd::m_hCursor;
29: /*static*/ CString CBarWnd::m_szRegistration;
30:
31: // Create:
32: // Upon creation, we register our type with Windows as necessary.
33: //
34: BOOL CBarWnd::Create(CWnd* pParentWnd, CRect rect)
35: {
36: if(m_szRegistration.IsEmpty())
37: {
38: m_hCursor = LoadCursor(NULL, IDC_ARROW);
39: m_szRegistration = AfxRegisterWndClass(0, m_hCursor,
40: (HBRUSH)(COLOR_BTNFACE+1), 0);
41: }
42:
43: return CWnd::Create(m_szRegistration, NULL,
44: WS_CHILD | WS_VISIBLE | WS_BORDER, rect, pParentWnd, 0);
45: }
46:
47: // OnNcCalcSize:
48: // We're being asked how large we should be, for a given client rectangle.
49: // We assume we have a border (because our Create gives us one), so we add
50: // that to the rectangle given to us.
51: //
52: void CBarWnd::OnNcCalcSize(NCCALCSIZE_PARAMS FAR* lpcsps)
53: {
54: int cxBorder = GetSystemMetrics(SM_CXBORDER);
55: int cyBorder = GetSystemMetrics(SM_CYBORDER);
56:
57: InflateRect(lpcsps->rgrc, -cxBorder, -(cyBorder * 2));
58: }
59:
60: // OnNCPaint:
61: // Paint the non-client area of a Bar window. This includes the black
62: // border rectangle (WS_BORDER is assumed to be TRUE), a white "border"
63: // near the top and a grey "border" near the bottom, to give us that
64: // chiseled look.
65: //
66: void CBarWnd::OnNcPaint()
67: {
68: CWindowDC dc(this);
69: CRect rc;
70: int cxBorder = GetSystemMetrics(SM_CXBORDER);
71: int cyBorder = GetSystemMetrics(SM_CYBORDER);
72:
73: GetWindowRect(rc);
74: int cxWidth = rc.Width();
75: int cyHeight = rc.Height();
76:
77: CBrush borderBrush(GetSysColor(COLOR_WINDOWFRAME));
78: CBrush* oldBrush = dc.SelectObject(&borderBrush);
79: dc.PatBlt(0, 0, cxWidth, cyBorder, PATCOPY);
80: dc.PatBlt(0, cyBorder, cxBorder, cyHeight - cyBorder * 2, PATCOPY);
81: dc.PatBlt(0, cyHeight - cyBorder, cxWidth, cyBorder, PATCOPY);
82: dc.PatBlt(cxWidth - cxBorder, cyBorder,
83: cxBorder, cyHeight - cyBorder * 2, PATCOPY);
84:
85: dc.PatBlt(cxBorder, cyBorder,
86: cxWidth - cxBorder * 2, cyBorder, WHITENESS);
87:
88: CBrush shadowBrush(GetSysColor(COLOR_BTNSHADOW));
89: dc.SelectObject(&shadowBrush);
90: dc.PatBlt(cxBorder, cyHeight - cyBorder * 2,
91: cxWidth - cxBorder * 2, cyBorder, PATCOPY);
92:
93: dc.SelectObject(oldBrush);
94: }
95:
96: /////////////////////////////////////////////////////////////////////////////
97: // CStatBar
98: // See bar.h for details.
99:
100: BEGIN_MESSAGE_MAP(CStatBar, CBarWnd)
101: ON_WM_PAINT()
102: END_MESSAGE_MAP()
103:
104:
105: BOOL CStatBar::Create(CWnd* pParentWnd, CRect rect)
106: {
107: int cyStatBar;
108: int cyBorder = GetSystemMetrics(SM_CYBORDER);
109:
110: if (!CBarWnd::Create(pParentWnd, rect))
111: return FALSE;
112:
113: m_font.CreateFont(13, 0, 0, 0, 0, FALSE, FALSE, FALSE, ANSI_CHARSET,
114: OUT_DEFAULT_PRECIS, CLIP_DEFAULT_PRECIS, DEFAULT_QUALITY,
115: DEFAULT_PITCH | FF_SWISS, NULL);
116:
117: CClientDC dc(this);
118: CFont* oldFont = dc.SelectObject(&m_font);
119: cyStatBar = dc.GetTextExtent("M", 1).cy + 5 * cyBorder + 4;
120: dc.SelectObject(oldFont);
121:
122: SetWindowPos(NULL, 0, 0, rect.right - rect.left, cyStatBar,
123: SWP_NOZORDER | SWP_NOMOVE | SWP_NOACTIVATE);
124:
125: return TRUE;
126: }
127:
128:
129: // OnPaint:
130: // A status bar, in addition to the chiseled look of all CBarWnd's, has a
131: // line of text to be displayed.
132: //
133: void CStatBar::OnPaint()
134: {
135: CPaintDC dc(this);
136: CRect rc;
137: int cyBorder = GetSystemMetrics(SM_CYBORDER);
138:
139: GetClientRect(rc);
140:
141: dc.SetBkColor(GetSysColor(COLOR_BTNFACE));
142: CFont* oldFont = dc.SelectObject(&m_font);
143: dc.ExtTextOut(8, 0, ETO_OPAQUE, rc, m_string,
144: m_string.GetLength(), NULL);
145: dc.SelectObject(oldFont);
146: }
This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.