00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025 #include "stdafx.h"
00026 #include "mplayerc.h"
00027 #include "StatusLabel.h"
00028
00029
00030
00031
00032 IMPLEMENT_DYNAMIC(CStatusLabel, CStatic)
00033 CStatusLabel::CStatusLabel(bool fRightAlign, bool fAddEllipses)
00034 : m_fRightAlign(fRightAlign)
00035 , m_fAddEllipses(fAddEllipses)
00036 {
00037 HDC hdc = ::GetDC(NULL);
00038 double scale = 1.0*GetDeviceCaps(hdc, LOGPIXELSY) / 96.0;
00039 ::ReleaseDC(0, hdc);
00040
00041 m_font.CreateFont(int(14.0 * scale), 0, 0, 0, FW_NORMAL, 0, 0, 0, DEFAULT_CHARSET,
00042 OUT_DEFAULT_PRECIS, CLIP_DEFAULT_PRECIS, DEFAULT_QUALITY, DEFAULT_PITCH|FF_DONTCARE,
00043 _T("Microsoft Sans Serif"));
00044 if(!m_font.m_hObject)
00045 m_font.CreateFont(int(14.0 * scale), 0, 0, 0, FW_NORMAL, 0, 0, 0, DEFAULT_CHARSET,
00046 OUT_DEFAULT_PRECIS, CLIP_DEFAULT_PRECIS, DEFAULT_QUALITY, DEFAULT_PITCH|FF_DONTCARE,
00047 _T("MS Sans Serif"));
00048 }
00049
00050 CStatusLabel::~CStatusLabel()
00051 {
00052 }
00053
00054 BEGIN_MESSAGE_MAP(CStatusLabel, CStatic)
00055 ON_WM_ERASEBKGND()
00056 END_MESSAGE_MAP()
00057
00058
00059
00060 void CStatusLabel::DrawItem(LPDRAWITEMSTRUCT lpDrawItemStruct)
00061 {
00062 CDC dc;
00063 dc.Attach(lpDrawItemStruct->hDC);
00064 CString str;
00065 GetWindowText(str);
00066 CRect r;
00067 GetClientRect(&r);
00068 CFont* old = dc.SelectObject(&m_font);
00069 dc.SetTextColor(0xffffff);
00070 dc.SetBkColor(0);
00071 CSize size = dc.GetTextExtent(str);
00072 CPoint p = CPoint(m_fRightAlign ? r.Width() - size.cx : 0, (r.Height()-size.cy)/2);
00073
00074 if(m_fAddEllipses)
00075 while(size.cx > r.Width()-3 && str.GetLength() > 3)
00076 {
00077 str = str.Left(str.GetLength()-4) + _T("...");
00078 size = dc.GetTextExtent(str);
00079 }
00080
00081 dc.TextOut(p.x, p.y, str);
00082 dc.ExcludeClipRect(CRect(p, size));
00083 dc.SelectObject(&old);
00084 dc.FillSolidRect(&r, 0);
00085 dc.Detach();
00086 }
00087
00088 BOOL CStatusLabel::OnEraseBkgnd(CDC* pDC)
00089 {
00090 CRect r;
00091 GetClientRect(&r);
00092 pDC->FillSolidRect(&r, 0);
00093 return TRUE;
00094 }
00095