Hi!

Starting of a super-exemple from the great Mark Hammond, I made a window with IE (ocx) embbed.

It run OK. Thanks to Pywin32's authors.

But...  When my script terminate, Python never close.
My code is huge, but I made a mini-version with the same problem. This script is below.

Any idea for a solution?
Thanks in advance.

Michel Claveau



=======================================================
# -*- coding: utf-8 -*-

import time,sys,ctypes
import win32ui, win32gui, win32con, win32api, win32uiole, win32com.client


# fenetre (window)
w_hinst = win32gui.dllhandle

wc = win32gui.WNDCLASS()
wc.lpszClassName = "Mini_win  -  {Echap} pour fermer. "
wc.style = win32con.CS_GLOBALCLASS| win32con.CS_VREDRAW | win32con.CS_HREDRAW wc.hbrBackground = ctypes.windll.gdi32.GetStockObject(ctypes.c_int(win32con.LTGRAY_BRUSH))
wc.hCursor = win32gui.LoadCursor(0, win32con.IDC_ARROW)
class_atom = win32gui.RegisterClass(wc)

style = win32con.WS_VISIBLE | win32con.WS_CAPTION | win32con.WS_SYSMENU
w_hwnd = win32gui.CreateWindowEx(0, class_atom,"mini_WIN", style, 40,10, 800,480, 0, 0, w_hinst, None)
w_pyw = win32ui.CreateWindowFromHandle(w_hwnd)


# IE COM/cx
WebBrowserModule = win32com.client.gencache.EnsureModule("{EAB22AC0-30C1-11CF-A7EB-0000C05BAE0B}", 0, 1, 1)
if WebBrowserModule is None:
   raise ImportError("IE non trouvé")

class MyWebBrowser(WebBrowserModule.WebBrowser):
   def __init__(self):
       self.__dict__["_dispobj_"] = None

def CreateControl(self, windowTitle, style, rect, parent, id, lic_string=None): self.hwnd = win32ui.CreateControl(str(self.CLSID), windowTitle, style, rect, parent, id, None, False, lic_string)
       self.__dict__["_obj_"] = self.hwnd
self.dispobj = self.default_interface(win32uiole.GetIDispatchForWindow(self._obj_))
       self.__dict__["_dispobj_"] = self.dispobj

win32ui.EnableControlContainer()
ocx = MyWebBrowser()
ieocx = ocx.CreateControl("Web Browser", win32con.WS_TABSTOP | win32con.WS_VISIBLE, (0,20,800,480), w_pyw, 3456)
ocx.Navigate("http://google.fr";)


# waiting close/escape
while True:
   if win32gui.GetActiveWindow() != w_hwnd:
       break
   if (win32api.GetKeyState(win32con.VK_ESCAPE) & 0x8000):
       break
   time.sleep(0.01)
   win32gui.PumpWaitingMessages()


# close win
try:
   win32gui.DestroyWindow(w_hwnd)
except:
   pass
time.sleep(0.250)


#quit python
print 62
print sys.exit()
print 64
=======================================================
_______________________________________________
python-win32 mailing list
python-win32@python.org
http://mail.python.org/mailman/listinfo/python-win32

Reply via email to