Annotation of mstools/mfc/samples/multipad/bar.cpp, revision 1.1.1.1

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

unix.superglobalmegacorp.com

This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.