找回密码
 注册
搜索
[新手上路]批处理新手入门导读[视频教程]批处理基础视频教程[视频教程]VBS基础视频教程[批处理精品]批处理版照片整理器
[批处理精品]纯批处理备份&还原驱动[批处理精品]CMD命令50条不能说的秘密[在线下载]第三方命令行工具[在线帮助]VBScript / JScript 在线参考
楼主: ygqiang

[系统相关] [已解决]hta代码,如何根据显示器屏幕尺寸/分辨率智能调整文字的位置和大小?

[复制链接]
发表于 2016-3-17 23:27:09 | 显示全部楼层
回复  ygqiang


    你到底有没有看 5 楼链接?他发的东西都已经写得那么清楚了
CrLf 发表于 2016-3-17 21:18


    网上现成的例子也有,缩放网页字体:
  1. www.jq22.com/demo/286f2b4a-484c-11e4-b680-00163e001348/
复制代码
发表于 2016-3-18 00:20:06 | 显示全部楼层
楼主的代码…
我有强迫症。
  1. <HTA:APPLICATION ID="screen"
  2.         APPLICATIONNAME="myApp1"
  3.         contextMenu ="no"
  4.         BORDER="none"
  5.         innerBorder="no"
  6.         SHOWINTASKBAR="yes"
  7.         SINGLEINSTANCE="yes"
  8.         SYSMENU="no"
  9.         VERSION="1.0"
  10.         WINDOWSTATE="maximize"
  11.         ICON="taskmgr.exe"
  12.         />

  13. <html lang="cn">
  14. <head>
  15. <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
  16. <script language="JavaScript" type="text/javascript">
  17.         function changeFontSize() {
  18.                 var w = document.body.clientWidth;
  19.                 var h = document.body.clientHeight;
  20.                 var size = w/3; size2 = w/9;
  21.                 if (w > 2000) {
  22.                         size = w/3;
  23.                 } else  {
  24.                         size = w/3;
  25.                 }
  26.                 document.getElementById("curtime").style.fontSize = "" + size + "px";
  27.                 document.getElementById("cursec").style.fontSize = "" + size2 + "px";
  28.                 document.getElementById("curdate").style.fontSize = "" + size2 + "px";
  29.                 document.getElementById("curweek").style.fontSize = "" + size2 + "px";
  30.         }
  31.        
  32.         function SetTimeText() {
  33.                 var dt1=new Date();
  34.                 document.getElementById("curtime").innerHTML = dt1.getHours() + ":" + ("00" + dt1.getMinutes()).slice(-2);
  35.                 document.getElementById("cursec").innerHTML = ("00" + dt1.getSeconds()).slice(-2);
  36.                 document.getElementById("curdate").innerHTML= dt1.getMonth() + "-" + dt1.getDate();
  37.                 document.getElementById("curweek").innerHTML = "周" + "日一二三四五六".substr(dt1.getDay(), 1);
  38.         }

  39.         window.onload = function(){
  40.                 SetTimeText();
  41.                 changeFontSize();
  42.                 setInterval(SetTimeText, 500);
  43.                 setInterval(changeFontSize, 1000);
  44.         };
  45.        
  46.         function closeWindow() {
  47.                 try {
  48.                         var Shell = new ActiveXObject("Shell.Application");
  49.                         Shell = null;
  50.                         window.close();
  51.                 } catch(e) {}
  52.         }
  53. </script>
  54. <style type="text/css">
  55.         strong {display: inline}
  56. </style>
  57. </head>
  58. <body bgcolor="#000000" bordercolor="#000000" scroll="no" onclick="closeWindow()" onkeyup="closeWindow()">
  59.         <table style="width:100%; height:100%; text-align:center">
  60.                 <tr>
  61.                         <td>
  62.                                 <strong id=curtime style="font-size:400px;color:#ffffff;font-family:黑体" /></strong>
  63.                                 <strong id=cursec style="font-size:50px;color:#ffffff;margin-left: 8px;"/></strong><br/>
  64.                                 <strong id=curdate style="font-size:50px;color:#ffffff;font-family:黑体;margin-left: 50px;" /></strong>
  65.                                 <strong id=curweek style="font-size:50px;color:#ffffff;font-family:黑体;margin-left: 50px;" /></strong>
  66.                         </td>
  67.                 </tr>
  68.         </table>
  69. </body>
  70. </html>
复制代码

评分

参与人数 1技术 +1 收起 理由
CrLf + 1 强迫症

查看全部评分

 楼主| 发表于 2016-3-18 06:41:56 | 显示全部楼层
回复 17# yu2n


    你这代码,星期不显示。。。只显示3个框框
发表于 2016-3-19 11:32:17 | 显示全部楼层
刚刚写的,试试吧。

Timer & Color
http://7i7hsj.com1.z0.glb.clouddn.com/ColorTimer.html
 楼主| 发表于 2016-3-19 13:03:23 | 显示全部楼层
回复 19# yu2n


    多谢。。

你这个有几个小问题。
1、IE提示有限制。每次都要用鼠标点击下:运行阻止的内容。才能继续运行。
2、颜色不够鲜艳。最好是黑色背景/白色数字
3、不能全屏显示。除了时间/日期/星期,其他按钮、按键啥的都不显示。
4、时间/日期/星期,字体大小。根据显示器大小/分辨率高低,自动缩小放大。
  1. <script language=vbscript>
  2. For Each Proc In GetObject("winmgmts:\\.\root\cimv2").ExecQuery("Select * from Win32_Process Where Name = 'mshta.exe'")
  3. if instr(Proc.commandline,location.pathname) then
  4. if proc.Priority>9 then  '检查进程优先级是否为设置值10,是则为已运行的原进程
  5.     if  msgbox("程序已运行, 重新运行请按确认!", VbOK+vbInformation)<>1 then window.close() else Proc.Terminate
  6.   else proc.SetPriority(32768)'64低 16384低于标准 32标准 32768高于标准 128高 256高(实时?)
  7.   end if
  8. end if
  9. Next
  10. </script>

  11. <script language=vbscript>
  12. RecTimer=Window.setInterval("PausedSection(0)",500)  //  window.clearInterval(RecTimer)  

  13. function  PausedSection(rush)
  14.          ON Error resume Next         
  15. changeFontSize
  16. document.getElementById("curtime").innertext=Hour(Now)&":"&right("0"&Minute(Now),2)
  17. document.getElementById("cursec").innertext=right("0"&Second(Now),2)
  18. document.getElementById("curdate").innertext=Month(Now)&"-"&day(Now)
  19. document.getElementById("curweek").innertext="周"& mid("日一二三四五六",Weekday(Now),1)
  20. End function
  21. </script>
  22. <script language="JavaScript" type="text/javascript">
  23.     function changeFontSize() {
  24.         var w = document.body.clientWidth /1.5
  25.         //var h = document.body.clientHeight
  26.         var size = w/1.8;
  27.         if (w > 2000) {
  28.             size = w/1.8;
  29.         } else  {
  30.             size = w/1.8;
  31.         }
  32.         document.getElementById("curtime").style.fontSize = ""+size+"px";
  33.         var size2 = w/9;var size3 = w/5;
  34.         document.getElementById("cursec").style.fontSize = "" + size2 + "px";
  35.         document.getElementById("curdate").style.fontSize = "" + size2 + "px";
  36.         document.getElementById("curweek").style.fontSize = "" + size3 + "px";
  37.     }
  38.     //setInterval( changeFontSize,100);
  39. </script>

  40. <body   bgcolor=#000000 bordercolor=#000000 >
  41.     <table style="width:100%; height:100%; text-align:center">
  42.         <tr>
  43.             <td>
  44. <strong><a id=curtime style="font-size:800px;color:#ffffff;font-family:黑体" /><p></strong>
  45. <strong><a id=curdate style="font-size:100px;color:#ffffff;font-family:黑体;margin-left: 2px;" /></strong>
  46. <strong><a id=curweek style="font-size:100px;color:#ffffff;font-family:黑体;margin-left: 100px;" /></strong>
  47.             </td>
  48.         </tr>
  49.     </table>



  50. <body scroll=no bgcolor=#000000 bordercolor=#000000 onclick=window.close() onkeyup=window.close()>

  51. <HTA:APPLICATION ID="screen"
  52.         APPLICATIONNAME="myApp123"
  53.         contextMenu ="no"
  54.         BORDER="none"
  55.         innerBorder="no"
  56.         CAPTION="no"
  57.         maximizebutton="yes"
  58.         minimizebutton="yes"
  59.         SHOWINTASKBAR="yes"
  60.         SINGLEINSTANCE="yes"
  61.         SYSMENU="no"
  62.         VERSION="1.0"
  63.         WINDOWSTATE="maximize"
  64.         ICON="taskmgr.exe"
  65.         />
复制代码
发表于 2016-3-19 15:14:24 | 显示全部楼层
回复 20# ygqiang


    IE下面的 split() 有个BUG, 与chrome不一致:
  1. console.log('rgb(1, 2, 3)'.split(/\D+/).join(', '));
复制代码
所以导致了出错。改用 match 方法就可以了。

试试:
http://7i7hsj.com1.z0.glb.clouddn.com/ColorTimer1.html
发表于 2016-3-19 15:54:54 | 显示全部楼层
回复 21# yu2n


    什么版本的IE?IE9的运行结果是:日志: ,1,2,3,
发表于 2016-3-19 16:09:13 | 显示全部楼层
回复 22# CrLf


    Windows 7 x64 IE8.0
  1. >>console.log('rgb(1, 2, 3)'.split(/\D+/).join(', '));
  2. 日志: 1, 2, 3
复制代码
 楼主| 发表于 2016-3-19 19:05:17 | 显示全部楼层
回复 21# yu2n


    http://7i7hsj.com1.z0.glb.clouddn.com/ColorTimer1.html

你好。非常感谢。请教2个小问题。
1、win7 64系统,IE9 浏览器。这个网页源代码,保存成1.hta。为啥不显示:星期?
2、winxp系统,IE8浏览器。弹出错误提示窗口。
  1. <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
  2. <HTA:APPLICATION ID="screen"
  3.         APPLICATIONNAME="myApp1"
  4.         contextMenu ="no"
  5.         BORDER="none"
  6.         innerBorder="no"
  7.         SHOWINTASKBAR="yes"
  8.         SINGLEINSTANCE="yes"
  9.         SYSMENU="no"
  10.         VERSION="1.0"
  11.         WINDOWSTATE="maximize"
  12.         ICON="taskmgr.exe"
  13.         />
  14. <html lang="cn">
  15. <head>
  16. <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
  17. <title>Timer & Color</title>
  18. <script language="JavaScript" type="text/javascript">
  19. /**
  20. * HSL颜色值转换为RGB.
  21. * 换算公式改编自 http://en.wikipedia.org/wiki/HSL_color_space.
  22. * h, s, 和 l 设定在 [0, 1] 之间
  23. * 返回的 r, g, 和 b 在 [0, 255]之间
  24. *
  25. * @param   Number  h       色相
  26. * @param   Number  s       饱和度
  27. * @param   Number  l       亮度
  28. * @return  Array           RGB色值数值
  29. */
  30. function hslToRgb(h, s, l){
  31.         var r, g, b;

  32.         if(s == 0){
  33.                 r = g = b = l; // achromatic
  34.         }else{
  35.                 var hue2rgb = function hue2rgb(p, q, t){
  36.                         if(t < 0) t += 1;
  37.                         if(t > 1) t -= 1;
  38.                         if(t < 1/6) return p + (q - p) * 6 * t;
  39.                         if(t < 1/2) return q;
  40.                         if(t < 2/3) return p + (q - p) * (2/3 - t) * 6;
  41.                         return p;
  42.                 }

  43.                 var q = l < 0.5 ? l * (1 + s) : l + s - l * s;
  44.                 var p = 2 * l - q;
  45.                 r = hue2rgb(p, q, h + 1/3);
  46.                 g = hue2rgb(p, q, h);
  47.                 b = hue2rgb(p, q, h - 1/3);
  48.         }

  49.         return [Math.round(r * 255), Math.round(g * 255), Math.round(b * 255)];
  50. }


  51. /**
  52. * RGB 颜色值转换为 HSL.
  53. * 转换公式参考自 http://en.wikipedia.org/wiki/HSL_color_space.
  54. * r, g, 和 b 需要在 [0, 255] 范围内
  55. * 返回的 h, s, 和 l 在 [0, 1] 之间
  56. *
  57. * @param   Number  r       红色色值
  58. * @param   Number  g       绿色色值
  59. * @param   Number  b       蓝色色值
  60. * @return  Array           HSL各值数组
  61. */
  62. function rgbToHsl(r, g, b){
  63.         r /= 255, g /= 255, b /= 255;
  64.         var max = Math.max(r, g, b), min = Math.min(r, g, b);
  65.         var h, s, l = (max + min) / 2;

  66.         if(max == min){
  67.                 h = s = 0; // achromatic
  68.         }else{
  69.                 var d = max - min;
  70.                 s = l > 0.5 ? d / (2 - max - min) : d / (max + min);
  71.                 switch(max){
  72.                         case r: h = (g - b) / d + (g < b ? 6 : 0); break;
  73.                         case g: h = (b - r) / d + 2; break;
  74.                         case b: h = (r - g) / d + 4; break;
  75.                 }
  76.                 h /= 6;
  77.         }

  78.         return [h, s, l];
  79. }

  80. //RGB转HEX
  81. function rgb2hex(rgb) {
  82.         if (rgb.charAt(0) == '#') return rgb;
  83.         function zero_fill_hex(num, digits) {
  84.                 var s = num.toString(16);
  85.                 while (s.length < digits) s = "0" + s;
  86.                 return s;
  87.         };
  88.         if (/rgb\(\d+, \d+, \d+\)/.test(rgb)) {
  89.                 var ds = rgb.match(/\d+/g);;
  90.                 var decimal = Number(ds[0]) * 65536 + Number(ds[1]) * 256 + Number(ds[2]);
  91.                 return "#" + zero_fill_hex(decimal, 6);
  92.         };
  93. }

  94. //改变色调
  95. var HueSign = [];        //色调符号
  96. function changColor(obj,uuid,type,step) {
  97.         if (!HueSign[uuid]) HueSign[uuid] = 1;
  98.         var rgb = obj.style[type];
  99.         var hex = (rgb2hex(rgb)).substring(1);
  100.         var r = parseInt("0x" + hex.substr(0,2));
  101.         var g = parseInt("0x" + hex.substr(2,2));
  102.         var b = parseInt("0x" + hex.substr(4,2));
  103.         var hsl = rgbToHsl(r,g,b);
  104.         var h = Math.round(hsl[0] * 2400)/10;
  105.         var s = Math.round(hsl[1] * 2400)/10;
  106.         var l = Math.round(hsl[2] * 2400)/10;
  107.         h = h + HueSign[uuid] * step * 1;        //修改色调
  108.         if (h <= 0 || h >= 240) HueSign[uuid] = -1 * HueSign[uuid];
  109.         if (h <= 0) h = 0;
  110.         if (h >= 240) h = 240;
  111.         var rgb = hslToRgb(h/240, s/240, l/240);
  112.         hex = rgb2hex('rgb(' + rgb.join(', ') + ')');
  113.         obj.style[type] = hex;
  114.         return(true);
  115. }
  116. </script>
  117. <script language="JavaScript" type="text/javascript">
  118. //设置字体大小位置
  119. var LastSize = [];        //记录最后的大小
  120. function changeFontSize() {

  121.         var w = document.documentElement.clientWidth;
  122.         var h = document.documentElement.clientHeight;
  123.         if ((LastSize['Width'] != w) || (LastSize['Height'] != h)) {
  124.                 LastSize['Width'] = w;
  125.                 LastSize['Height'] = h;
  126.                
  127.                 var size = w/100;
  128.                 document.getElementById("curtime").style.fontSize = "" + parseInt(size * 35) + "px";
  129.                 document.getElementById("cursec").style.fontSize = "" + parseInt(size * 10) + "px";
  130.                 document.getElementById("curdate").style.fontSize = "" + parseInt(size * 15) + "px";
  131.                 document.getElementById("curweek").style.fontSize = "" + parseInt(size * 15) + "px";
  132.                
  133.                 var center = document.getElementById("center");
  134.                 center.style.left = (w - center.clientWidth)/2 + "px";
  135.                 center.style.top = (h - center.clientHeight)/2 + "px";
  136.         }
  137. }

  138. //显示时间
  139. function SetTimeText() {
  140.         var dt1=new Date();
  141.         document.getElementById("curtime").innerHTML = dt1.getHours() + ":" + ("00" + dt1.getMinutes()).slice(-2);
  142.         document.getElementById("cursec").innerHTML = ("00" + dt1.getSeconds()).slice(-2);
  143.         document.getElementById("curdate").innerHTML= dt1.getMonth() + "-" + dt1.getDate();
  144.         document.getElementById("curweek").innerHTML = "周" + "日一二三四五六".substr(dt1.getDay(), 1);
  145. }

  146. window.onload = function(){
  147.        
  148.         //关闭窗口(HTA)
  149.         function closeWindow() {
  150.                 try {
  151.                         var Shell = new ActiveXObject("Shell.Application");
  152.                         Shell = null;
  153.                         window.close();
  154.                 } catch(e) {}
  155.         }
  156.         document.body.onclick = function(){ closeWindow(); };
  157.         document.body.onkeyup = function(){ closeWindow(); };
  158.        
  159.         //显示时间
  160.         SetTimeText();
  161.         changeFontSize();
  162.         setInterval(function(){
  163.                 SetTimeText();
  164.                 changeFontSize();
  165.         }, 500);
  166.        
  167.         //修改颜色
  168.         document.body.style['backgroundColor'] = '#336699';
  169.         document.body.style['color'] = '#FFFFFF';
  170.         setInterval(function(){
  171.                 //changColor(document.body, 'body::color', 'color', 1);
  172.                 changColor(document.body, 'body::backgroundColor', 'backgroundColor', 1);
  173.         }, 50);
  174. };


  175. </script>
  176. <style type="text/css">
  177.         #center {position: absolute; }
  178.         #center strong {display: inline; padding: 2%; font-family:SimHei,"Microsoft YaHei","Microsoft JhengHei",DFKai-SB,SimSun;}
  179. </style>
  180. </head>
  181. <body scroll="no">
  182.     <div id='center'>
  183.                 <strong id="curtime" /></strong><strong id="cursec" /></strong>
  184.                 <br/>
  185.                 <center><strong id="curdate" /></strong><strong id="curweek" /></strong></center>
  186.     </div>       
  187. </body>
  188. </html>
复制代码

评分

参与人数 1PB -30 收起 理由
pcl_test -30 已有链接,勿重复贴码

查看全部评分

发表于 2016-3-19 21:44:20 | 显示全部楼层
回复 24# ygqiang

编码不对应
 楼主| 发表于 2016-3-19 21:51:45 | 显示全部楼层
回复 25# pcl_test


    能否帮忙修改下24楼的2个问题?谢谢了。
发表于 2016-3-19 23:15:33 | 显示全部楼层
回复 26# ygqiang


    使用记事本打开源代码,依次点击菜单上“文件”-“另存为”,在“另存为”对话框中,编码选择“utf-8”,点“保存”。
发表于 2016-3-19 23:21:36 | 显示全部楼层
回复 26# ygqiang

用英文吧
document.getElementById("curweek").innerHTML = ['Sun','Mon','Tue','Wed','Thu','Fri','Sat'][dt1.getDay()];
 楼主| 发表于 2016-3-19 23:30:58 | 显示全部楼层
回复 27# yu2n


    多谢。。win7 64和xp系统下测试通过。

能否将秒,靠近左边的时间一点?谢谢。
发表于 2016-3-20 00:04:47 | 显示全部楼层
回复 29# ygqiang

替换CSS为:
  1. <style type="text/css">
  2.         #center {position: absolute; }
  3.         #center span {display: inline; font-weight:bold; font-family:SimHei,"Microsoft YaHei","Microsoft JhengHei",DFKai-SB,SimSun;}
  4.         #center span #curtime,#cursec {padding:1.5%;}
  5.         #center span #curdate,#curweek {padding:2%;}
  6. </style>
复制代码
完整代码:
    http://7i7hsj.com1.z0.glb.clouddn.com/ColorTimer2.html

评分

参与人数 1技术 +1 收起 理由
happy886rr + 1 这颜色真好看

查看全部评分

您需要登录后才可以回帖 登录 | 注册

本版积分规则

Archiver|手机版|小黑屋|批处理之家 ( 渝ICP备10000708号 )

GMT+8, 2026-3-18 17:55 , Processed in 0.022194 second(s), 7 queries , File On.

Powered by Discuz! X3.5

© 2001-2026 Discuz! Team.

快速回复 返回顶部 返回列表