我们从Python开源项目中,提取了以下4个代码示例,用于说明如何使用pythoncom.IID_IOleWindow()。
def SetSite(self,unknown): if unknown: # retrieve the parent window interface for this site olewindow = unknown.QueryInterface(pythoncom.IID_IOleWindow) # ask the window for its handle hwndparent = olewindow.GetWindow() # first get a command target cmdtarget = unknown.QueryInterface(axcontrol.IID_IOleCommandTarget) # then travel over to a service provider serviceprovider = cmdtarget.QueryInterface(pythoncom.IID_IServiceProvider) # finally ask for the internet explorer application, returned as a dispatch object self.webbrowser = win32com.client.Dispatch(serviceprovider.QueryService('{0002DF05-0000-0000-C000-000000000046}',pythoncom.IID_IDispatch)) # now create and set up the toolbar self.toolbar = IEToolbarCtrl(hwndparent) buttons = [ ('Visit PyWin32 Homepage',self.on_first_button), ('Another Button', self.on_second_button), ('Yet Another Button', self.on_third_button), ] self._command_map = {} # wrap our parent window so we can hook message handlers window = win32ui.CreateWindowFromHandle(hwndparent) # add the buttons for i in range(len(buttons)): button = TBBUTTON() name,func = buttons[i] id = 0x4444+i button.iBitmap = -2 button.idCommand = id button.fsState = commctrl.TBSTATE_ENABLED button.fsStyle = commctrl.TBSTYLE_BUTTON button.iString = name self._command_map[0x4444+i] = func self.toolbar.AddButtons(button) window.HookMessage(self.toolbar_command_handler,win32con.WM_COMMAND) else: # lose all references self.webbrowser = None