LRESULT FProgress::OnMouseButton(UINT message, WPARAM, LPARAM lParam, BOOL&) { if (message == WM_LBUTTONDOWN) { POINT pt = {GET_X_LPARAM(lParam), GET_Y_LPARAM(lParam)}; FRect rClient; GetClientRect(&rClient); int AvailPx = (int)GetAvail(rClient.Width()); if (pt.x < AvailPx) { if (m_hWnd != GetCapture()) { SetCapture(); m_dwFlags|=FPROGRESS_MOUSEDOWN; SetCurrentFromMax((double)pt.x, (double)rClient.Width()); InvalidateRect(NULL, TRUE); SendMessage(GetParent(), WM_HSCROLL, MAKEWPARAM(GetMenu(), TB_THUMBPOSITION), (LPARAM)m_hWnd); m_LastMousePt = pt; } } } else if (message == WM_LBUTTONUP) { m_LastMousePt.x = m_LastMousePt.y = 0; ReleaseCapture(); m_dwFlags&=~FPROGRESS_MOUSEDOWN; } return 0; }
LRESULT FProgress::OnMouseMove(UINT, WPARAM, LPARAM lParam, BOOL&) { POINT pt = {GET_X_LPARAM(lParam), GET_Y_LPARAM(lParam)}; FRect rClient; GetClientRect(&rClient); int AvailPx = (int)GetAvail(rClient.Width()); if (pt.x <= AvailPx) m_CurCursorIndex = 1; //Hand else m_CurCursorIndex = 0; //Arrow if (m_dwFlags & FPROGRESS_MOUSEDOWN) { if (pt.x > rClient.Width()) pt.x = rClient.Width(); SetCurrentFromMax((double)pt.x, (double)rClient.Width()); InvalidateRect(NULL, TRUE); SendMessage(GetParent(), WM_HSCROLL, MAKEWPARAM(GetMenu(), TB_THUMBPOSITION), (LPARAM)m_hWnd); } return 0; }
void FProgress::DrawMeter(CDC& dc, FRect& rcPaint) { //fill the unavailable int nLines = rcPaint.Width() / (gLineDistance + gPenWidth) + 1; int nAvailLines = (int)GetAvail((double)nLines) ; int nCurrLines = (int)GetCurrent((double)nLines); assert(nAvailLines >= nCurrLines); int x = rcPaint.left; int y = rcPaint.top; dc.MoveTo(x, y); int lh = rcPaint.Height() - 0; int mh = lh; int nPenIndex = 2; dc.SelectPen(m_Pens[nPenIndex]); dword dwStyle = GetWindowLong(GWL_STYLE); for (int k = 0; k < nLines; k++) { if (k == nCurrLines) { if (k < nAvailLines) dc.SelectPen(m_Pens[1]); else dc.SelectPen(m_Pens[0]); if (dwStyle & PROG_LARGER_CURRENT) { lh = lh / 2; y += lh / 2; dc.MoveTo(x, y); } } else if (k == nAvailLines) { dc.SelectPen(m_Pens[0]); } if (dwStyle & PROG_GROWING) { double dblNow = (double)k / (double)nLines; lh = (int)(mh * dblNow); y = mh - lh; dc.MoveTo(x, y); } dc.LineTo(x, y + lh); x += gLineDistance; x += gPenWidth; dc.MoveTo(x, y); } }