' Simple example program to illustrate use of an improved MyMsgBox Dim oHandle, sResult, iW, iH ' Determine screen size, used here to set MsgBox to full screen 'ScreenSize iW, iH ' Or use another size, such as ... iW = 320 : iH = 160 ' Create the message box and collect a handle to it ' (actually an instance of IE.App object) ... set oHandle = MyMsgbox("Msg=""This is an " _ & "IMPORTANT message."":" _ & "Title=""MyMessageBox"":" _ & "height=" & iH & ":width=" & iW & ":" _ & "Buttons=Array(""Done"",""Skip"")") ' Attach event exception handling procedures ... with oHandle.document.all.bdy .oncontextmenu = GetRef("clearMenu") ' Surpress Right-click .onkeydown = GetRef("clearKeys") ' Supress (almost) all keystrokes .onhelp = GetRef("clearKeys") ' Surpress F1 (IE help) key End with ' Error handling for a premature exit from message box (Alt-F4) ... On Error Resume Next ' Wait for button push ... Do Until False if oHandle.document.parentWindow.return <> "" Then ' Returns the number of the button pushed, zero based sResult = oHandle.document.parentWindow.return Exit Do end if if Err.Number <> 0 Then Exit Do wsh.sleep 50 Loop ' Close the box and clear the handle ... oHandle.visible = false oHandle.quit if Err.Number <> 0 then wsh.echo "*** Premature Exit ***", err.description Else wsh.echo "Button number:", sResult, "was selected" End if ' End sample program ' A utility routine to determine the pixel setting of screen Sub ScreenSize(iWidth, iHeight) with CreateObject("htmlfile") with .parentWindow iWidth = .Screen.availWidth iHeight = .Screen.availHeight end with end with End Sub ' Event handler routines ... sub ClearMenu With oHandle.document.parentWindow.event .cancelbubble = true .returnvalue = false End With End sub ' Upgraded keyboard handling - v 1.1 sub ClearKeys With oHandle.document.parentWindow.event Select Case .keycode Case 13 ' select button that has focus, if any oHandle.document.all.b0.click Case 27 ' aborted exit oHandle.document.parentWindow.return = -1 Case Else ' ignore all other keys .keycode = 0 .cancelbubble = true .returnvalue = false end Select End With End sub ' An inproved version of a function to present a non-modal message ' dialog in a VBS (WSF) script ' Returns the IE.App object for further processing. ' ' Improvements/changes: ' o First button receives focus by default ' o Enter key selects button with focus ' o Return button number, 0 to n-1, rather than text ' o Escape key returns with -1 result (in conjuction with ' improved ClearKeys, v 1.1 ' ' Requires WScript version 5.1+ ' Tom Lavedas ' version 1.1, dtd 21 July 2004 ' Function MyMsgBox(sArgs) Dim Msg, Height, Width, Title, oIE, i ' Default values ... height = 200 : width = 400: title = "TitleBar" ' Replace defaults with optional arguments, if supplied Execute sArgs set oIE = CreateObject("InternetExplorer.Application") With oIE .RegisterAsDropTarget = False .FullScreen = True :.width = Width : .height = Height .Navigate "about:blank" Do Until .ReadyState = 4 : WScript.Sleep 50 : Loop With .document oIE.left = (.parentWindow.screen.width - oIE.width )\ 2 oIE.top = (.parentWindow.screen.height- oIE.height)\ 2 .open .write "MsgBox ..." _ & "" _ & "" _ & "" _ & "" _ & "
" _ & " " & Title & "" _ & " 
" _ & "
" _ & Msg & "
" if IsArray(Buttons) Then for i = 0 to Ubound(Buttons) .write "   " next end if .write "
" .close Do Until oIE.ReadyState = 4 : WScript.Sleep 50 : Loop .all.b0.focus End With ' document .Visible = True CreateObject("Wscript.Shell").AppActivate "MsgBox ..." End With ' IE set MyMsgBox = oIE End Function