1 /////////////////////////////////////////////////////////////////////////
3 // CSizingControlBarCF Version 2.44
5 // Created: Dec 21, 1998 Last Modified: March 31, 2002
7 // See the official site at www.datamekanix.com for documentation and
10 /////////////////////////////////////////////////////////////////////////
11 // Copyright (C) 1998-2002 by Cristi Posea. All rights reserved.
13 // This code is free for personal and commercial use, providing this
14 // notice remains intact in the source files and all eventual changes are
15 // clearly marked with comments.
17 // You must obtain the author's consent before you can include this code
18 // in a software library.
20 // No warrantee of any kind, express or implied, is included with this
21 // software; use at your own risk, responsibility for damages (if any) to
22 // anyone resulting from the use of this software rests entirely with the
25 // Send bug reports, bug fixes, enhancements, requests, flames, etc. to
26 // cristi@datamekanix.com or post them at the message board at the site.
27 /////////////////////////////////////////////////////////////////////////
32 /////////////////////////////////////////////////////////////////////////
33 // CSizingControlBarCF
35 IMPLEMENT_DYNAMIC(CSizingControlBarCF, baseCSizingControlBarCF);
37 int CALLBACK EnumFontFamProc(ENUMLOGFONT FAR *lpelf,
38 NEWTEXTMETRIC FAR *lpntm,
44 UNUSED_ALWAYS(FontType);
45 UNUSED_ALWAYS(lParam);
50 CSizingControlBarCF::CSizingControlBarCF()
55 dc.CreateCompatibleDC(nullptr);
57 m_sFontFace = (::EnumFontFamilies(dc.m_hDC,
58 _T("Tahoma"), (FONTENUMPROC) EnumFontFamProc, 0) == 0) ?
59 _T("Tahoma") : _T("Arial");
62 BEGIN_MESSAGE_MAP(CSizingControlBarCF, baseCSizingControlBarCF)
63 //{{AFX_MSG_MAP(CSizingControlBarCF)
65 ON_MESSAGE(WM_SETTEXT, OnSetText)
68 void CSizingControlBarCF::OnUpdateCmdUI(CFrameWnd* pTarget, BOOL bDisableIfNoHndler)
70 baseCSizingControlBarCF::OnUpdateCmdUI(pTarget, bDisableIfNoHndler);
75 bool bNeedPaint = false;
77 CWnd* pFocus = GetFocus();
78 bool bActiveOld = m_bActive;
80 m_bActive = (pFocus && pFocus->GetSafeHwnd() && IsChild(pFocus));
82 if (m_bActive != bActiveOld)
86 SendMessage(WM_NCPAINT);
89 void CSizingControlBarCF::NcPaintGripper(CDC* pDC, const CRect& rcClient)
94 // compute the caption rectangle
95 bool bHorz = IsHorzDocked();
96 CRect rcGrip = rcClient;
97 const int lpx = pDC->GetDeviceCaps(LOGPIXELSX);
98 auto pointToPixel = [lpx](double point) { return static_cast<int>(point * lpx / 72); };
99 CRect rcBtn(m_biHide.ptOrg, CSize(pointToPixel(m_biHide.dblBoxSize), pointToPixel(m_biHide.dblBoxSize)));
101 { // right side gripper
102 rcGrip.left -= pointToPixel(m_dblGripper + 0.75);
103 rcGrip.right = rcGrip.left + pointToPixel(8.25);
104 rcGrip.top = rcBtn.bottom + pointToPixel(2.25);
108 rcGrip.top -= pointToPixel(m_dblGripper + 0.75);
109 rcGrip.bottom = rcGrip.top + pointToPixel(8.25);
110 rcGrip.right = rcBtn.left - pointToPixel(2.25);
112 rcGrip.InflateRect(bHorz ? pointToPixel(0.75) : 0, bHorz ? 0 : pointToPixel(0.75));
114 // draw the caption background
116 COLORREF clrCptn = m_bActive ?
117 ::GetSysColor(COLOR_ACTIVECAPTION) :
118 ::GetSysColor(COLOR_INACTIVECAPTION);
120 // query gradient info (usually TRUE for Win98/Win2k)
121 BOOL bGradient = FALSE;
122 ::SystemParametersInfo(SPI_GETGRADIENTCAPTIONS, 0, &bGradient, 0);
125 pDC->FillSolidRect(&rcGrip, clrCptn); // solid color
128 // gradient from left to right or from bottom to top
129 // get second gradient color (the right end)
130 COLORREF clrCptnRight = m_bActive ?
131 ::GetSysColor(COLOR_GRADIENTACTIVECAPTION) :
132 ::GetSysColor(COLOR_GRADIENTINACTIVECAPTION);
134 // this will make 2^6 = 64 fountain steps
136 int nSteps = 1 << nShift;
138 for (int i = 0; i < nSteps; i++)
140 // do a little alpha blending
141 int nR = (GetRValue(clrCptn) * (nSteps - i) +
142 GetRValue(clrCptnRight) * i) >> nShift;
143 int nG = (GetGValue(clrCptn) * (nSteps - i) +
144 GetGValue(clrCptnRight) * i) >> nShift;
145 int nB = (GetBValue(clrCptn) * (nSteps - i) +
146 GetBValue(clrCptnRight) * i) >> nShift;
148 COLORREF cr = RGB(nR, nG, nB);
150 // then paint with the resulting color
154 r2.bottom = rcGrip.bottom -
155 ((i * rcGrip.Height()) >> nShift);
156 r2.top = rcGrip.bottom -
157 (((i + 1) * rcGrip.Height()) >> nShift);
159 pDC->FillSolidRect(r2, cr);
163 r2.left = rcGrip.left +
164 ((i * rcGrip.Width()) >> nShift);
165 r2.right = rcGrip.left +
166 (((i + 1) * rcGrip.Width()) >> nShift);
168 pDC->FillSolidRect(r2, cr);
173 // draw the caption text - first select a font
176 bool bFont = !!font.CreatePointFont(85/*8.5 points*/, m_sFontFace);
179 // get the text color
180 COLORREF clrCptnText = m_bActive ?
181 ::GetSysColor(COLOR_CAPTIONTEXT) :
182 ::GetSysColor(COLOR_INACTIVECAPTIONTEXT);
184 int nOldBkMode = pDC->SetBkMode(TRANSPARENT);
185 COLORREF clrOldText = pDC->SetTextColor(clrCptnText);
189 // rotate text 90 degrees CCW if horizontally docked
190 font.GetLogFont(&lf);
192 lf.lfEscapement = 900;
193 font.CreateFontIndirect(&lf);
196 CFont* pOldFont = pDC->SelectObject(&font);
198 GetWindowText(sTitle);
200 CPoint ptOrg = bHorz ?
201 CPoint(rcGrip.left - pointToPixel(0.75), rcGrip.bottom - pointToPixel(2.25)) :
202 CPoint(rcGrip.left + pointToPixel(2.25), rcGrip.top - pointToPixel(0.75));
204 pDC->ExtTextOut(ptOrg.x, ptOrg.y,
205 ETO_CLIPPED, rcGrip, sTitle, nullptr);
207 pDC->SelectObject(pOldFont);
208 pDC->SetBkMode(nOldBkMode);
209 pDC->SetTextColor(clrOldText);
216 LRESULT CSizingControlBarCF::OnSetText(WPARAM wParam, LPARAM lParam)
218 LRESULT lResult = baseCSizingControlBarCF::OnSetText(wParam, lParam);
220 SendMessage(WM_NCPAINT);