HTA 菜单条生成示例

[ 2859 查看 / 2 回复 ]

  1. <html>
  2. <!-- An editable menu bar that looks like a standard Windows menu for use in an HTA -->
  3. <head>
  4. <title>Example Menu System</title>
  5. <script language=vbs>
  6. resizeto 640, 480
  7. ' Copyright 2010, Tom Lavedas, tlavedas at hotmail dot com
  8. ' Released for non-commercial use, only.

  9. ' Define menu items
  10. Const sMenuItems = "File,Edit,Font,Help"

  11. ' Define one submenu constant for each menu item as illustrated below
  12. ' Each is a comma separated list in a single string
  13. Const sFile = "Open,Close,Save,Save As ...,Exit"
  14. Const sEdit = "Cut,Copy,Paste,Select All,Deselect All"
  15. Const sFont = "Arial,Century Gothic,Times"
  16. Const sHelp = "Help, About"
  17. Const sHTML = "&nbsp;&nbsp;&nbsp;#sItem#&nbsp;&nbsp;&nbsp;"

  18. Dim dMenus, sMenuOpen

  19. sub Window_onload
  20. Dim entry

  21.   set dMenus = createObject("Scripting.Dictionary")
  22.   for each entry in Split(sMenuItems, ",")
  23.     menu.innerHTML = menu.innerHTML & "&nbsp;<span id=" & entry _
  24.                   & " style='padding-bottom:2px' onselectstart=cancelEvent>&nbsp;" _
  25.                   & entry & "&nbsp;</span>&nbsp;&nbsp;"
  26.     dMenus.Add entry, Split(eval("s" & entry), ",")
  27.   next
  28.   sMenuOpen = ""

  29. end sub

  30. Sub menu_onmouseover
  31.  
  32.   clearmenu
  33.   with window.event.srcElement
  34.     if .parentElement.ID = "menu" then
  35.       .style.border = "thin outset"
  36.       .style.cursor = "arrow"
  37.     end if
  38.   end with

  39. end sub

  40. Sub menu_onmouseout

  41.   with window.event.srcElement
  42.     .style.border = "none"
  43.     .style.cursor = "default"
  44.   end with ' srcElement

  45. end sub

  46. Sub dropmenu_onmouseover
  47.  
  48.   with window.event
  49.     .srcElement.style.cursor = "arrow"
  50.     .cancelbubble = true
  51.     .returnvalue = false
  52.   end with

  53. end sub

  54. sub SubMenuOver

  55.   with window.event.srcElement
  56.     if .ID = "dropmenu" then exit sub
  57.     .style.backgroundcolor = "darkblue"
  58.     .style.color = "white"
  59.     .style.cursor = "arrow"
  60.   end with

  61. end sub

  62. sub SubMenuOut

  63.   with window.event.srcElement
  64.     .style.backgroundcolor = "lightgrey"
  65.     .style.color = "black"
  66.     .style.cursor = "default"
  67.   end with

  68. end sub

  69. Sub menu_onclick
  70. Dim oEL, oItem

  71.   if sMenuOpen <> "" then exit sub
  72.   with window.event.srcElement
  73.     if .ID <> "menu" then
  74.       .style.border = "thin inset"
  75.       nLeft = .offsetLeft
  76.       ntop  = .offsetTop + replace(menu.style.Height, "px", "") - 5
  77.       sMenuOpen = trim(.innertext)
  78.       with dropmenu
  79.         with .style
  80.           .border = "thin outset"
  81.           .backgroundcolor = "lightgrey"
  82.           .position = "absolute"
  83.           .left = nLeft
  84.           .top = nTop
  85.           .width = "100px"
  86.         end with ' style
  87.         for each sItem in dMenus.Item(sMenuOpen)
  88.           set oEL = document.createElement("SPAN")
  89.           .appendChild(oEL)
  90.           with oEl
  91.             .ID = sItem
  92.             .style.height = "20px"
  93.             .style.width = dropmenu.style.width
  94.             .innerHTML = Replace(sHTML, "#sItem#", trim(sItem))
  95.             set .onmouseover = getRef("SubMenuOver")
  96.             set .onmouseout = getRef("SubMenuOut")
  97.             set .onclick = getRef("SubMenuClick")
  98.             set .onselectstart = getRef("cancelEvent")
  99.           end with ' child node
  100.           set oEL = document.createElement("BR")
  101.           .appendChild(oEL)
  102.         next
  103.       end with ' dropmenu
  104.     end if
  105.   end with ' srcEement

  106. end sub

  107. sub cancelEvent
  108.   window.event.returnValue = false
  109. end sub ' cancelEvent

  110. sub clearmenu

  111.   dropmenu.innerHTML = ""
  112.   dropmenu.style.border = "none"
  113.   dropmenu.style.backgroundcolor = "transparent"
  114.   if sMenuOpen <> "" then
  115.     document.getElementByID(sMenuOpen).style.border = "none"
  116.     sMenuOpen = ""
  117.   end if
  118. end sub

  119. ' ###################  IMPORTANT  ###################
  120. ' Code to accomplish each submenu item defined above
  121. ' Can be as simple as a subroutine call
  122. '
  123. Sub SubMenuClick

  124.   sItem = trim(window.event.srcElement.innerText)
  125.   clearmenu
  126.   Select Case lcase(sItem)
  127.     case "open"
  128.       msgbox "Sorry, " & sItem & " is not implemented"
  129.     case "close"
  130.       msgbox "Sorry, " & sItem & " is not implemented"
  131.     case "save"
  132.       msgbox "Sorry, " & sItem & " is not implemented"
  133.     case "save as ..."
  134.       msgbox "Sorry, " & sItem & " is not implemented"
  135.     case "exit"
  136.       window.close
  137.     case "cut"
  138.       msgbox "Sorry, " & sItem & " is not implemented"
  139.     case "copy"
  140.     case "paste"
  141.       msgbox "Sorry, " & sItem & " is not implemented"
  142.     case "select all"
  143.       msgbox "Sorry, " & sItem & " is not implemented"
  144.     case "deselect all"
  145.       msgbox "Sorry, " & sItem & " is not implemented"
  146.     case "arial"
  147.       document.body.style.font = "12pt Arial"
  148.     case "century gothic"
  149.       document.body.style.font = "12pt Century Gothic"
  150.     case "times"
  151.       document.body.style.font = "11pt Times New Roman"
  152.     case "help"
  153.       msgbox "Help under construction", vbOKOnly + vbInformation, "Help"
  154.     case "about"
  155.       msgbox "Copyright, 2010" & vbCRLF & "Tom Lavedas"_
  156.               & vbCRLF & "Released for non-commercial use only",_
  157.               vbOKOnly + vbInformation, "About Menu"
  158.     case else ' catch all for undefined menu items
  159.       msgbox "Sorry, " & sItem & " is not implemented"
  160.   end Select

  161. end sub

  162. </script>
  163. </head>
  164. <!--
  165.     Page layout follows
  166. -->
  167. <body onmouseover=menu_onmouseover style="font:12pt Arial">
  168. <div id=menu style="position:absolute;left:0;top:0;width:110%;height:23px;
  169.                     padding-top:2px;background-color:lightgrey;
  170.                     font:normal 9pt Microsoft Sans Serif;z_Index:100">
  171. </div>
  172. <span id=dropmenu style="font:normal 9pt Microsoft Sans Serif"></span>
  173. <br><br><br>
  174. <center>
  175. <b>Build-Your-Own Menu Example</b><br>
  176. Copyright, 2010 Tom Lavedas<br>
  177. For non-commercial use, only.
  178. </center>
  179. <span id=msg style="z_Index:10"></span>
  180. </body>
  181. </html>
复制代码
分享 转发
TOP

const 中文間題

' Define menu items

Const sMenuItems = "File,Edit,Font,Help"



' Define one submenu constant for each menu item as illustrated below

' Each is a comma separated list in a single string

Const sFile = "Open,Close,Save,Save As ...,Exit"

Const sEdit = "Cut,Copy,Paste,Select All,Deselect All"

Const sFont = "Arial,Century Gothic,Times"

Const sHelp = "Help, About"

Const sHTML = "  #sItem#  "



Menu const  中文有錯  不接受
TOP

你可以这样修改一下
添加html字符集声明,简体中文gb2312,繁体中文big5
<html>
<!-- An editable menu bar that looks like a standard Windows menu for use in an HTA -->
<meta http-equiv="Content-Type" content="text/html; charset=gb2312" />
<head>


或者在页面头部添加
<%@LANGUAGE="VBSCRIPT" CODEPAGE="936"%>  简体中文

<%@LANGUAGE="VBSCRIPT" CODEPAGE="950"%>  繁体中文
TOP