如何改变进度条的颜色?

sailing 2000-06-15 09:37:00
加精
诸位高手:
我需要随进度条位置的改变而改变它的颜色,如何实现?
望不吝赐教 ,多谢。
suandy@sohu.com
...全文
925 7 打赏 收藏 转发到动态 举报
写回复
用AI写文章
7 条回复
切换为时间正序
请发表友善的回复…
发表回复
ZPoint 2000-06-24
  • 打赏
  • 举报
回复
void CJMed_ProgressCtrl::OnPaint()
{
CPaintDC dc(this); // device context for painting

// TODO: Add your message handler code here

// If the current positionis invalid then we should fade into the background
if (m_nCurrentPosition <= m_nLower || m_nCurrentPosition > m_nUpper)
{
CRect rect;
GetClientRect(rect);
CBrush brush;
brush.CreateSolidBrush(::GetSysColor(COLOR_3DFACE));
dc.FillRect(&rect, &brush);
VERIFY(brush.DeleteObject());
return;
}


// Figure out what part should be visible so we can stop the gradient when needed
CRect rectClient;
GetClientRect(&rectClient);
float maxWidth((float)m_nCurrentPosition/(float)m_nUpper * (float)rectClient.right);


// Draw the gradient
DrawGradient(&dc, rectClient, (int)maxWidth);

// Show percent indicator if needed
if (m_bShowPercent)
{
CString percent;
percent.Format("%.0f%%", 100.0f*(float)m_nCurrentPosition/(float)m_nUpper);
dc.SetTextColor(m_clrText);
dc.SetBkMode(TRANSPARENT);
dc.DrawText(percent, &rectClient, DT_VCENTER | DT_CENTER | DT_SINGLELINE);
}

// Do not call CProgressCtrl::OnPaint() for painting messages
}


如果需要更具体的资料,可以给我MAIL:softwonder@citiz.net
sailing 2000-06-19
  • 打赏
  • 举报
回复
多谢Un1!不好意思(惭愧)我没用过VB,我想知道在VC 中如何实现。
再次感谢Un1
sailing 2000-06-16
  • 打赏
  • 举报
回复
我就是从通用的进度条继承的,我定义了CtlColor函数处理=WM——CTLCOLOR句柄,但是
我跟踪发现它并不被执行。。。。有什么问题吗?
多谢
WHQ 2000-06-16
  • 打赏
  • 举报
回复
如果要完全模拟通用的进度条,那就从它继承,如果想定义自己的控制消息与行为,那可从最简单的CWnd继承(这会稍麻烦,你可参照VC中其它控件类的源码来写)
sailing 2000-06-16
  • 打赏
  • 举报
回复
继承一个什么样的控件?你能举个例子吗?
我想做成window volume control 那样。
Un1 2000-06-16
  • 打赏
  • 举报
回复
进度条实际上是很简单的部件,自己完全写代码也不复杂,比如(VB):

'progressbar.ctl

VERSION 5.00
Begin VB.UserControl Progressbar
Alignable = -1 'True
CanGetFocus = 0 'False
ClientHeight = 3600
ClientLeft = 0
ClientTop = 0
ClientWidth = 4800
ScaleHeight = 3600
ScaleWidth = 4800
End
Attribute VB_Name = "Progressbar"
Attribute VB_GlobalNameSpace = False
Attribute VB_Creatable = True
Attribute VB_PredeclaredId = False
Attribute VB_Exposed = True
Option Explicit

Const MYNAME = "Progress"

Private lngWidth As Long
Private lngHeight As Long
Private lngTextHeight As Long

Private m_Format As String
Private m_Value As Double


Private Sub UserControl_Initialize()
With UserControl
.ForeColor = &H8000000D
.DrawMode = 10
.BorderStyle = 1
End With
lngTextHeight = TextHeight("%")

m_Format = "#0%"

End Sub

Public Property Get Value() As Long
Attribute Value.VB_MemberFlags = "200"
Value = m_Value * 100
End Property
Public Property Let Value(ByVal New_Value As Long)
If New_Value < 0 Or New_Value > 100 Then
Err.Raise 380, MYNAME
End If
m_Value = New_Value / 100

UserControl_Paint
End Property

Public Property Get FormatString() As String
FormatString = m_Format
End Property
Public Property Let FormatString(ByVal New_Format As String)
m_Format = New_Format
Refresh
End Property

Private Sub UserControl_Paint()
On Error Resume Next

Cls

Dim strPercent As String
strPercent = Format$(m_Value, m_Format)

CurrentX = (lngWidth - TextWidth(strPercent)) / 2
CurrentY = (lngHeight - lngTextHeight) / 2
Print strPercent

Line (0, 0)-(lngWidth * m_Value, lngHeight), ForeColor, BF
End Sub

Private Sub UserControl_Resize()
On Error Resume Next

lngWidth = ScaleWidth
lngHeight = ScaleHeight
End Sub
WHQ 2000-06-15
  • 打赏
  • 举报
回复
只能自己继承一个或采用OWNER_DRAW

16,471

社区成员

发帖
与我相关
我的任务
社区描述
VC/MFC相关问题讨论
社区管理员
  • 基础类社区
  • Web++
  • encoderlee
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

        VC/MFC社区版块或许是CSDN最“古老”的版块了,记忆之中,与CSDN的年龄几乎差不多。随着时间的推移,MFC技术渐渐的偏离了开发主流,若干年之后的今天,当我们面对着微软的这个经典之笔,内心充满着敬意,那些曾经的记忆,可以说代表着二十年前曾经的辉煌……
        向经典致敬,或许是老一代程序员内心里面难以释怀的感受。互联网大行其道的今天,我们期待着MFC技术能够恢复其曾经的辉煌,或许这个期待会永远成为一种“梦想”,或许一切皆有可能……
        我们希望这个版块可以很好的适配Web时代,期待更好的互联网技术能够使得MFC技术框架得以重现活力,……

试试用AI创作助手写篇文章吧