helloapp.py 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  1. ##
  2. ## helloapp.py
  3. ##
  4. ##
  5. ## A nice, small 'hello world' Pythonwin application.
  6. ## NOT an MDI application - just a single, normal, top-level window.
  7. ##
  8. ## MUST be run with the command line "pythonwin.exe /app helloapp.py"
  9. ## (or if you are really keen, rename "pythonwin.exe" to something else, then
  10. ## using MSVC or similar, edit the string section in the .EXE to name this file)
  11. ##
  12. ## Originally by Willy Heineman <wheineman@uconect.net>
  13. import win32con
  14. import win32ui
  15. from pywin.mfc import window, dialog, afxres
  16. from pywin.mfc.thread import WinApp
  17. # The main frame.
  18. # Does almost nothing at all - doesnt even create a child window!
  19. class HelloWindow(window.Wnd):
  20. def __init__(self):
  21. # The window.Wnd ctor creates a Window object, and places it in
  22. # self._obj_. Note the window object exists, but the window itself
  23. # does not!
  24. window.Wnd.__init__(self, win32ui.CreateWnd())
  25. # Now we ask the window object to create the window itself.
  26. self._obj_.CreateWindowEx(win32con.WS_EX_CLIENTEDGE, \
  27. win32ui.RegisterWndClass(0, 0, win32con.COLOR_WINDOW + 1), \
  28. 'Hello World!', win32con.WS_OVERLAPPEDWINDOW, \
  29. (100, 100, 400, 300), None, 0, None)
  30. # The application object itself.
  31. class HelloApp(WinApp):
  32. def InitInstance(self):
  33. self.frame = HelloWindow()
  34. self.frame.ShowWindow(win32con.SW_SHOWNORMAL)
  35. # We need to tell MFC what our main frame is.
  36. self.SetMainFrame(self.frame)
  37. # Now create the application object itself!
  38. app = HelloApp()