Can't find the information you are looking for here? Then leave a message over on our WinBatch Tech Support Forum.
; Figure 2 IHTMLDocument2 Interface ; After a few minutes of research, I came across how to reference ; the HTMLWindow2 object, which allows the implementation of right-click, ; context menus in MSIE. This is a simple demonstration of creating a ; context menu, filling it with a few options and executing them ; OR ; using one for a message or help screen information. ; Strangely, line 39 below ;<--- action on right click is a comment ; but isn't colorized green in WinBatch Studio. Oh well, maybe Detlev's ; script will cure it. ; I'm using MSIE 6, Windows XP home and Winbatch 2004F... #DefineSubRoutine startMSIE() Browser = ObjectOpen("InternetExplorer.Application") Browser.addressbar = @FALSE Browser.statusbar = @FALSE Browser.menubar = @FALSE Browser.toolbar = @FALSE browser.visible = @TRUE url = "c:\RiftsPC-URL.html" ; <--------- URL doesn't matter browser.navigate(url) ;WaitForPageLoad() ; setup the document object... browserDoc = Browser.Document all = browserdoc.all Return(browser) #EndSubRoutine #DefineSubRoutine WaitForPageLoad() ; assume Browser While browser.busy || browser.readystate == 1 TimeDelay(0.5) EndWhile While browser.Document.ReadyState != "complete" TimeDelay(0.5) EndWhile Return #EndSubRoutine ; set up what to do if the browser is closed before the script ends... IntControl(73, 1, 0, 0, 0) ; start the browser... br = startMSIE() ; write out the HTML... browserdoc.writeln(`<head>`) browserdoc.writeln(` <title>Winbatch Context Menu Example</title>`) browserdoc.writeln(`</head>`) browserdoc.writeln(`<body oncontextmenu="cmenu.innerText='cm'; return false">`) ; <--- action on right click browserdoc.writeln(`<h1 align="center">Winbatch Context Menu Example</h1><br><br>`) browserdoc.writeln(`<h2 align="center"><span id=top> </span><br><span id=bot> </span></h2>`) browserdoc.writeln(`<form name="Test" action="ignored" method="POST">`) browserdoc.writeln(` <div align="center"><center><table border="5" cellpadding="5"`) browserdoc.writeln(` cellspacing="5">`) browserdoc.writeln(` <tr>`) browserdoc.writeln(` <td>Enter Name: <input type="text" size="20" name="PopupText"></td>`) browserdoc.writeln(` </tr>`) browserdoc.writeln(` <tr>`) browserdoc.writeln(` <td>Expanding Context: <input type="checkbox" name="check1"><font color="red" size=-2><b>Try it, you'll like it<b></font></td>`) browserdoc.writeln(` </tr>`) browserdoc.writeln(` </table>`) browserdoc.writeln(` </center></div>`) browserdoc.writeln(` <p align="center">`) browserdoc.writeln(` <input type="reset" name="Clear" value="Clear"> </p>`) browserdoc.writeln(` <h2 align="center"><span id=vbot> </span></h2>`) browserdoc.writeln(`</form>`) browserdoc.writeln(`<span id="cmenu"></span>`) browserdoc.writeln(`</body>`) ; setup the context menu capture span... cmenu = all.cmenu ; animate the instructions a bit... top = all.top msg = "Please enter your First & Last names" For q = 1 To StrLen(msg) top.innerHTML = StrCat(`<font color=blue>`, StrSub(msg, 1, q), `</font>`) Yields(12000) Next TimeDelay(1) bot = all.bot msg = "then Right Click on the page" For q = 1 To StrLen(msg) bot.innerHTML = StrCat(`<font color=green>`, StrSub(msg, 1, q), `</font>`) Yields(12000) Next TimeDelay(1) vbot = all.vbot msg = "Then hit the CLEAR button and right click" For q = 1 To StrLen(msg) vbot.innerHTML = StrCat(`<font color=red>`, StrSub(msg, 1, q), `</font>`) Yields(12000) Next ; loop While @TRUE Yields(2000) ; now check inside the span to see if a value appears... ; if so, then we know a right-click has been performed... If cmenu.innerText <> "" req = cmenu.innerText cmenu.innerText = "" ; build and display a context menu... If req == "cm" GoSub createContextMenu Else ; hide an existing context menu... If IsDefined(popupWindow) Then popupWindow.hide() ; inspect the contents and run corresponding tasks... Select @TRUE Case StrLower(req) == "notepad.exe" Run(req, "") Break Case StrLower(req) == "calc.exe" Run(req, "") Break Case StrLower(req) == "dosbox" Run("cmd.exe","") Break EndSelect EndIf EndIf EndWhile browser.quit :WBERRORHANDLER Return Exit :createContextMenu ; create a reference to the HTMLWindow2 object... hw2 = browserdoc.script ; create a popup window object... popupWindow = hw2.createpopup() ; reference the popup's document... pDocument = popupWindow.document ; reference the popup's body... pBody = pDocument.Body ; reference the body's style element... pStyle = pBody.style ; set the font color... pStyle.color = "white" ; set the popup's background color... pBody.bgcolor = "blue" ; set the popup's font size... pStyle.fontSize = "8pt" ; set the popup's left & top margin... ;pStyle.marginLeft = "5" ;pStyle.marginTop = "1" ;pStyle.borderRightWidth = "10pt" ;pStyle.borderRightColor = "red" ; fill the popup with a message... PopupText = all.PopupText usertext = PopupText.value If usertext <> "" ; show the message pop-up... theHTML = "" theHTML = StrCat(theHTML, `<DIV `) theHTML = StrCat(theHTML, `style="BORDER-RIGHT: black 1px solid; BORDER-TOP: black 1px solid; FONT-SIZE: 9pt; Z-INDEX: 3; BACKGROUND: #ffffff; LEFT: 0px; BORDER-LEFT: black 1px solid; WIDTH: 207px; `) theHTML = StrCat(theHTML, `BORDER-BOTTOM: black 1px solid; FONT-FAMILY: verdana; POSITION: absolute; TOP: 0px; HEIGHT: 150px">`) theHTML = StrCat(theHTML, `<DIV id=oTitle `) theHTML = StrCat(theHTML, `style="PADDING-RIGHT: 5px; PADDING-LEFT: 5px; FONT-WEIGHT: bold; FONT-SIZE: 8pt; BACKGROUND: #ffffff; `) theHTML = StrCat(theHTML, `FILTER: progid:DXImageTransform.Microsoft.Gradient(endColorstr='#00ffffff', startColorstr='blue', gradientType='1'); PADDING-BOTTOM: 5px; WIDTH: 100%%; PADDING-TOP: 5px; POSITION: relative; HEIGHT: 20px">`) theHTML = StrCat(theHTML, `%usertext%</DIV></div>`) ; theHTML = strcat(theHTML, `<DIV id=oText `) ; theHTML = strcat(theHTML, `style="PADDING-RIGHT: 5px; PADDING-LEFT: 5px; PADDING-BOTTOM: 5px; PADDING-TOP: 5px">Text</DIV>`) theHTML = StrCat(theHTML, ``) pBody.innerHTML = StrCat(theHTML) Else ; show the default pop-up... ThisVar = `` ThisVar = StrCat(ThisVar, `<table width=110%% border=1 style="Border-Collapse: collapse; cursor: hand;">`) ThisVar = StrCat(ThisVar, `<tr><td onclick="top.document.all.cmenu.innerText='notepad.exe'"><font size="-1">Notepad</font></td></tr>`) ThisVar = StrCat(ThisVar, `<tr><td onclick="top.document.all.cmenu.innerText='calc.exe'"><font size="-1">Calculator</font></td></tr>`) ThisVar = StrCat(ThisVar, `<tr><td onclick="top.document.all.cmenu.innerText='dosbox'"><font size="-1">DOS Command Line</font></td></tr>`) ThisVar = StrCat(ThisVar, `<tr><td> </td></tr>`) ThisVar = StrCat(ThisVar, `<tr><td> </td></tr>`) ThisVar = StrCat(ThisVar, `<tr><td> </td></tr>`) ThisVar = StrCat(ThisVar, `<tr><td> </td></tr>`) ThisVar = StrCat(ThisVar, `</table>`) pBody.innerHTML = ThisVar EndIf ; find out where the mouse is... mi = MouseInfo(3) ; build X and Y coords to the right of mouse... xpos = ItemExtract(1, mi, " ")+15 ypos = ItemExtract(2, mi, " ")+10 ; reference the checkbox... expand = all.check1 ; if it's checked... If expand.checked ; make the context menu grow visibly... h = 1 step = 2 For w = 1 To 207 By step If h < 150 Then h = h+step popupWindow.show(xpos, ypos, w, h) Next Else ; show the window at the coordinates... popupWindow.show(xpos, ypos, 207, 150) EndIf Return
Article ID: W16125
File Created: 2007:09:20:08:27:56
Last Updated: 2007:09:20:08:27:56