00001
00002
00003
00004
00005
00006
00007
00008
00009
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00028
00029 #include "stdafx.h"
00030 #include "scbarcf.h"
00031
00033
00034
00035 IMPLEMENT_DYNAMIC(CSizingControlBarCF, baseCSizingControlBarCF);
00036
00037 int CALLBACK EnumFontFamProc(ENUMLOGFONT FAR *lpelf,
00038 NEWTEXTMETRIC FAR *lpntm,
00039 int FontType,
00040 LPARAM lParam)
00041 {
00042 UNUSED_ALWAYS(lpelf);
00043 UNUSED_ALWAYS(lpntm);
00044 UNUSED_ALWAYS(FontType);
00045 UNUSED_ALWAYS(lParam);
00046
00047 return 0;
00048 }
00049
00050 CSizingControlBarCF::CSizingControlBarCF()
00051 {
00052 m_bActive = FALSE;
00053
00054 CDC dc;
00055 dc.CreateCompatibleDC(NULL);
00056
00057 m_sFontFace = (::EnumFontFamilies(dc.m_hDC,
00058 _T("Tahoma"), (FONTENUMPROC) EnumFontFamProc, 0) == 0) ?
00059 _T("Tahoma") : _T("Arial");
00060
00061 dc.DeleteDC();
00062
00063 }
00064
00065 BEGIN_MESSAGE_MAP(CSizingControlBarCF, baseCSizingControlBarCF)
00066
00067
00068 ON_MESSAGE(WM_SETTEXT, OnSetText)
00069 END_MESSAGE_MAP()
00070
00071 void CSizingControlBarCF::OnUpdateCmdUI(CFrameWnd* pTarget, BOOL bDisableIfNoHndler)
00072 {
00073 baseCSizingControlBarCF::OnUpdateCmdUI(pTarget, bDisableIfNoHndler);
00074
00075 if (!HasGripper())
00076 return;
00077
00078 BOOL bNeedPaint = FALSE;
00079
00080 CWnd* pFocus = GetFocus();
00081 BOOL bActiveOld = m_bActive;
00082
00083 m_bActive = (pFocus->GetSafeHwnd() && IsChild(pFocus));
00084
00085 if (m_bActive != bActiveOld)
00086 bNeedPaint = TRUE;
00087
00088 if (bNeedPaint)
00089 SendMessage(WM_NCPAINT);
00090 }
00091
00092
00093 #ifndef COLOR_GRADIENTACTIVECAPTION
00094 #define COLOR_GRADIENTACTIVECAPTION 27
00095 #define COLOR_GRADIENTINACTIVECAPTION 28
00096 #define SPI_GETGRADIENTCAPTIONS 0x1008
00097 #endif
00098
00099 void CSizingControlBarCF::NcPaintGripper(CDC* pDC, CRect rcClient)
00100 {
00101 if (!HasGripper())
00102 return;
00103
00104
00105 BOOL bHorz = IsHorzDocked();
00106 CRect rcGrip = rcClient;
00107 CRect rcBtn = m_biHide.GetRect();
00108 if (bHorz)
00109 {
00110 rcGrip.left -= m_cyGripper + 1;
00111 rcGrip.right = rcGrip.left + 11;
00112 rcGrip.top = rcBtn.bottom + 3;
00113 }
00114 else
00115 {
00116 rcGrip.top -= m_cyGripper + 1;
00117 rcGrip.bottom = rcGrip.top + 11;
00118 rcGrip.right = rcBtn.left - 3;
00119 }
00120 rcGrip.InflateRect(bHorz ? 1 : 0, bHorz ? 0 : 1);
00121
00122
00123
00124 COLORREF clrCptn = m_bActive ?
00125 ::GetSysColor(COLOR_ACTIVECAPTION) :
00126 ::GetSysColor(COLOR_INACTIVECAPTION);
00127
00128
00129 BOOL bGradient = FALSE;
00130 ::SystemParametersInfo(SPI_GETGRADIENTCAPTIONS, 0, &bGradient, 0);
00131
00132 if (!bGradient)
00133 pDC->FillSolidRect(&rcGrip, clrCptn);
00134 else
00135 {
00136
00137
00138 COLORREF clrCptnRight = m_bActive ?
00139 ::GetSysColor(COLOR_GRADIENTACTIVECAPTION) :
00140 ::GetSysColor(COLOR_GRADIENTINACTIVECAPTION);
00141
00142
00143 int nShift = 6;
00144 int nSteps = 1 << nShift;
00145
00146 for (int i = 0; i < nSteps; i++)
00147 {
00148
00149 int nR = (GetRValue(clrCptn) * (nSteps - i) +
00150 GetRValue(clrCptnRight) * i) >> nShift;
00151 int nG = (GetGValue(clrCptn) * (nSteps - i) +
00152 GetGValue(clrCptnRight) * i) >> nShift;
00153 int nB = (GetBValue(clrCptn) * (nSteps - i) +
00154 GetBValue(clrCptnRight) * i) >> nShift;
00155
00156 COLORREF cr = RGB(nR, nG, nB);
00157
00158
00159 CRect r2 = rcGrip;
00160 if (bHorz)
00161 {
00162 r2.bottom = rcGrip.bottom -
00163 ((i * rcGrip.Height()) >> nShift);
00164 r2.top = rcGrip.bottom -
00165 (((i + 1) * rcGrip.Height()) >> nShift);
00166 if (r2.Height() > 0)
00167 pDC->FillSolidRect(r2, cr);
00168 }
00169 else
00170 {
00171 r2.left = rcGrip.left +
00172 ((i * rcGrip.Width()) >> nShift);
00173 r2.right = rcGrip.left +
00174 (((i + 1) * rcGrip.Width()) >> nShift);
00175 if (r2.Width() > 0)
00176 pDC->FillSolidRect(r2, cr);
00177 }
00178 }
00179 }
00180
00181
00182 CFont font;
00183 int ppi = pDC->GetDeviceCaps(LOGPIXELSX);
00184 int pointsize = MulDiv(85, 96, ppi);
00185
00186 LOGFONT lf;
00187 BOOL bFont = font.CreatePointFont(pointsize, m_sFontFace);
00188 if (bFont)
00189 {
00190
00191 COLORREF clrCptnText = m_bActive ?
00192 ::GetSysColor(COLOR_CAPTIONTEXT) :
00193 ::GetSysColor(COLOR_INACTIVECAPTIONTEXT);
00194
00195 int nOldBkMode = pDC->SetBkMode(TRANSPARENT);
00196 COLORREF clrOldText = pDC->SetTextColor(clrCptnText);
00197
00198 if (bHorz)
00199 {
00200
00201 font.GetLogFont(&lf);
00202 font.DeleteObject();
00203 lf.lfEscapement = 900;
00204 font.CreateFontIndirect(&lf);
00205 }
00206
00207 CFont* pOldFont = pDC->SelectObject(&font);
00208 CString sTitle;
00209 GetWindowText(sTitle);
00210
00211 CPoint ptOrg = bHorz ?
00212 CPoint(rcGrip.left - 1, rcGrip.bottom - 3) :
00213 CPoint(rcGrip.left + 3, rcGrip.top - 1);
00214
00215 pDC->ExtTextOut(ptOrg.x, ptOrg.y,
00216 ETO_CLIPPED, rcGrip, sTitle, NULL);
00217
00218 pDC->SelectObject(pOldFont);
00219 pDC->SetBkMode(nOldBkMode);
00220 pDC->SetTextColor(clrOldText);
00221 }
00222
00223
00224 m_biHide.Paint(pDC);
00225 }
00226
00227 LRESULT CSizingControlBarCF::OnSetText(WPARAM wParam, LPARAM lParam)
00228 {
00229 LRESULT lResult = baseCSizingControlBarCF::OnSetText(wParam, lParam);
00230
00231 SendMessage(WM_NCPAINT);
00232
00233 return lResult;
00234 }