Advertisement
aveyo

nested_gui_buttons

Aug 17th, 2018
891
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Batch 4.13 KB | None | 0 0
  1. @echo off &title Nested GUI buttons example via mshta snippet by AveYo                &rem preview: https://i.imgur.com/bAIuIHy.png
  2.  
  3. :gui_dialog_1
  4. set first_choices=Option 1,Option 2,Option3,Option4,Finish&set title=Simple GUI choices #1
  5. :: Show gui dialog %1=Title %2=choices %3=outputvariable
  6. call :choice "Simple GUI buttons" "%first_choices%" CHOICE
  7. :: Quit if no choice selected
  8. if not defined CHOICE color 0c &echo  ERROR! No choice selected.. &timeout /t 20 &color 07 &exit/b
  9. :: Print choices
  10. echo Choice1: %CHOICE% & echo.
  11. :: Continue to dialog_2
  12. goto gui_dialog_2
  13.  
  14. :gui_dialog_2
  15. :: Process results from dialog_1
  16. if "%CHOICE%"=="Option 1" set next_choices=Suboption 1 1,Suboption 1 2,Suboption 1 3,Back&set title=Option 1
  17. if "%CHOICE%"=="Option 2" set next_choices=Suboption 2 1,Suboption 2 2,Back&set title=Option 2
  18. if "%CHOICE%"=="Option3"  set next_choices=Suboption 3 1,Suboption 3 2,Suboption 3 3,Suboption 3 4,Back&set title=Option3
  19. if "%CHOICE%"=="Option4"  call :"Option4" &goto Done no suboption
  20. if "%CHOICE%"=="Finish"   call :"Finish"  &goto Done no suboption
  21. :: Show gui dialog %1=Title %2=choices %3=outputvariable
  22. call :choice "%title%" "%next_choices%" CHOICE
  23. :: Quit if no choice selected
  24. if not defined CHOICE color 0c &echo  ERROR! No choice selected.. &timeout /t 20 &color 07 &exit/b
  25. :: Print choices
  26. echo Choice2: %CHOICE% & echo.
  27. :: Back to dialog_1
  28. if "%CHOICE%"=="Back" goto gui_dialog_1
  29.  
  30. :: Process final choice
  31. call :"%CHOICE%"
  32.  
  33. :Done
  34. timeout /t -1
  35. exit/b
  36.  
  37. :: Choice code
  38. :"Option4"
  39. echo running code for %0
  40. rem do stuff here
  41. exit/b
  42. :"Finish"
  43. echo running code for %0
  44. rem do stuff here
  45. goto :Done
  46. :"Suboption 1 1"
  47. echo running code for %0
  48. rem do stuff here
  49. exit/b
  50. :"Suboption 1 2"
  51. echo running code for %0
  52. rem do stuff here
  53. exit/b
  54. :"Suboption 1 3"
  55. echo running code for %0
  56. rem do stuff here
  57. exit/b
  58. :"Suboption 2 1"
  59. echo running code for %0
  60. rem do stuff here
  61. exit/b
  62. :"Suboption 2 2"
  63. echo running code for %0
  64. rem do stuff here
  65. exit/b
  66. :"Suboption 3 1"
  67. echo running code for %0
  68. rem do stuff here
  69. exit/b
  70. :"Suboption 3 2"
  71. echo running code for %0
  72. rem do stuff here
  73. exit/b
  74. :"Suboption 3 3"
  75. echo running code for %0
  76. rem do stuff here
  77. exit/b
  78. :"Suboption 3 4"
  79. echo running code for %0
  80. rem do stuff here
  81. exit/b
  82.  
  83. ::---------------------------------------------------------------------------------------------------------------------------------
  84. :choice %1:title %2:options %3:output_variable                                    example: call :choice Choose "op1,op2,op3" result
  85. setlocal & set "c=about:<title>%~1</title><head><hta:application innerborder='no' sysmenu='yes' scroll='no'><style>body"
  86. set "c=%c% {background-color:#17141F;} br{font-size:14px;vertical-align:-4px;} .button{background-color:#7D5BBE;border:2px solid"
  87. set "c=%c% #392E5C;color:white;padding:4px 4px;text-align:center;text-decoration:none;display:inline-block;font-size:16px;cursor:"
  88. set "c=%c% pointer;width:100%%;display:block;}</style></head><script language='javascript'>function choice(){"
  89. set "c=%c% var opt=document.getElementById('options').value.split(','); var btn=document.getElementById('buttons');for (o in opt){"
  90. set "c=%c% var b=document.createElement('button');b.className='button';b.onclick=function(){
  91. set "c=%c% close(new ActiveXObject('Scripting.FileSystemObject').GetStandardStream(1).Write(this.value));};"
  92. set "c=%c% b.appendChild(document.createTextNode(opt[o]));btn.appendChild(b);btn.appendChild(document.createElement('br'));};"
  93. set "c=%c% btn.appendChild(document.createElement('br'));var r=window.parent.screen;"
  94. set "c=%c% window.moveTo(r.availWidth/3,r.availHeight/6);window.resizeTo(r.availWidth/3,document.body.scrollHeight);}</script>"
  95. set "c=%c% <body onload='choice()'><div id='buttons'/><input type='hidden' name='options' value='%~2'></body>"
  96. for /f "usebackq tokens=* delims=" %%# in (`mshta "%c%"`) do set "choice_var=%%#"
  97. endlocal & set "%~3=%choice_var%" & exit/b &rem snippet by AveYo released under MIT License                                                  
  98. ::--------------------------------------------------------------------------------------------------------------------------------
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement