模拟windows control的进度条

原创 2003年02月13日 10:01:00

<HTML><HEAD>
<TITLE>xyProgressLG xo</TITLE>
<script>
 function xyProgressLG(xyID){
  this.xyProgressID = 'oProgress' + Math.random().toString().substr(2, 10) + xyID;

  this.max = 0;
  this.min = 0;
 
  this.width = 100;
  this.height = 20;
  this.currPos = 0;
  this.outerBorderColor = "black";
  this.outerBackColor = "white";
  this.innerBorderColor = "";
  this.innerBackColor = "blue";
  this.TextColor = "red";

  this.SetProgressTop = xySetProgressTop;
  this.SetProgressLeft = xySetProgressLeft;
  this.SetProgressWidth = xySetProgressWidth;
  this.SetProgressHeight = xySetProgressHeight;
  this.SetProgressBorderColor = xySetProgressBorderColor;
  this.SetProgressForeBorderColor = xySetProgressForeBorderColor;
  this.SetProgressBackColor = xySetProgressBackColor;
  this.SetProgressForeColor = xySetProgressForeColor;
  this.EnableProgressText = xyEnableProgressText;
  this.SetProgressTextFontSize = xySetProgressTextFontSize;
  this.SetProgressTextFontColor = xySetProgressTextFontColor;
  this.SetProgressTextFontFamily = xySetProgressTextFontFamily;

  this.SetProgressMax = xySetProgressMax;
  this.SetProgressMin = xySetProgressMin;
  this.UpdatePosition = xyUpdatePosition;
  this.UpdateToPosition = xyUpdateToPosition;
  this.UpdatePersent = xyUpdatePersent;
  this.UpdateToPersent = xyUpdateToPersent;

  xyProgressInit(this.xyProgressID);
  return this.xyProgressID;
 }
 function xyProgressInit(xyID){
  var div = document.createElement("div");
  div.id = xyID;
  div.style.position = "absolute";
  div.style.left = "100px";
  div.style.top = "100px";
  document.body.appendChild(div);

  var pro = document.createElement("div");
  pro.style.position = "absolute";
  pro.style.left = "0px";
  pro.style.top = "0px";
  pro.style.fontSize= "0px";
  pro.style.width = "100px";
  pro.style.height = "20px";
  pro.style.border = "1px solid black";
  pro.style.background = "white";
  pro.style.zIndex = "100";
  div.appendChild(pro);

  var proInner = document.createElement("div");
  proInner.id = xyID+"_Inner";
  proInner.style.position = "absolute";
  proInner.style.left = "1px";
  proInner.style.top = "1px";
  proInner.style.fontSize= "0px";
  proInner.style.width = "0px";
  proInner.style.height = "16px";
  proInner.style.border = "1px solid black";
  proInner.style.background = "blue";
  pro.style.zIndex = "102";
  pro.appendChild(proInner);

  var text = document.createElement("div");
  text.style.position = "absolute";
  text.style.left = "50px";
  text.style.top = "2px";
  text.style.fontSize= "11px";
  text.style.width = "40px";
  text.style.height = "16px";
  text.style.zIndex = "103";
  div.appendChild(text);
 }
 function xySetProgressTop(pStyleTop){
  try{
   var e = document.all(this.xyProgressID);
   e.style.top = pStyleTop;
  }catch(e){
   alert(e.description);
  }
 }
 function xySetProgressLeft(pStyleLeft){
  try{
   var e = document.all(this.xyProgressID);
   e.style.left = pStyleLeft;
  }catch(e){
   alert(e.description);
  }
 }
 function xySetProgressWidth(pWidth){
  try{
   var e = document.all(this.xyProgressID);
   e.style.width = pWidth;
   eOuter = e.children(0);
   eOuter.style.width = pWidth;
   this.width = pWidth;
  }catch(e){
   alert(e.description);
  }
 }
 function xySetProgressHeight(pHeight){
  try{
   var e = document.all(this.xyProgressID);
   e.style.height = pHeight;
   eOuter = e.children(0);
   eInner = e.children(0).children(0);
   eOuter.style.height = pHeight;
   eInner.style.height = pHeight-4;
   this.height = pHeight;
  }catch(e){
   alert(e.description);
  }
 }
 function xySetProgressBorderColor(pColor){
  try{
   var e = document.all(this.xyProgressID);
   e = e.children(0);
   e.style.border = "1px solid "+pColor;
  }catch(e){
   alert(e.description);
  }
 }
 function xySetProgressForeBorderColor(pColor){
  try{
   var e = document.all(this.xyProgressID);
   e = e.children(0).children(0);
   e.style.border = "1px solid "+pColor;
  }catch(e){
   alert(e.description);
  }
 }
 function xySetProgressBackColor(pColor){
  try{
   var e = document.all(this.xyProgressID);
   e = e.children(0);
   e.style.background = pColor;
  }catch(e){
   alert(e.description);
  }
 }
 function xySetProgressForeColor(pColor){
  try{
   var e = document.all(this.xyProgressID);
   e = e.children(0).children(0);
   e.style.background = pColor;
  }catch(e){
   alert(e.description);
  }
 }
 function xyEnableProgressText(bEnable){
  try{
   var e = document.all(this.xyProgressID);
   eText = e.children(1);
   if(bEnable){
    eText.style.display = "none";
   }else{
    eText.style.display = "";
   }
   var pos = e.style.width;
   var sel = eText.style.width;
   pos = (pos-sel)/2;
   eText.style.left = pos;
  }catch(e){
   alert(e.description);
  }
 }
 function xySetProgressTextFontSize(pSize){
  try{
   var e = document.all(this.xyProgressID);
   e = e.children(1);
   e.style.fontSize = pSize;
  }catch(e){
   alert(e.description);
  }
 }
 function xySetProgressTextFontColor(pColor){
  try{
   var e = document.all(this.xyProgressID);
   e = e.children(1);
   e.style.fontColor = pColor;
  }catch(e){
   alert(e.description);
  }
 }
 function xySetProgressTextFontFamily(pFamily){
  try{
   var e = document.all(this.xyProgressID);
   e = e.children(1);
   e.style.fontFamily = pFamily;
  }catch(e){
   alert(e.description);
  }
 }
 function xySetProgressMax(pMax){
  this.max = pMax;
 }
 function xySetProgressMin(pMin){
  this.min = pMin;
 }
 function xyUpdatePosition(pPosition){   /*将progress增长或减小pPosition,其中,0<pPersent<max*/
  try{
   var max = this.max;
   var min = this.min;
   var e = document.all(this.xyProgressID);
   if(pPosition>max){
    return -1;
   }
   var len = this.width;
   var pos = this.currPos+(pPosition/(max-min))*len;
   eProgress = e.children(0).children(0);
   if(pos>=this.width){
    eProgress.style.width = this.width-4;
    this.currPos = pos;
   }else if(pos<=0){
    eProgress.style.width = 0;
    this.currPos = pos;
   }else{
    eProgress.style.width = pos;
    this.currPos = pos;
   }
   return this.currPos;
  }catch(e){
   alert(e.description);
   return -1;
  }
 }
 function xyUpdateToPosition(pPosition){   /*将progress更新到pPosition位置,其中,min<pPersent<max*/
  try{
   var max = this.max;
   var min = this.min;
   var e = document.all(this.xyProgressID);
   if(pPosition<min||pPosition>max){
    return -1;
   }
   var len = this.width;
   var pos = ((pPosition-min)/(max-min))*len;
   eProgress = e.children(0).children(0);
   if(pos>=this.width){
    eProgress.style.width = this.width-4;
    this.currPos = pos;
   }else if(pos<=0){
    eProgress.style.width = 0;
    this.currPos = pos;
   }else{
    eProgress.style.width = pos;
    this.currPos = pos;
   }
   return this.currPos;
  }catch(e){
   alert(e.description);
   return -1;
  }
 }
 function xyUpdatePersent(pPersent){   /*从当前位置增长或减小pPersent%,pPersent大于零:增长,否则,减小*/
  try{
   var e = document.all(this.xyProgressID);
   e = e.children(0).children(0);
   var len = this.width;
   var pos = this.currPos;
   len = len*pPersent/100;
   pos += len;
   if(pos>this.width||pos<0){
    return -1;
   }
   e.style.width = pos;
   this.currPos = pos;
   return this.currPos;
  }catch(e){
   alert(e.description);
   return -1;
  }
 }
 function xyUpdateToPersent(pPersent){   /*从当前位置增长或减小到pPersent%*/
  try{
   var e = document.all(this.xyProgressID);
   e = e.children(0).children(0);
   var len = this.width;
   var pos = len*pPersent/100;
   if(pos>this.width||pos<0){
    return -1;
   }
   e.style.width = pos;
   this.currPos = pos;
   return this.currPos;
  }catch(e){
   alert(e.description);
   return -1;
  }
 }

 function xyNewID(){
  var d = new Date();
  var t = "oDraw_"+d.getTime().toString();
  return t;
 }
</script>
</HEAD>
<body topmargin=0 id="bodyID">
<script>
 var xy = new xyProgressLG("kitty");
 xy.SetProgressLeft(200)
 xy.SetProgressTop(200);
 xy.SetProgressWidth(200)
 xy.SetProgressHeight(20)
 xy.SetProgressMax(200)
 xy.SetProgressMin(50);

 
</script>
<Script LANGUAGE="JavaScript">
function update(){
 xy.UpdatePosition(10)
 setTimeout("update()",100);
}

</Script>
<button onclick="xy.UpdateToPersent(20)">update</button>
<button onclick="xy.UpdatePosition(10)">updatePosition</button>
<button onclick="update()">autoUpdate</button>
</BODY>
</HTML>

javascript模拟windows control的进度条

xyProgressLG xo function xyProgressLG(xyID){  this.xyProgressID = oProgress + Math.random().toString...
  • menjoy
  • menjoy
  • 2006年12月23日 22:17
  • 456

模拟进度条

本文通过编写模拟进度条程序来记录一些知识点,进度条始终在同一行显示,且不断的增加打印*个数以表示进度增加,程序如下: 1 #include 2 3 void display_pr...
  • wustzjf
  • wustzjf
  • 2015年10月10日 14:43
  • 681

模拟实现进度条

实现进度条的代码: Makefile 运行效果图: 进度条原理: 缓冲区: 回车换行:...
  • lishitao_578
  • lishitao_578
  • 2017年02月17日 09:40
  • 349

控制台实现进度条

#include "stdio.h" #include #include int g_iCnt = 0; int l_iSum = 10000; HANDLE hSemaphore; voi...
  • qq229596421
  • qq229596421
  • 2017年01月13日 18:57
  • 231

VS2013 Progress Control控件实现进度条

1.资源视图下新建资源Dialog,并为对话框添加类,设置类名为ProgDlg.在类ProgDlg中添加消息WM_TIMER,并点击编辑代码。 2.在对话框内拖动添加控件Progre...
  • BCD_not_CBD
  • BCD_not_CBD
  • 2016年07月20日 17:29
  • 2536

Android Handler模拟进度条更新

Handler是Android提供的消息处理类,可用于异步消息的处理,Handler关联了两个队列,一个是消息队列,里面顺序的存放消息对象(Message对象),另一个是存放实现了Runnabler接...
  • yezhouyong
  • yezhouyong
  • 2016年05月07日 16:46
  • 1821

MFC_Process control 进度条

MFC class : CProgressCtrl 中文名:进度条 成员函数: GetPos() SetPos() GetRange32() ...
  • qq_35508344
  • qq_35508344
  • 2017年09月25日 18:52
  • 181

MFC-ProgressControl(进度条)

效果如图: 首先在初始化对话框中设置进度条的范围和初始位置:CProgressCtrl* pProg = (CProgressCtrl*)GetDlgItem(IDC_PROGRESS); ...
  • qq_18297675
  • qq_18297675
  • 2016年03月25日 17:41
  • 3188

dos模拟进度条显示

@echo off mode con cols=90 lines=30&color 9f cls echo. echo 程序正在初始化. . . echo. echo ┌───────────...
  • agoago_2009
  • agoago_2009
  • 2012年10月15日 19:24
  • 871

【转】进度条的使用(设置值,改变颜色)

================设置值,参考以下:http://topic.csdn.net/t/20040821/18/3297045.htmlZT: (一)进度条的主要功能 进度条控制(Progr...
  • gengxt2003
  • gengxt2003
  • 2010年06月21日 16:20
  • 3147
内容举报
返回顶部
收藏助手
不良信息举报
您举报文章:模拟windows control的进度条
举报原因:
原因补充:

(最多只允许输入30个字)