PHP 8.5.0 Beta 1 available for testing

Voting

: seven minus five?
(Example: nine)

The Note You're Voting On

csaba at alum dot mit dot edu
20 years ago
Getting IE to the foreground
If you are using a command line (CLI) version of PHP on a Win32 platform (e.g. XP Pro, SP2), you might want to have output directed to IE (perhaps you'll want to work with the output there) when Popup does not suffice (see my earlier post, below).

It's easy enough to get an instance of IE using $ie = new COM("InternetExplorer.Application");. The problem is, you don't necessarily see it in the foreground (especially if you already have one open) and who wants to waste keystrokes getting to it? The code below has been working for me (If you want to do other adjustments (e.g. $ie->Document->ParentWindow->resizeTo(800,500); or $ie->Document->Body->bgColor = "yellow";), doing them before the $ie->Visible = true; line will avoid screen distractions):

<?php
function newIEtoForeground($title, $evtPrefix="") {
// brings new instance of IE to foreground with title $title
if (!$extPrefix) $ie = new COM("InternetExplorer.Application");
else
$ie = new COM("InternetExplorer.Application", $evtPrefix);
$ie->Navigate2("about:blank");
$oWSH = new COM("WScript.Shell");
while (
$ie->ReadyState!=4) usleep(10000);

$ie->Document->Title = ($tmpTitle = mt_rand()); //unique title
$ie->Visible = true;
while (!
$oWSH->AppActivate("$tmpTitle - M")) usleep(10000);

$ie->Document->Title = $title;
$ie->Document->ParentWindow->opener="me"; // allows self.close()
return $ie;
}
?>

Csaba Gabor from Vienna

<< Back to user notes page

To Top