Code:
<HTML>
<HEAD>
<style type="text/css">
P { margin-top:2px;}
FORM { margin-bottom:1px;}
</style>
<SCRIPT LANGUAGE="JavaScript" FOR="window">
<!--
/* To do: keys for volume change */
var filecounter=1;
var folder = "c:\\progra~1\\apache~1\\apache2\\realdocs";
var filename = "wtv";
var fileformat = 2;
var fileformat_desc = "JPG";
var interval = 30.0;
var filename_fmt_desc = "date_time";
var quality = 85;
var ch = 75;
var tmp = 0;
var vol = 50; /* Volume in % */
var videowidth = 320;
var videoheight = 240;
var preview = true;
var hotkeys = 1;
var frozen = 0; /* used to unfreeze image when changing channels and image was frozen */
/* Declare global variables used for window.setInterval */
var folder1;
var filename1;
var fileformat1;
var quality1;
var filename_fmt_desc1;
function TVsource(source) {
WinTVocx1.VideoSource = source;
window.focus();
}
function TVtune(channel) {
WinTVocx1.Channel = channel;
}
function display_volume(v) {
window.status = "Volume = " + v + "%";
}
function TVvolume_up() {
WinTVocx1.VolumeUp();
vol = WinTVocx1.Volume;
display_volume(vol);
}
function TVvolume_dn() {
WinTVocx1.VolumeDown();
vol = WinTVocx1.Volume;
display_volume(vol);
}
function TVtogglemute() {
WinTVocx1.ToggleMute();
}
function TVtogglemute2() {
WinTVocx1.ToggleMute();
if (WinTVocx1.Mute) frm2.button_mute.value = "UnMute"; else frm2.button_mute.value = "Mute";
}
function TVtogglefreeze2() {
WinTVocx1.ToggleFreezeVideo();
if (WinTVocx1.FreezeVideo) {
frozen = 1;
frm3.button_freeze.value = "Unfreeze"; }
else {
frozen = 0;
frm3.button_freeze.value = "Freeze";
}
defaultStatus = "frozen = " + frozen;
}
function TVget_channel() {
return WinTVocx1.Channel;
}
function TVchannelup() {
WinTVocx1.ChannelUp();
window.focus();
}
function TVchanneldn() {
WinTVocx1.ChannelDown();
window.focus();
}
function TVchannelup2() {
if (frozen == 1) TVtogglefreeze2();
WinTVocx1.ChannelUp();
ch = TVget_channel();
frm3.channel_field.value = ch;
window.focus();
}
function TVchanneldn2() {
if (frozen == 1) TVtogglefreeze2();
WinTVocx1.ChannelDown();
ch = TVget_channel();
frm3.channel_field.value = ch;
window.focus();
}
function TVsavetodisk() {
WinTVocx1.SaveToDisk();
}
function TVsavetodiskEx(FileName, fileformat, ColorDepth, CompressionOption, Quality) {
WinTVocx1.SaveToDiskEx(FileName, fileformat, ColorDepth, CompressionOption, Quality);
}
function TVtoolbar(position) {
WinTVocx1.ToolBarPosition = position;
}
function TVcolordialog() {
WinTVocx1.ShowColorControlBox();
}
function TVsuite() {
WinTVocx1.ShowChannelExplorer();
ch = WinTVocx1.Channel;
frm3.channel_field.value = ch;
}
function TVsize(w, h) {
WinTVocx1.Height = h;
WinTVocx1.Width = w;
defaultStatus="width=" + w + " height=" + h;
}
function find_height(w) {
switch(w) {
case 320: return 240;
case 352: return 288;
case 384: return 288;
case 576: return 432;
case 640: return 480;
case 720: return 576;
case 768: return 576;
default: alert("Could not find height");
}
}
function check_first_line() {
if (document.all.tags("!")[0]) {
var x = document.all.tags("!")[0].outerHTML;
if (x.indexOf("saved from url") >= 0) alert("Please edit this HTML document and remove the first line:\n\n" + x);
}
}
function replace_char(str1, c1, c2) {
var str2 = "";
for (i = 0; i <= str1.length-1; i++) {
if (str1.charAt(i) == c1) str2 = str2 + c2; else str2 = str2 + str1.charAt(i);
}
return str2;
}
function str(n, len) {
nstr = "" + n;
while (nstr.length <len) {
nstr = "0" + nstr; }
return nstr;
}
function date_str(separator) {
var now = new Date();
var day = now.getDate();
var month = now.getMonth() + 1;
var year = now.getYear();
d_str = "" + year + separator + str(month, 2) + separator + str(day, 2);
return d_str;
}
function time_str(separator) {
var now = new Date();
var h = now.getHours();
var m = now.getMinutes();
var s = now.getSeconds();
t_str = "" + str(h, 2) + separator + str(m, 2) + separator + str(s, 2);
return t_str;
}
function close_window() {
window.close();
}
function set_cookie_value(name, val, lifetime) {
/* varname, value, lifetime (days) */
/* sets one varname/value pair in cookie and updates expiring date */
/* empty strings are not saved correctly! */
var d = new Date();
d.setTime(d.getTime() + (24*60*60*1000*lifetime));
document.cookie = name + "=" + escape(val) + ';expires=' + d.toGMTString();
}
/* x=4; y=2 */
/* 01234567 */
/* */
function get_cookie_value(name) {
var data;
var val = "undefined";
var found = 0;
var semi;
if (document.cookie) {
data = document.cookie;
while (data.length > 0 && found == 0 ) {
if (data.slice(0,1) == ' ') data = data.slice(1, data.length)
if ((name + '=') == data.slice(0, name.length + 1)) {
found = 1;
data = data.slice(1 + name.length, data.length);
semi = data.indexOf(";");
if (semi < 0) semi = data.length;
val = data.slice(0, semi);
} else {
semi = data.indexOf(";");
if (semi < 0) {semi = data.length}
data = data.slice(1 + semi, data.length);
}
}
}
return unescape(val);
}
function save_to_cookie() {
read_form1(document.frm1);
set_cookie_value("filename", filename, 365);
set_cookie_value("fileformat", fileformat, 365);
set_cookie_value("folder", folder, 365);
set_cookie_value("fileformat_desc", fileformat_desc, 365);
set_cookie_value("filename_fmt_desc", filename_fmt_desc, 365);
read_form2(document.frm2);
set_cookie_value("videowidth", videowidth, 365);
set_cookie_value("videoheight", videoheight, 365);
set_cookie_value("preview", preview, 365);
read_form3(document.frm3);
set_cookie_value("interval", interval, 365);
/* Also save some global vars */
set_cookie_value("vol", vol, 365);
set_cookie_value("filecounter", filecounter, 365);
}
function read_from_cookie() {
var x;
var undef = "undefined";
x = get_cookie_value("filename"); if (x != undef) filename = x;
x = get_cookie_value("fileformat"); if (x != undef) fileformat = x;
x = get_cookie_value("folder"); if (x != undef) folder = x;
x = get_cookie_value("fileformat_desc"); if (x != undef) fileformat_desc = x;
x = get_cookie_value("filename_fmt_desc"); if (x != undef) filename_fmt_desc = x;
x = get_cookie_value("videowidth"); if (x != undef) videowidth = parseInt(x);
x = get_cookie_value("videoheight"); if (x != undef) videoheight = parseInt(x);
x = get_cookie_value("preview"); preview = (x == "true");
x = get_cookie_value("interval"); if (x != undef) interval = Number(x);
/* Also read some global vars */
x = get_cookie_value("vol"); if (x != undef) vol = parseInt(x);
x = get_cookie_value("filecounter"); if (x != undef) filecounter = parseInt(x);
}
function save(folder, filename, fileformat, quality, filename_fmt_desc) {
var fullname;
var extension;
var ColorDepth=32;
var CompressionOption=64;
var part2 = "";
if (fileformat == 2) extension = ".jpg";
if (fileformat == 7) extension = ".png";
if (fileformat == 12) extension = ".bmp";
if (filename_fmt_desc == "time") part2 = time_str("");
if (filename_fmt_desc == "date_time") part2 = date_str("") + "_" + time_str("");
if (filename_fmt_desc == "counter") {
part2 = str(filecounter, 4);
filecounter = filecounter + 1;
}
if (filename_fmt_desc == " ") part2 = "";
var f = folder;
if (f.length > 0) if (f.charAt(f.length - 1) != '\\') f = f + "\\";
fullname = f + frm3.channel_field.value + extension;
/* fullname = f + filename + part2 + extension; */
defaultStatus = "Saving " + fullname;
/* var fso; */
/* fso = new ActiveXObject("Scripting.FileSystemObject"); */
/* fso.DeleteFile(fullname); */
TVsavetodiskEx(fullname, fileformat, ColorDepth, CompressionOption, quality);
defaultStatus = "Saving " + fullname + " ... done.";
if (preview) view_image(fullname);
tmp = ch;
if(tmp == 75) ch =77;
if(tmp == 77) ch = 79;
if(tmp == 79) ch = 75;
frm3.channel_field.value = ch;
TVtune(ch);
}
var autosave_hdl;
var autosave_flg = 0;
function start_autosave(folder, filename, fileformat, quality, sec, filename_fmt_desc) {
if (autosave_flg == 0) {
autosave_flg = 1;
document.frm3.button_autosave.value = "--- Stop ---";
folder1 = folder;
filename1 = filename;
fileformat1 = fileformat;
quality1 = quality;
filename_fmt_desc1 = filename_fmt_desc;
save(folder1, filename1, fileformat1, quality1, filename_fmt_desc1); /* save the first image */
autosave_hdl = window.setInterval("save(folder1, filename1, fileformat1, quality1, filename_fmt_desc1)", 1000 * sec);
} else {
autosave_flg = 0;
window.clearInterval(autosave_hdl);
document.frm3.button_autosave.value = "AutoSave";
}
}
function stop_autosave() {
autosave_flg = 0;
window.clearInterval(autosave_hdl);
document.frm3.button_autosave.value = "AutoSave";
}
function reset_filecounter() {
if (confirm("Counter = " + filecounter + "\n\nSet Counter to 1 ?")) filecounter = 1;
defaultStatus = "Counter = " + filecounter;
}
function init_form1(form) {
form.field_folder.value = folder;
form.field_filename.value = filename;
var i = -1;
var j = 0;
while ((j < form.fileformat.length) && i < 0 ) {
if (form.fileformat.options[j].text == fileformat_desc) {i = j};
j = j + 1;
}
form.fileformat.selectedIndex = i;
var i = -1;
var j = 0;
while ((j < form.filename_fmt.length) && i < 0 ) {
if (form.filename_fmt.options[j].text == filename_fmt_desc) {i = j};
j = j + 1;
}
form.filename_fmt.selectedIndex = i;
}
function init_form2(form) {
var i = -1;
var j = 0;
while ((j < form.videowidth_selector.length) && i < 0 ) {
if (form.videowidth_selector.options[j].text == "" + videowidth) {i = j};
j = j + 1;
}
if (i < 0) i = 0;
form.videowidth_selector.selectedIndex = i;
i = -1;
j = 0;
while ((j < form.videoheight_selector.length) && i < 0 ) {
if (form.videoheight_selector.options[j].text == "" + videoheight) {i = j};
j = j + 1;
}
if (i < 0) i = 0;
form.videoheight_selector.selectedIndex = i;
form.preview_checkbox.checked = preview;
}
function init_form3(form) {
form.channel_field.value = TVget_channel();
form.interval_field.value = interval;
}
function read_form1(form) {
filename = form.field_filename.value;
folder = form.field_folder.value;
var i = form.fileformat.selectedIndex;
fileformat_desc = form.fileformat.options[i].text;
if (fileformat_desc == "JPG") fileformat = 2;
if (fileformat_desc == "PNG") fileformat = 7;
if (fileformat_desc == "BMP") fileformat = 12;
var j = form.filename_fmt.selectedIndex;
filename_fmt_desc = form.filename_fmt.options[j].text;
}
function read_form2(form) {
var i = form.videowidth_selector.selectedIndex;
videowidth = parseInt(form.videowidth_selector.options[i].text);
var j = form.videoheight_selector.selectedIndex;
videoheight = parseInt(form.videoheight_selector.options[j].text);
preview = form.preview_checkbox.checked;
}
function read_form3(form) {
var x;
x = form.interval_field.value;
if (isNaN(x)) {
x = replace_char(x, ',', '.');
x = Number(x);
}
if (isNaN(x)) interval = 1; else interval = x;
defaultStatus = "interval = " + interval + " seconds";
}
function check_keypress() {
if (hotkeys == 1) {
k = event.keyCode;
defaultStatus = "" + k;
if (k == 32) save(folder, filename, fileformat, 75, filename_fmt_desc);
if (k == 27) stop_autosave();
if (k == 43) TVchannelup2();
if (k == 45) TVchanneldn2();
}
}
document.onkeypress = check_keypress;
function disable_hotkeys() {
hotkeys = 0;
}
function enable_hotkeys() {
hotkeys = 1;
}
function view_image(filename) {
window.open(filename, "window_preview", "width=340,height=260,toolbar=yes,location=no,status=no,menubar=no,resizable=yes,scrollbars=no");
/* window.open(filename, "window_preview", "width=" + videowidth + 20 + ",height=" + videoheight + 20 + ",toolbar=yes,location=no,status=no,menubar=no,resizable=yes,scrollbars=no"); */
}
function open_folder(foldername) {
window.open(foldername, "window_folder", "toolbar=yes,location=yes,status=yes,menubar=yes,resizable=yes,scrollbars=yes");
}
function check_WinTVocx() {
if (! WinTVocx1.Height) alert("Please install the WinTV OCX and MS Visual Basic Runtime 6.0 !");
}
function check_colors() {
if (WinTVocx1.Brightness < 10 || WinTVocx1.Contrast < 10) {
alert("Click OK to check color values!");
TVcolordialog();
}
}
function tbl_width() {
/* window.resizeTo(document.all.tbl2.offsetWidth,document.all.tbl2.offsetHeight); */
window.defaultStatus = "" + document.all.tbl2.offsetWidth + ", " + document.body.clientWidth;
while (document.all.tbl2.offsetWidth + 8 > document.body.clientWidth) window.resizeBy(8,0);
while (document.all.tbl2.offsetHeight + 8 > document.body.clientHeight) window.resizeBy(0,8);
}
//-->
</SCRIPT>
<TITLE>WinTV window</TITLE>
</HEAD>
<BODY bgcolor="#A0A0A0" text="#000000" topmargin="4" leftmargin="4" NAME="bdy" onUnload="save_to_cookie()" >
<TABLE ID="tbl2" BORDER="0" CELLSPACING="0" CELLPADDING="5" bgcolor="#A0A0A0">
<TR>
<TD COLSPAN=3 NOWRAP>
<P align="center">
<FORM NAME="frm1">
<INPUT TYPE=button VALUE="Folder:" NAME="button_folder" TITLE="Open folder" onClick="open_folder(form.field_folder.value)">
<INPUT TYPE="text" TITLE="Enter name of existing folder" NAME="field_folder" SIZE="35" onChange="read_form1(this.form)" onfocus="disable_hotkeys()" onBlur="enable_hotkeys()">
File:
<INPUT TYPE="text" TITLE="Enter first part of the filename" NAME="field_filename" SIZE="8" onChange="read_form1(this.form)" onfocus="disable_hotkeys()" onBlur="enable_hotkeys()">
+
<SELECT NAME="filename_fmt" onChange="read_form1(this.form)" onfocus="disable_hotkeys()" onBlur="enable_hotkeys()">
<OPTION SELECTED>date_time
<OPTION>time
<OPTION>counter
<OPTION>
</SELECT>
<SELECT NAME="fileformat" onChange="read_form1(this.form)" onfocus="disable_hotkeys()" onBlur="enable_hotkeys()">
<OPTION SELECTED>JPG
<OPTION>PNG
<OPTION>BMP
</SELECT>
</FORM>
<P>
</TD>
</TR>
<TR valign=top>
<TD>
<P>
<FORM NAME="frm2">
<P align="right">
<INPUT TYPE=button VALUE="Color" TITLE="Open color settings dialog" NAME="button_color" onClick="TVcolordialog()">
<P align="right">
<SELECT NAME="videowidth_selector" onChange="read_form2(this.form);videoheight=find_height(videowidth);init_form2(this.form);TVsize(videowidth,videoheight)" onfocus="disable_hotkeys()" onBlur="enable_hotkeys()">
<OPTION SELECTED>320
<OPTION>352
<OPTION>384
<OPTION>576
<OPTION>640
<OPTION>720
<OPTION>768
</SELECT>
<P align="right">
<SELECT NAME="videoheight_selector" onChange="read_form2(this.form);TVsize(videowidth,videoheight)" onfocus="disable_hotkeys()" onBlur="enable_hotkeys()">
<OPTION SELECTED>240
<OPTION>288
<OPTION>432
<OPTION>480
<OPTION>576
</SELECT>
<P align="right">
<INPUT TYPE=button VALUE="Vol ↑" NAME="button_volume_up" TITLE="Volume up" onClick="TVvolume_up()">
<P align="right">
<INPUT TYPE=button VALUE="Vol ↓" NAME="button_volume_dn" TITLE="Volume down" onClick="TVvolume_dn()">
<P align="right">
<INPUT TYPE=button VALUE="Mute" NAME="button_mute" TITLE="Mute on/off" onClick="TVtogglemute2()">
<P align="right">
<INPUT TYPE=button VALUE="Close" TITLE="Close window" onClick="close_window()">
<P align="right">
<INPUT TYPE=button VALUE="Reload" TITLE="Reload page" onClick="location.reload();window.focus()">
<P align="right">
<INPUT TYPE="checkbox" NAME="preview_checkbox" VALUE="on" TITLE="Enable preview of saved image" onChange="read_form2(this.form)" onfocus="disable_hotkeys()" onBlur="enable_hotkeys()"> Preview
</FORM>
<P>
</TD>
<TD>
<P align="center">
<OBJECT ID="WinTVocx1" WIDTH=320 HEIGHT=240 CLASSID="CLSID:41F3F2F6-0ABE-11D8-BEB2-00A0C9F21FC7" CODEBASE="hcwWinTV.ocx"></OBJECT>
</TD>
<TD>
<P>
<FORM NAME="frm3">
<P>
<INPUT TYPE=button VALUE="Suite" NAME="button_suite" TITLE="Open Channel Manager" onClick="TVsuite()">
<P>
<INPUT TYPE=text VALUE="" NAME="channel_field" TITLE="Current tuner channel" SIZE=3 READONLY>
<P>
<INPUT TYPE=button VALUE="Channel ↑" NAME="button_channel_up" TITLE="Channel up" onClick="TVchannelup2()">
<P>
<INPUT TYPE=button VALUE="Channel ↓" NAME="button_channel_dn" TITLE="Channel down" onClick="TVchanneldn2()">
<P>
<INPUT TYPE=button VALUE="Freeze" NAME="button_freeze" TITLE="Freeze / Unfreeze image" onClick="TVtogglefreeze2()">
<P>
<INPUT TYPE=button VALUE="Save As" NAME="button_save_as" TITLE="Save image as..." onClick="TVsavetodisk()">
<P>
<INPUT TYPE=button VALUE="Save" NAME="button_save" TITLE="Save image" onClick="save(folder, filename, fileformat, quality, filename_fmt_desc)">
<P>
<INPUT TYPE=button VALUE="AutoSave" NAME="button_autosave" TITLE="Start / Stop auto saving of images" onClick="start_autosave(folder, filename, fileformat, quality, interval, filename_fmt_desc)">
<P>
<INPUT TYPE="text" NAME="interval_field" SIZE="6" TITLE="Enter intervall in seconds" onChange="read_form3(this.form)" onfocus="disable_hotkeys()" onBlur="enable_hotkeys()"> sec
<P>
<INPUT TYPE=button VALUE="Reset" TITLE="Reset counter" NAME="button_reset" onClick="reset_filecounter()">
</FORM>
<P>
</TD>
</TR>
<TR>
<TD COLSPAN=3>
</TD>
</TR>
</TABLE>
<SCRIPT LANGUAGE="JavaScript" FOR="window">
<!--
check_first_line()
check_WinTVocx()
WinTVocx1.Enabled = 1;
check_colors();
WinTVocx1.ToolBarPosition = 4; /* hide toolbar */
WinTVocx1.AspectRatio = 1;
init_form1(document.frm1);
read_form1(document.frm1);
init_form2(document.frm2);
read_form2(document.frm2);
init_form3(document.frm3);
WinTVocx1.Volume = vol;
document.frm3.channel_field.value = 77;
window.setTimeout("TVsize(videowidth,videoheight)",250);
ch = 77;
TVtune(ch);
//-->
</SCRIPT>
</BODY></HTML>