Skip to content

Instantly share code, notes, and snippets.

@simply-coded
Last active December 10, 2023 01:51
Show Gist options
  • Save simply-coded/f49161aa40cae8a5ac10dad03bc8b331 to your computer and use it in GitHub Desktop.
Save simply-coded/f49161aa40cae8a5ac10dad03bc8b331 to your computer and use it in GitHub Desktop.
VBScript MsgBox clone using HTA. Allows you to customize the buttons, look and style, unlike the default VBScript MsgBox.
<!DOCTYPE html>
<html>
<head>
<title>Message Box</title>
<meta http-equiv="x-ua-compatible" content="IE=9">
<meta name="author" content="Jeremy England">
<meta name="copyright" content="SimplyCoded">
<meta name="last-modified" content="2015-11-10">
<hta:application
border="thin"
contextMenu="no"
innerBorder="no"
icon="Narrator.exe"
maximizeButton="no"
minimizeButton="no"
selection="no"
singleInstance="yes"
/>
<!--HTML APP SCRIPT-->
<script type="text/vbscript">
'***************
'STARTUP SECTION
Sub window_onload()
document.body.scroll = "no"
window.moveTo 0,2000
resizeWindow()
window.moveTo 200,100
End Sub
'***************
'ONCALL SECTION
Class getWindowSize
Function width()
width = document.body.offsetWidth+16
End Function
Function height()
height = document.body.offsetHeight+39
End Function
Function scrollHeight()
scrollHeight = document.getElementById("tpArea").scrollHeight
End Function
End Class
Set current = New getWindowSize
Function resizeWindow()
ratio = 0.62
wdth = current.width
hght = current.width*ratio
Do while current.height-50 <= current.scrollHeight
If current.height >= screen.height-200 Or current.width >= screen.width-200 Then
Exit Do
Else
wdth = wdth + 5
hght = hght + 5*ratio
window.resizeTo wdth, hght
End If
Loop
Do while current.height-50 >= current.scrollHeight
If current.height <= 155 Or current.width <= 250 Then
Exit Do
Else
wdth = wdth - 5
hght = hght - 5*ratio
window.resizeTo wdth, hght
End If
Loop
End Function
'***************
'ONCLICK SECTION
Function yesBtn()
document.getElementById("tpArea").innerHTML = "You clicked the yes button."
resizeWindow()
document.getElementById("Ybtn").disabled = True
document.getElementById("Nbtn").disabled = False
End Function
Function noBtn()
document.getElementById("tpArea").innerHTML = "You clicked the no button."
resizeWindow()
document.getElementById("Nbtn").disabled = True
document.getElementById("Ybtn").disabled = False
End Function
</script>
<!--HTML APP STYLE-->
<style>
html, body {
height: 100%;
width: 100%;
margin: 0px;
padding: 0px;
font-family: Arial;
font-size: 10pt;
}
#tpArea {
margin: 10px;
padding-bottom: 60px;
}
#btArea {
position: fixed;
bottom: 0px;
right: 0px;
background-color: #ecf0f1;
width: 100%;
height: 50px;
text-align: right;
}
button {
font-family: Arial;
font-size: 10pt;
position: relative;
top: 12.5px;
right: 10px;
width: 85px;
height: 25px;
margin-left: 5px;
border: none;
border-radius: 30px;
background-color: #ffffff;
}
button:hover {
color: #ecf0f1;
}
</style>
</head>
<!--HTML APP CONTENT-->
<body>
<div id="tpArea">
Select your option.
</div>
<div id="btArea">
<button id="Ybtn" onclick="yesBtn()">Yes</button>
<button id="Nbtn" onclick="noBtn()">No</button>
</div>
</body>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment