Version 32 of Stefan Vogel

Updated 2004-07-23 03:36:20

mailto: stefan at vogel-nest dot de

Homepage: http://www.vogel-nest.de

http://www.vogel-nest.de/uploads/Main/stefan_pass.jpg

Contributions to wikit:

Furthermore:


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

''''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"
    update

}

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"} {
                        continue
                }
                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" } {
            EndLoopMessage
        $application Quit
        exit
    }

}

proc BeginLoopMessage { } {

        global LoopFlag

        set LoopFlag 1
        vwait LoopFlag

        puts "LoopFlag = $LoopFlag"

        return        

}

proc EndLoopMessage {} {

        global LoopFlag

        set LoopFlag 0
        return

}

set application ::tcom::ref createobject "InternetExplorer.Application" $application Visible 1 doUpdate "Visible"

BindEvent $application sink DWebBrowserEvents BindEvent $application sink DWebBrowserEvents2

$application Navigate2 "http://www.163.com " doUpdate "Navigate2"

##Loop Message while {1} {

        BeginLoopMessage
        after 10

}

#$application Quit


My Tclers Wiki-Bookmarks

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 ;-)


[ Category Home Page | Category Person ]