[python-win32] Using DDE to launch a file in an existing window

Matt Harriger mharriger at gmail.com
Thu Dec 6 20:20:18 CET 2007


Does windows provide a different/better/newer way than the ddeexec registry
key to open a file in an existing window? Is the accepted way to do this now
to take your arguments on the command line to a new instance of your
application, then find your own open application and tell it to open the
file? I'm open to any suggestions of a better way to do this.

(side note: DDE may be antiquated, but internet explorer and firefox under
windows XP both use this method to open a URL in an existing window if you,
for example, type the URL in the run box).

Here's an export from my registry. This example is not exactly as described
above (it talks to the topic named "test", rather than the system topic)

[HKEY_CLASSES_ROOT\ft000005]
"EditFlags"=dword:00000000
"BrowserFlags"=dword:00000008
@="filetest file"

[HKEY_CLASSES_ROOT\ft000005\shell]
@="open"

[HKEY_CLASSES_ROOT\ft000005\shell\open]

[HKEY_CLASSES_ROOT\ft000005\shell\open\command]
@="\"e:\\python24\\python.exe\" \"e:\\development\\filetest\\filetest.py\""

[HKEY_CLASSES_ROOT\ft000005\shell\open\ddeexec]
@="open(%1)"

[HKEY_CLASSES_ROOT\ft000005\shell\open\ddeexec\Application]
@="filetest"

[HKEY_CLASSES_ROOT\ft000005\shell\open\ddeexec\Topic]
@="test"



Sample code for filetest.py:

import win32ui
import dde
from pywin.mfc import object

class DdeSystemTopic(object.Object):
    def __init__(self):
        object.Object.__init__(self, dde.CreateServerSystemTopic())

    def Exec(self, cmd):
        print "Exec:", cmd

class DdeOtherTopic(object.Object):
    def __init__(self, topicName):
        object.Object.__init__(self, dde.CreateTopic(topicName))

    def Exec(self, cmd):
        print "Exec:", cmd

server = dde.CreateServer()
server.AddTopic(DdeSystemTopic())
server.AddTopic(DdeOtherTopic('test'))
server.Create("filetest")
while 1:
    win32ui.PumpWaitingMessages(0, -1)

Thanks!


On Dec 6, 2007 12:41 PM, Tim Roberts <timr at probo.com> wrote:

> Matt Harriger wrote:
> >
> > I have a question about using DDE to launch a file in an existing
> > application when double-clicked from explorer. I'm trying to use the
> > built-in windows functionality for doing this by setting the
> > application and topic keys in HKCR\my_file_type\shell\open
> > \ddeexec. I also have HKCR\my_file_type\shell\open\command set up to
> > launch my python script if windows can't find the application through
> > dde ( i.e. it's not currently running). The python script create a
> > server and registers the system topic as the very first thing it does.
> > When I double-click a file of this type in Explorer, I get an error
> > dialog saying that "windows cannot find ' filename.ext' Make sure you
> > typed the name correctly...". Has anyone else been able to open a file
> > in a running application this way?
>
> Are you really using DDE?  DDE is an antique protocol that is virtually
> extinct today.  It's interesting to see someone trying to find a modern
> use for it.
>
> Can you dump the whole HKCR\my_file_type registry key and show it to
> us?  Mail it to me privately, if you want.  I'll see if anything looks
> unusual.
>
> --
> Tim Roberts, timr at probo.com
> Providenza & Boekelheide, Inc.
>
> _______________________________________________
> python-win32 mailing list
> python-win32 at python.org
> http://mail.python.org/mailman/listinfo/python-win32
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://mail.python.org/pipermail/python-win32/attachments/20071206/4701aa6e/attachment.htm 


More information about the python-win32 mailing list