ddeserver.py 1015 B

1234567891011121314151617181920212223242526272829303132333435363738
  1. # 'Request' example added jjk 11/20/98
  2. import win32ui
  3. from pywin.mfc import object
  4. import dde
  5. class MySystemTopic(object.Object):
  6. def __init__(self):
  7. object.Object.__init__(self, dde.CreateServerSystemTopic())
  8. def Exec(self, cmd):
  9. print("System Topic asked to exec", cmd)
  10. class MyOtherTopic(object.Object):
  11. def __init__(self, topicName):
  12. object.Object.__init__(self, dde.CreateTopic(topicName))
  13. def Exec(self, cmd):
  14. print("Other Topic asked to exec", cmd)
  15. class MyRequestTopic(object.Object):
  16. def __init__(self, topicName):
  17. topic = dde.CreateTopic(topicName)
  18. topic.AddItem(dde.CreateStringItem(""))
  19. object.Object.__init__(self, topic)
  20. def Request(self, aString):
  21. print("Request Topic asked to compute length of:", aString)
  22. return(str(len(aString)))
  23. server = dde.CreateServer()
  24. server.AddTopic(MySystemTopic())
  25. server.AddTopic(MyOtherTopic("RunAnyCommand"))
  26. server.AddTopic(MyRequestTopic("ComputeStringLength"))
  27. server.Create('RunAny')
  28. while 1:
  29. win32ui.PumpWaitingMessages(0, -1)