Introduction Interfaces Buy Support More ActiveX Site Home

ActiveScreen Interface


Methods of ActiveScreen.Cature

The methods marked with "*" requires XP or higher versions of Windows.

Properties of ActiveScreen.asHWND
Usage Samples
// Cature the whole screen and save to a jpg file
var as=new ActiveXObject("ActiveScreen.Capturer");
as.CaptureScreen();
var fs=as.SaveToFile("test1.jpg");
WScript.Echo("Image Size = " + fs.toString() + "\r\n");
// Cature the forground window and save to a gif file
var as=new ActiveXObject("ActiveScreen.Capturer");
as.CaptureActiveWindow();
var fs=as.SaveToFile("test2.gif");
WScript.Echo("Image Size = " + fs.toString() + "\r\n");
// Cature a rectangle of the screen and save to a png file
var as=new ActiveXObject("ActiveScreen.Capturer");
as.CaptureRect(200, 200, 400, 300);
var fs=as.SaveToFile("test3.png");
WScript.Echo("Image Size = " + fs.toString() + "\r\n");
// EnumWindow and Capture
<HTML>
<HEAD>
<META HTTP-EQUIV="Content-Type" content="text/html; charset=iso-8859-1">
<TITLE>EnumWindow and Capture</TITLE>

<SCRIPT LANGUAGE="JAVASCRIPT">

function capit()
{
result.innerText="Please wait.";
var as=new ActiveXObject("ActiveScreen.Capturer");
var dt=new Date();
var fn="c:\\asweb_"+dt.getYear().toString()+dt.getMonth().toString()+dt.getDay().toString()+dt.getHours().toString()+dt.getMinutes().toString()+dt.getSeconds().toString()+".gif";
var i=0;
var mainWindow=0;
while(true)
{
    var hwnd=as.EnumWindow(i++);
    if(hwnd==null)
        break;
    var wt1=hwnd.WindowText.toLowerCase();
    var wt2=winText.value.toLowerCase();
    if(wt1.indexOf(wt2)==0)
    {
        mainWindow=hwnd.HWND;
        break;
    }
}
if(mainWindow==0)
{
    result.innerText="Not found.";
    return;
}
as.SetForegroundWindow(mainWindow);
as.CaptureHWND(mainWindow);
if(as.SaveToFile(fn))
  {
  result.innerText=fn;
  scrn.src=fn;
  scrn.style.visibility="visible";
  }
  else
  {
    result.innerText="failed to capture"+mainWindow.toString();
  }
}
</script>
</HEAD>

<BODY>
<h3>EnumWindow and Capture</h3>
<hr size="1">
<table border="0">
<tr bgColor="#c0c0c0">
<td width="80">Result:</td>
<td colspan="3" id="result" style="color:#ff0000"></td>
</tr>
<tr>
<td>Window Text:</td>
<td width="300"><input type="text" id="winText" value="google" style="width:100%"></td>
<td width="32"></td>
<td width="80"><input type="button" value="Capture" onclick="capit();"></input></td>
</tr>
</table>
<hr size="1">
<img id="scrn" style="visibility:hidden" src="">

</BODY>
</HTML>
// Use ActiveScreen in a Web page
<HTML>
<HEAD>
<META HTTP-EQUIV="Content-Type" content="text/html; charset=iso-8859-1">
<TITLE>Sample: Use ActiveScreen In a Web Page</TITLE>

<SCRIPT LANGUAGE="JAVASCRIPT">

function capit()
{
result.innerText="Please wait.";
var as=new ActiveXObject("ActiveScreen.Capturer");
as.CaptureURL(url.value, width.value);
var dt=new Date();
var fn="c:\\asweb_"+dt.getYear().toString()+dt.getMonth().toString()+dt.getDay().toString()+dt.getHours().toString()+dt.getMinutes().toString()+dt.getSeconds().toString()+".gif";
if(as.SaveToFile(fn))
  {
  result.innerText=fn;
  scrn.src=fn;
  scrn.style.visibility="visible";
  }
  else
  {
	result.innerText="failed.";
  }
}
</script>
</HEAD>

<BODY>
<h3>Sample: Use ActiveScreen In A Web Page</h3>
<hr size="1">
<table width="100%" border="0">
<tr bgColor="#c0c0c0"><td>Result:    </td><td colspan="6" id="result" style="color:#ff0000"></td>
</tr>
<tr>
<td width="32" align="right">URL:</td>
<td><input type="text" id="url" value="http://www.xuebrothers.net" style="width:100%"></td>
<td width="32"> </td>
<td width="32" align="right">Width:</td>
<td width="80"><input type="text" id="width" value="800" style="width:100%"></td>
<td width="32"> </td>
<td width="80"><input type="button" value="Capture" onclick="capit();"></input></td>
</tr>
</table>
<hr size="1">
<img id="scrn" style="visibility:hidden" src="">

</BODY>
</HTML>