Stefan Vogel

mailto: stefan at vogel-nest dot de


Contributions to wikit:

A small XML-Parser
in Regular Expression Examples:
Static-Wikit in Tclhttpd: in Wikit configuration
Integration of Tom Krehbiel's wikitool into the CGI of Tclhttpd
in wikitool
a GDBM binding
Webadmin for Metakit with Tclhttpd or


Convert MSProject-Files to CSV with tcom

I lately discovered COM to make many regular tasks easier. Here is a sample on how to convert MSProject-Files in CSV-Files (tested with tcom 3.8 and MSProject 2000 on Windows XP)

package require tcom  
set app [::tcom::ref createobject "MSProject.Application"]  
$app FileOpen c:/test.mpp   # Parameters for "FileSaveAs" are:  
                            # Name Format Backup ReadOnly TaskInformation Filtered Table  
                            # Format is a Number with (4=csv; 19=html)  
$app FileSaveAs c:/test.csv 4 0 0 1 0 "Tablename"  

Using bind for InternetExplorer to capture events with tcom

I wanted to control my IE-object with tcom and often had the problem where I wanted to stop opening new windows Here is some kind of braindump on how to use the callback

package require tcom
proc myCallback {event args} {    
    switch -- $event {      
        NewWindow2 {        
            set idispatch [lindex $args 0]        
            set icancel [lindex $args 1]        # to cancel "NewWindow2"        
            upvar #0 $icancel _iCancel        
            set _iCancel [expr 1=1]   
            # to get access to the new window you have to provide your own created IE-object
            set popup [create a "popup"-object and wait until it's not busy anymore ... see below]        
            upvar #0 $idispatch _iDispatch        
            set _iDispatch $popup   
# create the IE-object  
set app [::tcom::ref createobject "InternetExplorer.Application"]  
# wait until it's there  
while {[$app Busy]} { 
    after 100  
::tcom::bind $app myCallback  

Churchy Zheng It can not capture "NewWindow2" event ,why? do you have test it ? and did you have capture it? l modified above code and it can capture "NewWindow" but can not capture "NewWindow2".

package require tcom      
proc doUpdate { {comment ""}} {      
    puts "invoked $comment"      

proc BindEvent {obj sink {name ""}} {          
    if {$name == ""} {                  
        ::tcom::bind $obj $sink                  
        return OK          
    set lib [::tcom::import shdocvw.dll]          
    foreach i [info commands $lib\::*] {                  
        if {$i != "\::$lib\::$name"} {                          
        set h [$i $obj]                  
        set f [::tcom::info interface $h]                  
        #set N [$f name]                  
        set idd [$f iid]                                   
                ::tcom::bind $obj $sink $idd                                    
                return OK          
    return NO  

proc sink {method args} {      
    global application        
    if {$method != "StatusTextChange"} {              
        puts "event: M=$method P=$args"      
    if {$method == "OnQuit" } {              
        $application Quit          

proc BeginLoopMessage { } {          
    global LoopFlag                    
    set LoopFlag 1          
    vwait LoopFlag                    
    puts "LoopFlag = $LoopFlag"                    

proc EndLoopMessage {} {          
    global LoopFlag                    
    set LoopFlag 0          

set application [::tcom::ref createobject "InternetExplorer.Application"]  
$application Visible 1  
doUpdate "Visible"    
BindEvent $application sink DWebBrowserEvents 
BindEvent $application sink DWebBrowserEvents2      
$application Navigate2 ""  
doUpdate "Navigate2"    
##Loop Message  
while {1} {           
    after 10  
#$application Quit   

Stefan Vogel 2004-07-28: As mentioned on the Microsoftpage [L1 ]:

This [NewWindow] event is obsolete. Use one of the NewWindow2 event instead. And yes it does work but if you opt for me (IE 6.0; tcom 3.8 on Windows XP). When clicking on a link which opens a new browser-window a "NewWindow2"-event is captured.

Churchy Zheng: It is not about IE: TCOM have a bug l have send the bug to author of TCOM. and he have fix the the new version can be donwloaded and can capture NewWindow2 event wrong one than all your efforts will go in vain

My Tclers Wiki-Bookmarks

How to create and clean up a Wikit .tkd file
Tcl data files
An excellent overview about "File patterns". links in fact to
Starkit - How To's
stuff on the main.tcl-file of a starkit

US: Very interesting stuff, but the paragraph Limitations of the Active File pattern in chapter The Active File design pattern is definitely wrong. Tcl doesn't have reserved words and it, of course, allows you to redefine if or any other command.

Thanks for the correction, but to be clear: I didn't write that article (it's from Koen Van Damme) and I only have bookmarked it here, because I searched for it at least a hundred years and don't want to search for it again ;-) *

I can create InternetExplorer.Application objects without any problem. But I cannot get references to already existing ones. By using

set IE [::tcom::ref getactiveobject "InternetExplorer.Application"]

I get a {operation unavailable} error message. I would like to be able to get the URLs of all pages opened within IE. Did someone ever manage to get this done? Thanks

Stefan Vogel 2006-07-27: You are better off asking this in comp.lang.tcl I suppose.