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 "VolumeCtrl.h"
00028
00029
00030
00031
00032 IMPLEMENT_DYNAMIC(CVolumeCtrl, CSliderCtrl)
00033 CVolumeCtrl::CVolumeCtrl(bool fSelfDrawn) : m_fSelfDrawn(fSelfDrawn)
00034 {
00035 }
00036
00037 CVolumeCtrl::~CVolumeCtrl()
00038 {
00039 }
00040
00041 bool CVolumeCtrl::Create(CWnd* pParentWnd)
00042 {
00043 if(!CSliderCtrl::Create(WS_CHILD|WS_VISIBLE|TBS_NOTICKS|TBS_HORZ, CRect(0,0,0,0), pParentWnd, IDC_VOLUMESLIDER))
00044 return(false);
00045
00046 SetRange(1, 100);
00047 SetPosInternal(AfxGetAppSettings().nVolume);
00048 SetPageSize(8);
00049 SetLineSize(0);
00050
00051 return(true);
00052 }
00053
00054 void CVolumeCtrl::SetPosInternal(int pos)
00055 {
00056 SetPos(pos);
00057 GetParent()->PostMessage(WM_HSCROLL, MAKEWPARAM((short)pos, SB_THUMBPOSITION), (LPARAM)m_hWnd);
00058 }
00059
00060 void CVolumeCtrl::IncreaseVolume()
00061 {
00062 SetPosInternal(GetPos() + GetPageSize());
00063 }
00064
00065 void CVolumeCtrl::DecreaseVolume()
00066 {
00067 SetPosInternal(GetPos() - GetPageSize());
00068 }
00069
00070 BEGIN_MESSAGE_MAP(CVolumeCtrl, CSliderCtrl)
00071 ON_NOTIFY_REFLECT(NM_CUSTOMDRAW, OnNMCustomdraw)
00072 ON_WM_LBUTTONDOWN()
00073 ON_WM_SETFOCUS()
00074 ON_WM_HSCROLL_REFLECT()
00075 END_MESSAGE_MAP()
00076
00077
00078
00079
00080 void CVolumeCtrl::OnNMCustomdraw(NMHDR* pNMHDR, LRESULT* pResult)
00081 {
00082 LPNMCUSTOMDRAW pNMCD = reinterpret_cast<LPNMCUSTOMDRAW>(pNMHDR);
00083
00084 LRESULT lr = CDRF_DODEFAULT;
00085
00086 if(m_fSelfDrawn)
00087 switch(pNMCD->dwDrawStage)
00088 {
00089 case CDDS_PREPAINT:
00090 lr = CDRF_NOTIFYITEMDRAW;
00091 break;
00092
00093 case CDDS_ITEMPREPAINT:
00094 if(pNMCD->dwItemSpec == TBCD_CHANNEL)
00095 {
00096 CDC dc;
00097 dc.Attach(pNMCD->hdc);
00098
00099 CRect r;
00100 GetClientRect(r);
00101 r.DeflateRect(8, 4, 10, 6);
00102 CopyRect(&pNMCD->rc, &r);
00103 CPen shadow(PS_SOLID, 1, GetSysColor(COLOR_3DSHADOW));
00104 CPen light(PS_SOLID, 1, GetSysColor(COLOR_3DHILIGHT));
00105 CPen* old = dc.SelectObject(&light);
00106 dc.MoveTo(pNMCD->rc.right, pNMCD->rc.top);
00107 dc.LineTo(pNMCD->rc.right, pNMCD->rc.bottom);
00108 dc.LineTo(pNMCD->rc.left, pNMCD->rc.bottom);
00109 dc.SelectObject(&shadow);
00110 dc.LineTo(pNMCD->rc.right, pNMCD->rc.top);
00111 dc.SelectObject(old);
00112
00113 dc.Detach();
00114 lr = CDRF_SKIPDEFAULT;
00115 }
00116 else if(pNMCD->dwItemSpec == TBCD_THUMB)
00117 {
00118 CDC dc;
00119 dc.Attach(pNMCD->hdc);
00120 pNMCD->rc.bottom--;
00121 CRect r(pNMCD->rc);
00122 r.DeflateRect(0, 0, 1, 0);
00123
00124 COLORREF shadow = GetSysColor(COLOR_3DSHADOW);
00125 COLORREF light = GetSysColor(COLOR_3DHILIGHT);
00126 dc.Draw3dRect(&r, light, 0);
00127 r.DeflateRect(0, 0, 1, 1);
00128 dc.Draw3dRect(&r, light, shadow);
00129 r.DeflateRect(1, 1, 1, 1);
00130 dc.FillSolidRect(&r, GetSysColor(COLOR_BTNFACE));
00131 dc.SetPixel(r.left+7, r.top-1, GetSysColor(COLOR_BTNFACE));
00132
00133 dc.Detach();
00134 lr = CDRF_SKIPDEFAULT;
00135 }
00136
00137 break;
00138 };
00139
00140 pNMCD->uItemState &= ~CDIS_FOCUS;
00141
00142 *pResult = lr;
00143 }
00144
00145 void CVolumeCtrl::OnLButtonDown(UINT nFlags, CPoint point)
00146 {
00147 CRect r;
00148 GetChannelRect(&r);
00149
00150 if(r.left >= r.right) return;
00151
00152 int start, stop;
00153 GetRange(start, stop);
00154
00155 int pos = GetPos();
00156
00157 r.left += 3;
00158 r.right -= 4;
00159
00160 if(point.x < r.left) SetPos(start);
00161 else if(point.x >= r.right) SetPos(stop);
00162 else
00163 {
00164 int w = r.right - r.left;
00165 if(start < stop)
00166 SetPosInternal(start + ((stop - start) * (point.x - r.left) + (w/2)) / w);
00167 }
00168
00169 CSliderCtrl::OnLButtonDown(nFlags, point);
00170 }
00171
00172 void CVolumeCtrl::OnSetFocus(CWnd* pOldWnd)
00173 {
00174 CSliderCtrl::OnSetFocus(pOldWnd);
00175
00176 AfxGetMainWnd()->SetFocus();
00177 }
00178
00179 void CVolumeCtrl::HScroll(UINT nSBCode, UINT nPos)
00180 {
00181 AfxGetAppSettings().nVolume = GetPos();
00182
00183 CFrameWnd* pFrame = GetParentFrame();
00184 if(pFrame && pFrame != GetParent())
00185 pFrame->PostMessage(WM_HSCROLL, MAKEWPARAM((short)nPos, nSBCode), (LPARAM)m_hWnd);
00186 }