- ActiveX friendly name : ThumbCl class
- CLSID : 1D2B4F40-1F10-11D1-9E88-00C04FDCAB92
- Automation-enabled
- Exposed methods :
HRESULT displayFile([IN] BSTR filepath)
HRESULT haveThumbnail([OUT] BOOL *bThumbnail)
- Exposed properties :
[propget] HRESULT freeSpace(/* [retval][out] */ long *);
[propget] HRESULT usedSpace(/* [retval][out] */ long *);
[propget] HRESULT totalSpace(/* [retval][out] */ long *);
Of course as anyone guesses the one and only method that is worth mentioning is that displayFile([IN] BSTR filepath). It uses the client area declared in the Html <object...> tag to render a preview of the passed file.
<table>
<tr>
<td>
<object id=Thumbnail_0
classid="clsid:1D2B4F40-1F10-11D1-9E88-00C04FDCAB92"
width=120 height=100>
</object>
</td>
<td> </td>
</tr>
</table>
<script>
function Init_0()
{
Thumbnail_0.displayFile( 'D:\\new_stuff\\codeproject_homepage.htm' )
}
</script>
<script language="javascript">
// purpose : use directory file enumerator to list all *.htm* files
// and prepare a table cell to preview it using the preview ActiveX
// put the following line in comment if you don't want scaling
var imgsize = " width=160 height=140";
var clsid = " classid='clsid:1D2B4F40-1F10-11D1-9E88-00C04FDCAB92'";
var fso = new ActiveXObject("Scripting.FileSystemObject"), f, fc;
f = fso.GetFolder(curdir);
fc = new Enumerator(f.files);
s = "";
sf = "<script language='javascript'> function Init() { ";
i = 0;
for (; !fc.atEnd(); fc.moveNext())
{
// create an ActiveX instance for the preview of this html file
name = "Thumbnail"+i
s = "<object id=" + name + clsid + imgsize + "></"+"object>";
if (fc.item().Name.indexOf(".htm",0)>-1 && fc.item().Name!=thisfilename)
{
// and add an hyperlink to play with
s = "<a href='"+fc.item().Name+"'>" + s + "</a>";
document.write(s);
// attach initialisation code to it
// .replace(/\\/g, "\\\\") replaces simple backslashes with double-backslashes
s = name + ".displayFile( '" + fc.item().Path.replace(/\\/g, "\\\\") + "');";
sf += s;
i++;
}
}
sf += "} </"+ "script>";
document.writeln(sf);
</script>
var fullpath = location.href;we rather get something of the form file:/// c:/ Documents%20and%20Settings / Administrator / My%20Documents / htmlpreview.html because javascript is cross-platform by design, thus returns a file://-protocol compliant URI.
<script language="javascript">
var fullpath, curdir, thisfilename;
fullpath = location.href; // fully qualified filepath
// of the form "file:///c:/Documents%20and%20Settings/Administrator/My%20Documents/htmlpreview.html"
// regexp weirdo
fullpath = fullpath.replace(/file:\/\/\//,""); // remove file:///
fullpath = fullpath.replace(/\//g,"\\"); // replace slash with backslash (for use on Windows OS)
fullpath = fullpath.replace(/%20/g," "); // replace escaped space
// split path and filename
var iLastBackslash = fullpath.lastIndexOf("\\");
var thisfilename = fullpath.substring( iLastBackslash+1, fullpath.length); // = htmlpreview.html
// remove filename from full path, we are just interested in the path
var curdir = fullpath.substring( 0, iLastBackslash );
</script>
Ok now for full listing of htmlpreview.html :
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML>
<HEAD>
<TITLE> HTML Preview </TITLE>
</HEAD>
<BODY BGCOLOR="#FFFFFF" onload="Init()">
<script language="javascript">
var fullpath, curdir, thisfilename;
fullpath = location.href; // fully qualified filepath
// of the form "file:///c:/Documents%20and%20Settings/Administrator/My%20Documents/htmlpreview.html"
// regexp weirdo
fullpath = fullpath.replace(/file:\/\/\//,""); // remove file:///
fullpath = fullpath.replace(/\//g,"\\"); // replace slash with backslash (for use on Windows OS)
fullpath = fullpath.replace(/%20/g," "); // replace escaped space
// split path and filename
var iLastBackslash = fullpath.lastIndexOf("\\");
var thisfilename = fullpath.substring( iLastBackslash+1, fullpath.length); // = htmlpreview.html
// remove filename from full path, we are just interested in the path
var curdir = fullpath.substring( 0, iLastBackslash );
// purpose : use directory file enumerator to list all *.htm* files
// and prepare a table cell to preview it using the preview ActiveX
// put the following line in comment if you don't want scaling
var imgsize = " width=160 height=140";
var clsid = " classid='clsid:1D2B4F40-1F10-11D1-9E88-00C04FDCAB92'";
var fso = new ActiveXObject("Scripting.FileSystemObject"), f, fc;
f = fso.GetFolder(curdir);
fc = new Enumerator(f.files);
s = "";
sf = "<script language='javascript'> function Init() { ";
i = 0;
for (; !fc.atEnd(); fc.moveNext())
{
// create an ActiveX instance for the preview of this html file
name = "Thumbnail"+i
s = "<object id=" + name + clsid + imgsize + "></"+"object>";
if (fc.item().Name.indexOf(".htm",0)>-1 && fc.item().Name!=thisfilename)
{
// and add an hyperlink to play with
s = "<a href='"+fc.item().Name+"'>" + s + "</a>";
document.write(s);
// attach initialisation code to it
// .replace(/\\/g, "\\\\") replaces simple backslashes with double-backslashes
s = name + ".displayFile( '" + fc.item().Path.replace(/\\/g, "\\\\") + "');";
sf += s;
i++;
}
}
sf += "} </"+ "script>";
document.writeln(sf);
</script>
The hyperlinks we have inserted while generating the Html code are of course enabled : just right-click on previews.
Stephane Rodriguez-