2010年2月10日
代码
1 int nRange = m_nRangeMax - m_nRangeMin;
2 CRect rcClient;
3
4 if( nRange > 0 && m_hBkPic )
5 {
6 int nOldBkMode = GetBkMode( lpDrawItemStruct->hDC );
7 COLORREF cOldColor = GetTextColor( lpDrawItemStruct->hDC );
8
9 GetWindowRect( rcClient );
10 GetParent( )->ScreenToClient( rcClient );
11
12 HDC hBkDC = CreateCompatibleDC( lpDrawItemStruct->hDC );
13 HGDIOBJ hOldBmp = SelectObject( hBkDC, m_hBkPic );
14
15 // 擦除
16 BitBlt( lpDrawItemStruct->hDC, 0, 0, rcClient.Width( ),
17 rcClient.Height( ), hBkDC, rcClient.left, rcClient.top, SRCCOPY );
18
19 int nPosX = rcClient.Width( ) * (float)m_nCurPos / (float)nRange;
20 if( !m_hProgressFr )
21 {
22 // 自己填充颜色
23 CDC* pDC = CDC::FromHandle(lpDrawItemStruct->hDC);
24 CBrush br;
25 br.CreateHatchBrush( HS_CROSS, m_crProgressColor);
26 pDC->FillRect( CRect( 0, 0, nPosX, rcClient.Height( ) ), &br );
27 }
28
29 GetClientRect( rcClient );
30
31 CString strName;
32 strName.Format( "%d%%", (int)((float)m_nCurPos / (float)nRange * 100) );
33 SetBkMode( lpDrawItemStruct->hDC, TRANSPARENT );
34 SetROP2( lpDrawItemStruct->hDC, R2_BLACK );
35
36 if( m_hProgressFr )
37 {
38 SelectObject( hBkDC, m_hProgressFr );
39 // BitBlt( lpDrawItemStruct->hDC, 0, 0, nPosX, rcClient.Height( ), hBkDC, 0, 0, SRCERASE ); //
40 BitBlt( lpDrawItemStruct->hDC, 0, 0, nPosX, rcClient.Height( ), hBkDC, 0, 0, SRCCOPY ); //
41 }
42
43 OffsetRect( rcClient, 1, 1 );
44 SetTextColor( lpDrawItemStruct->hDC, RGB( 0, 0, 0 ) );
45 DrawText( lpDrawItemStruct->hDC, strName, strName.GetLength( ), rcClient, DT_CENTER | DT_VCENTER | DT_SINGLELINE );
46 OffsetRect( rcClient, -1, -1 );
47 SetTextColor( lpDrawItemStruct->hDC, RGB( 200, 200, 0 ) );
48 DrawText( lpDrawItemStruct->hDC, strName, strName.GetLength( ), rcClient, DT_CENTER | DT_VCENTER | DT_SINGLELINE );
49
50
51 SetBkMode( lpDrawItemStruct->hDC, nOldBkMode );
52 SetTextColor( lpDrawItemStruct->hDC, cOldColor );
53
54 SelectObject( hBkDC, hOldBmp );
55 DeleteDC( hBkDC );
56 }
2 CRect rcClient;
3
4 if( nRange > 0 && m_hBkPic )
5 {
6 int nOldBkMode = GetBkMode( lpDrawItemStruct->hDC );
7 COLORREF cOldColor = GetTextColor( lpDrawItemStruct->hDC );
8
9 GetWindowRect( rcClient );
10 GetParent( )->ScreenToClient( rcClient );
11
12 HDC hBkDC = CreateCompatibleDC( lpDrawItemStruct->hDC );
13 HGDIOBJ hOldBmp = SelectObject( hBkDC, m_hBkPic );
14
15 // 擦除
16 BitBlt( lpDrawItemStruct->hDC, 0, 0, rcClient.Width( ),
17 rcClient.Height( ), hBkDC, rcClient.left, rcClient.top, SRCCOPY );
18
19 int nPosX = rcClient.Width( ) * (float)m_nCurPos / (float)nRange;
20 if( !m_hProgressFr )
21 {
22 // 自己填充颜色
23 CDC* pDC = CDC::FromHandle(lpDrawItemStruct->hDC);
24 CBrush br;
25 br.CreateHatchBrush( HS_CROSS, m_crProgressColor);
26 pDC->FillRect( CRect( 0, 0, nPosX, rcClient.Height( ) ), &br );
27 }
28
29 GetClientRect( rcClient );
30
31 CString strName;
32 strName.Format( "%d%%", (int)((float)m_nCurPos / (float)nRange * 100) );
33 SetBkMode( lpDrawItemStruct->hDC, TRANSPARENT );
34 SetROP2( lpDrawItemStruct->hDC, R2_BLACK );
35
36 if( m_hProgressFr )
37 {
38 SelectObject( hBkDC, m_hProgressFr );
39 // BitBlt( lpDrawItemStruct->hDC, 0, 0, nPosX, rcClient.Height( ), hBkDC, 0, 0, SRCERASE ); //
40 BitBlt( lpDrawItemStruct->hDC, 0, 0, nPosX, rcClient.Height( ), hBkDC, 0, 0, SRCCOPY ); //
41 }
42
43 OffsetRect( rcClient, 1, 1 );
44 SetTextColor( lpDrawItemStruct->hDC, RGB( 0, 0, 0 ) );
45 DrawText( lpDrawItemStruct->hDC, strName, strName.GetLength( ), rcClient, DT_CENTER | DT_VCENTER | DT_SINGLELINE );
46 OffsetRect( rcClient, -1, -1 );
47 SetTextColor( lpDrawItemStruct->hDC, RGB( 200, 200, 0 ) );
48 DrawText( lpDrawItemStruct->hDC, strName, strName.GetLength( ), rcClient, DT_CENTER | DT_VCENTER | DT_SINGLELINE );
49
50
51 SetBkMode( lpDrawItemStruct->hDC, nOldBkMode );
52 SetTextColor( lpDrawItemStruct->hDC, cOldColor );
53
54 SelectObject( hBkDC, hOldBmp );
55 DeleteDC( hBkDC );
56 }