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

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

[已解决]hta代码,如何根据显示器屏幕尺寸/分辨率,智能调整。

hta代码,需要解决的问题主要是:
1、让时间居中、尽量最大化字体显示在屏幕中间。
2、任何尺寸大小/任何分辨率高低的显示器。
都能全屏/居中/尽量大字体显示。
能够根据显示器屏幕尺寸/分辨率,智能调整。
2

评分人数

    • CrLf: 感谢给帖子标题标注[已解决]字样PB + 2
    • pcl_test: 未按版规发帖PB -4

想要显示的效果如下

TOP

这个应该属于,网页代码,java脚本之类的?

TOP

回复 6# 522235677


    分辨率如果不是固定的呢?
显示器,预先并不知道具体多大尺寸/多高分辨率。

TOP

回复 5# yu2n


    一般就是xp/win7系统环境下的平板/笔记本/台式机显示器。

屏幕的具体尺寸/分辨率,都不是固定的。

TOP

试了下。在一台显示器上调整好了
换到另一台不同尺寸/不同分辨率的显示器上,显示就不满足要求了。

TOP

回复 10# 522235677


显示器分辨率有很多种。不是固定的啊。

TOP

本帖最后由 ygqiang 于 2016-3-17 20:56 编辑

回复 12# CrLf


    有人说:这个得用js脚本控制
js获取浏览器的宽高比例,
然后当达到某个比例的时候,就改变一下font-size字体大小

TOP

回复 14# CrLf


    多谢。解决了。。

时间屏保.hta
  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. document.getElementById("curtime").innertext=Hour(Now)&":"&right("0"&Minute(Now),2)
  16. document.getElementById("cursec").innertext=right("0"&Second(Now),2)
  17. document.getElementById("curdate").innertext=Month(Now)&"-"&day(Now)
  18. document.getElementById("curweek").innertext="周"& mid("日一二三四五六",Weekday(Now),1)
  19. End function
  20. '''vertical-align:middle;line-height: 80px;
  21. </script>
  22. <script language="JavaScript" type="text/javascript">
  23.     function changeFontSize() {
  24.         var w = document.body.clientWidth
  25.         var h = document.body.clientHeight
  26.         var size = w/3;
  27.         if (w > 2000) {
  28.             size = w/3;
  29.         } else  {
  30.             size = w/3;
  31.         }
  32.         document.getElementById("curtime").style.fontSize = ""+size+"px";
  33.         var size2 = w/9;
  34.         document.getElementById("cursec").style.fontSize = "" + size2 + "px";
  35.         document.getElementById("curdate").style.fontSize = "" + size2 + "px";
  36.         document.getElementById("curweek").style.fontSize = "" + size2 + "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:400px;color:#ffffff;font-family:黑体" /></strong>
  45. <strong><a id=cursec style="font-size:50px;color:#ffffff;margin-left: 8px;"/>
  46. <p></strong>
  47. <strong><a id=curdate style="font-size:50px;color:#ffffff;font-family:黑体;margin-left: 50px;" /></strong>
  48. <strong><a id=curweek style="font-size:50px;color:#ffffff;font-family:黑体;margin-left: 50px;" /></strong>
  49.             </td>
  50.         </tr>
  51.     </table>
  52. <body scroll=no bgcolor=#000000 bordercolor=#000000 onclick=window.close() onkeyup=window.close()>
  53. <HTA:APPLICATION ID="screen"
  54. APPLICATIONNAME="myApp1"
  55. contextMenu ="no"
  56. BORDER="none"
  57. innerBorder="no"
  58. CAPTION="no"
  59. maximizebutton="yes"
  60. minimizebutton="yes"
  61. SHOWINTASKBAR="yes"
  62. SINGLEINSTANCE="yes"
  63. SYSMENU="no"
  64. VERSION="1.0"
  65. WINDOWSTATE="maximize"
  66. ICON="taskmgr.exe"
  67. />
复制代码

TOP

回复 17# yu2n


    你这代码,星期不显示。。。只显示3个框框

TOP

回复 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. />
复制代码

TOP

回复 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. var size = w/100;
  127. document.getElementById("curtime").style.fontSize = "" + parseInt(size * 35) + "px";
  128. document.getElementById("cursec").style.fontSize = "" + parseInt(size * 10) + "px";
  129. document.getElementById("curdate").style.fontSize = "" + parseInt(size * 15) + "px";
  130. document.getElementById("curweek").style.fontSize = "" + parseInt(size * 15) + "px";
  131. var center = document.getElementById("center");
  132. center.style.left = (w - center.clientWidth)/2 + "px";
  133. center.style.top = (h - center.clientHeight)/2 + "px";
  134. }
  135. }
  136. //显示时间
  137. function SetTimeText() {
  138. var dt1=new Date();
  139. document.getElementById("curtime").innerHTML = dt1.getHours() + ":" + ("00" + dt1.getMinutes()).slice(-2);
  140. document.getElementById("cursec").innerHTML = ("00" + dt1.getSeconds()).slice(-2);
  141. document.getElementById("curdate").innerHTML= dt1.getMonth() + "-" + dt1.getDate();
  142. document.getElementById("curweek").innerHTML = "周" + "日一二三四五六".substr(dt1.getDay(), 1);
  143. }
  144. window.onload = function(){
  145. //关闭窗口(HTA)
  146. function closeWindow() {
  147. try {
  148. var Shell = new ActiveXObject("Shell.Application");
  149. Shell = null;
  150. window.close();
  151. } catch(e) {}
  152. }
  153. document.body.onclick = function(){ closeWindow(); };
  154. document.body.onkeyup = function(){ closeWindow(); };
  155. //显示时间
  156. SetTimeText();
  157. changeFontSize();
  158. setInterval(function(){
  159. SetTimeText();
  160. changeFontSize();
  161. }, 500);
  162. //修改颜色
  163. document.body.style['backgroundColor'] = '#336699';
  164. document.body.style['color'] = '#FFFFFF';
  165. setInterval(function(){
  166. //changColor(document.body, 'body::color', 'color', 1);
  167. changColor(document.body, 'body::backgroundColor', 'backgroundColor', 1);
  168. }, 50);
  169. };
  170. </script>
  171. <style type="text/css">
  172. #center {position: absolute; }
  173. #center strong {display: inline; padding: 2%; font-family:SimHei,"Microsoft YaHei","Microsoft JhengHei",DFKai-SB,SimSun;}
  174. </style>
  175. </head>
  176. <body scroll="no">
  177.     <div id='center'>
  178. <strong id="curtime" /></strong><strong id="cursec" /></strong>
  179. <br/>
  180. <center><strong id="curdate" /></strong><strong id="curweek" /></strong></center>
  181.     </div>
  182. </body>
  183. </html>
复制代码
1

评分人数

    • pcl_test: 已有链接,勿重复贴码PB -30

TOP

回复 25# pcl_test


    能否帮忙修改下24楼的2个问题?谢谢了。

TOP

回复 27# yu2n


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

能否将秒,靠近左边的时间一点?谢谢。

TOP

本帖最后由 ygqiang 于 2016-3-20 06:47 编辑

回复 30# yu2n


搞定了。谢谢

TOP

返回列表