def command(self, hwnd, msg, wparam, lparam): id = win32api.LOWORD(wparam) if id == 1023: import webbrowser webbrowser.open('http://127.0.0.1:8050/') win32gui.DestroyWindow(self.hwnd) elif id == 1024: print("Goodbye") win32gui.DestroyWindow(self.hwnd) else: print("Unknown command -", id)
def desktop_name_dlgproc(hwnd,msg,wparam,lparam): """ Handles messages from the desktop name dialog box """ if msg in (win32con.WM_CLOSE,win32con.WM_DESTROY): win32gui.DestroyWindow(hwnd) elif msg == win32con.WM_COMMAND: if wparam == win32con.IDOK: desktop_name=win32gui.GetDlgItemText(hwnd, 72) print 'new desktop name: ',desktop_name win32gui.DestroyWindow(hwnd) create_desktop(desktop_name) elif wparam == win32con.IDCANCEL: win32gui.DestroyWindow(hwnd)
def UpdateControl_FromValue(self): combo = self.GetControl() conn = self.func() list = conn.GetDBList() db = conn.getitem('_dbname') if list == -1: hinst = win32gui.dllhandle parent = self.window.hwnd dwStyle = win32con.WS_CHILD | win32con.WS_VISIBLE | win32con.WS_TABSTOP | win32con.WS_BORDER | \ win32con.ES_AUTOHSCROLL | win32con.FF_ROMAN | win32con.FW_EXTRALIGHT hwndImg = win32gui.CreateWindow("EDIT", db, dwStyle, 67, 80, 180, 20, parent, 7000, 0, None) self.active_control_id = 7000 win32gui.ShowWindow(combo, False) else: try: txtbx = win32gui.GetDlgItem(self.window.hwnd, 7000) win32gui.DestroyWindow(txtbx) except Exception, e: pass win32gui.ShowWindow(combo, True) win32gui.SendMessage(combo, win32con.CB_RESETCONTENT, 0, 0) for item in list: win32gui.SendMessage(combo, win32con.CB_ADDSTRING, 0, str(item)) sel = win32gui.SendMessage(combo, win32con.CB_SELECTSTRING, 0, db) if sel == -1: win32gui.SendMessage(combo, win32con.CB_SETCURSEL, 0, 0) self.active_control_id = self.control_id
def close(self): if not self._hwnd: return win32gui.Shell_NotifyIcon(win32gui.NIM_DELETE, (self._hwnd, 0)) win32gui.DestroyWindow(self._hwnd) win32gui.PostQuitMessage(0) self._hwnd = None
def window_callback(self, hwnd, nMsg, wParam, lParam): if nMsg == win32con.WM_CLOSE: log.debug('WM_CLOSE') win32gui.DestroyWindow(hwnd) elif nMsg == win32con.WM_DESTROY: log.debug('WM_DESTROY') win32gui.PostQuitMessage(0) elif nMsg == win32con.WM_DEVICECHANGE: log.debug('WM_DEVICECHANGE') if wParam in [ win32con.DBT_DEVICEARRIVAL, win32con.DBT_DEVICEREMOVECOMPLETE ]: # Unpack the 'lp' into the appropriate DEV_BROADCAST_* structure, # using the self-identifying data inside the DEV_BROADCAST_HDR. try: info = win32gui_struct.UnpackDEV_BROADCAST(lParam) except NotImplementedError: info = None log.debug( "Device change notification: nMsg=%s, wParam=%s, info=%s:" % (nMsg, wParam, str(info))) inserted = True if wParam == win32con.DBT_DEVICEARRIVAL else False self._cbk(inserted, info) return True else: log.debug('other message nMsg = %d' % nMsg) return win32gui.DefWindowProc(hwnd, nMsg, wParam, lParam)
def TestGradientFill(): wc = win32gui.WNDCLASS() wc.lpszClassName = "test_win32gui_2" wc.style = win32con.CS_GLOBALCLASS | win32con.CS_VREDRAW | win32con.CS_HREDRAW wc.hbrBackground = win32con.COLOR_WINDOW + 1 wc.lpfnWndProc = wndproc_2 class_atom = win32gui.RegisterClass(wc) hwnd = win32gui.CreateWindowEx( 0, class_atom, "Kaleidoscope", win32con.WS_CAPTION | win32con.WS_VISIBLE | win32con.WS_THICKFRAME | win32con.WS_SYSMENU, 100, 100, 900, 900, 0, 0, 0, None, ) s = win32gui.GetWindowLong(hwnd, win32con.GWL_EXSTYLE) win32gui.SetWindowLong(hwnd, win32con.GWL_EXSTYLE, s | win32con.WS_EX_LAYERED) win32gui.SetLayeredWindowAttributes(hwnd, 0, 175, win32con.LWA_ALPHA) for x in range(30): win32gui.InvalidateRect(hwnd, None, True) win32gui.PumpWaitingMessages() time.sleep(0.3) win32gui.DestroyWindow(hwnd) win32gui.UnregisterClass(class_atom, None)
def TestSetWorldTransform(): wc = win32gui.WNDCLASS() wc.lpszClassName = "test_win32gui_1" wc.style = win32con.CS_GLOBALCLASS | win32con.CS_VREDRAW | win32con.CS_HREDRAW wc.hbrBackground = win32con.COLOR_WINDOW + 1 wc.lpfnWndProc = wndproc_1 class_atom = win32gui.RegisterClass(wc) hwnd = win32gui.CreateWindow( wc.lpszClassName, "Spin the Lobster!", win32con.WS_CAPTION | win32con.WS_VISIBLE, 100, 100, 900, 900, 0, 0, 0, None, ) for x in range(500): win32gui.InvalidateRect(hwnd, None, True) win32gui.PumpWaitingMessages() time.sleep(0.01) win32gui.DestroyWindow(hwnd) win32gui.UnregisterClass(wc.lpszClassName, None)
def destroy(self): """ GUIの破棄と, 破棄時コールバックの実行. @note ウィンドウを作成したスレッドと同じスレッドから呼び出すこと. """ if not(self._can_destroy): return self._can_destroy = False self.stop() if callable(self._callback_on_destroy): self._callback_on_destroy() try: self._trayicon.destroy() except Exception as e: # 他の終了処理もあるのでとりあえず続行. pass try: win32gui.DestroyWindow(self._hwnd) except Exception as e: # 他の終了処理もあるのでとりあえず続行. pass try: win32gui.UnregisterClass(self._classatom, self._hinst) except Exception as e: # 他の終了処理もあるのでとりあえず続行. pass
def _run(self, quiet: bool = False): message_map = {con32.WM_DESTROY: self._onDestroy, } # register the window class wc = gui32.WNDCLASS() self._hinst = wc.hInstance = gui32.GetModuleHandle(None) wc.lpszClassName = 'PythonBalloontip' wc.lpfnWndProc = message_map self._classAtom = gui32.RegisterClass(wc) # create the window style = con32.WS_OVERLAPPED | con32.WS_SYSMENU self._hwnd = gui32.CreateWindow(self._classAtom, 'Taskbar', style, 0, 0, con32.CW_USEDEFAULT, con32.CW_USEDEFAULT, 0, 0, self._hinst, None) gui32.UpdateWindow(self._hwnd) try: timeout = float(self.timeout) if timeout <= 0: raise ValueError( "the 'timeout' parameter must be greater than 0") except Exception as e: self._showError(e, 'exit') return self._infoFlags = gui32.NIIF_NOSOUND if quiet else 0 if not self._getIcon(): return flags = gui32.NIF_ICON | gui32.NIF_MESSAGE | gui32.NIF_TIP | gui32.NIF_INFO nid = (self._hwnd, 0, flags, con32.WM_USER + 20, self._hicon, "Balloontip", self.msg, 200, self.title, self._infoFlags) gui32.Shell_NotifyIcon(gui32.NIM_ADD, nid) sleep(timeout) gui32.DestroyWindow(self._hwnd) gui32.UnregisterClass(self._classAtom, self._hinst)
def OnClose(self, hwnd, msg, wparam, lparam): __LOG__.Trace( "OnClose END +++++++++++++++++++++++++++++++++++++++++++++++++", (logging.CRITICAL)) win32gui.DestroyWindow(self.hwnd) """
def execute_menu_option(s, id): print(id) menu_action = s.menu_actions_by_id[id] if menu_action == s.QUIT: win32gui.DestroyWindow(s.hwnd) else: menu_action(s)
def __init__(self, title, msg): message_map = { win32con.WM_DESTROY: self.OnDestroy, } # Register the Window class. wc = win32gui.WNDCLASS() hinst = wc.hInstance = win32api.GetModuleHandle(None) wc.lpszClassName = "PythonTaskbar" wc.lpfnWndProc = message_map # could also specify a wndproc. classAtom = win32gui.RegisterClass(wc) # Create the Window. style = win32con.WS_OVERLAPPED | win32con.WS_SYSMENU self.hwnd = win32gui.CreateWindow(classAtom, "Taskbar", style, 0, 0, win32con.CW_USEDEFAULT, win32con.CW_USEDEFAULT, 0, 0, hinst, None) win32gui.UpdateWindow(self.hwnd) iconPathName = os.path.abspath(icon) icon_flags = win32con.LR_LOADFROMFILE | win32con.LR_DEFAULTSIZE try: hicon = win32gui.LoadImage(hinst, iconPathName, win32con.IMAGE_ICON, 0, 0, icon_flags) except: hicon = win32gui.LoadIcon(0, win32con.IDI_APPLICATION) flags = win32gui.NIF_ICON | win32gui.NIF_MESSAGE | win32gui.NIF_TIP nid = (self.hwnd, 0, flags, win32con.WM_USER + 20, hicon, "tooltip") win32gui.Shell_NotifyIcon(win32gui.NIM_ADD, nid) win32gui.Shell_NotifyIcon( win32gui.NIM_MODIFY, (self.hwnd, 0, win32gui.NIF_INFO, win32con.WM_USER + 20, hicon, "Balloon tooltip", title, 200, msg)) win32gui.DestroyWindow(self.hwnd)
def TestDeviceNotifications(dir_names): wc = win32gui.WNDCLASS() wc.lpszClassName = 'test_devicenotify' wc.style = win32con.CS_GLOBALCLASS | win32con.CS_VREDRAW | win32con.CS_HREDRAW wc.hbrBackground = win32con.COLOR_WINDOW + 1 wc.lpfnWndProc = {win32con.WM_DEVICECHANGE: OnDeviceChange} class_atom = win32gui.RegisterClass(wc) hwnd = win32gui.CreateWindow( wc.lpszClassName, 'Testing some devices', # no need for it to be visible. win32con.WS_CAPTION, 100, 100, 900, 900, 0, 0, 0, None) hdevs = [] # Watch for all USB device notifications filter = win32gui_struct.PackDEV_BROADCAST_DEVICEINTERFACE( GUID_DEVINTERFACE_USB_DEVICE) hdev = win32gui.RegisterDeviceNotification( hwnd, filter, win32con.DEVICE_NOTIFY_WINDOW_HANDLE) hdevs.append(hdev) # and create handles for all specified directories for d in dir_names: hdir = win32file.CreateFile( d, winnt.FILE_LIST_DIRECTORY, winnt.FILE_SHARE_READ | winnt.FILE_SHARE_WRITE | winnt.FILE_SHARE_DELETE, None, # security attributes win32con.OPEN_EXISTING, win32con.FILE_FLAG_BACKUP_SEMANTICS | # required privileges: SE_BACKUP_NAME and SE_RESTORE_NAME. win32con.FILE_FLAG_OVERLAPPED, None) filter = win32gui_struct.PackDEV_BROADCAST_HANDLE(hdir) hdev = win32gui.RegisterDeviceNotification( hwnd, filter, win32con.DEVICE_NOTIFY_WINDOW_HANDLE) hdevs.append(hdev) # now start a message pump and wait for messages to be delivered. print "Watching", len(hdevs), "handles - press Ctrl+C to terminate, or" print "add and remove some USB devices..." if not dir_names: print "(Note you can also pass paths to watch on the command-line - eg," print "pass the root of an inserted USB stick to see events specific to" print "that volume)" while 1: win32gui.PumpWaitingMessages() time.sleep(0.01) win32gui.DestroyWindow(hwnd) win32gui.UnregisterClass(wc.lpszClassName, None)
def OnCommand(self, hwnd, msg, wparam, lparam): id = win32api.LOWORD(wparam) if id == TrayThermostat.Exit: log.debug("Quitting") win32gui.DestroyWindow(self.hwnd) else: log.debug("Setting mode - %i", id) self.__mode = id
def QuitApplication(parent, windowID, msg, wparam, lparam): cefpython.QuitMessageLoop() win32gui.DestroyWindow(windowID) #browser = cefpython.GetBrowserByWindowHandle(windowID) #browser.CloseBrowser() className = cefwindow.GetWindowClassName(windowID) win32gui.UnregisterClass(className, None)
def __close_window(window_handle, window_class): """ Unregisters and destroys a window """ # https://archive.is/BWQv6 win32gui.DestroyWindow(window_handle) # https://archive.is/53x2A win32gui.UnregisterClass(window_class.lpszClassName, None)
def OnCommand(self, hwnd, msg, wparam, lparam): id = win32api.LOWORD(wparam) if id == 1023: self.open() elif id == 1024: win32gui.DestroyWindow(self.hwnd) else: print("Unknown command -", id)
def execute_menu_option(self, id): cur_item = self.menu_actions_by_id[id] menu_action = cur_item[-2] if menu_action == self.QUIT: win32gui.DestroyWindow(self.hwnd) else: ret = menu_action(self, cur_item) if ret is not None: self.walk_check_menu_options(id, self.menu_options)
def RUN_CODE(line, activeJupiter): active = ACTIVE if activeJupiter == True else DEACTIVE connector = JupiterListener() message = CODE_TYPE + line + ";" + active SendMessageToJupiter(message) win32gui.DestroyWindow(connector.hwnd) win32gui.UnregisterClass(connector.self_classAtom, connector.self_hinst) # win32gui.PumpMessages() pass
def RUN_DEBUG(line, activeJupiter): active = ACTIVE if activeJupiter == True else DEACTIVE connector = JupiterListener() message = DEBUG_TYPE + line + ";" + active SendMessageToJupiter(message) win32gui.DestroyWindow(connector.hwnd) win32gui.UnregisterClass(connector.self_classAtom, connector.self_hinst) return trimMsg pass
def _on_command(self, hwnd, msg, wparam, lparam): id = win32api.LOWORD(wparam) if id == 1023: log.info("Goodbye") elif id == 1025: log.info("Goodbye") win32gui.DestroyWindow(self.hwnd) else: log.error("Unknown command -", id)
def cleanup(self): self.stop_win32_session_events() if self.hwnd: try: win32gui.DestroyWindow(self.hwnd) except Exception, e: log.warn("error during win32 events cleanup: %s", e) self.hwnd = None win32gui.UnregisterClass(self.wc.lpszClassName, None)
def WndProc(self, hWnd, message, wParam, lParam): if message == WM_WTSSESSION_CHANGE: self.OnSession(wParam, lParam) elif message == con.WM_CLOSE: gui.DestroyWindow(hWnd) elif message == con.WM_DESTROY: gui.PostQuitMessage(0) elif message == con.WM_QUERYENDSESSION: return True
def command_callback(hwnd, cid): if cid == 1024: from xpra.platform.win32.win32_balloon import notify notify(hwnd, "hello", "world") elif cid == 1025: print("Goodbye") win32gui.DestroyWindow(hwnd) else: print("OnCommand for ID=%s" % cid)
def _on_command(self, hwnd, msg, wparam, lparam): id = win32api.LOWORD(wparam) if id == 1023: print "Goodbye" elif id == 1025: print "Goodbye" win32gui.DestroyWindow(self.hwnd) else: print "Unknown command -", id
def __init__(self, title, message, icon_path=None): # noqa: D107 try: import win32con except ImportError as e: # noqa: F841 logger.debug( 'Failed to import win32con: {e}'.format_map(locals())) return try: import win32gui except ImportError as e: # noqa: F841 logger.debug( 'Failed to import win32gui: {e}'.format_map(locals())) return wc, class_atom = NotificationWindow._create_window_class() # create the window hwnd = win32gui.CreateWindow( NotificationWindow._class_atom, 'Colcon notification', # window class name win32con.WS_OVERLAPPED | win32con.WS_SYSMENU, # style 0, 0, win32con.CW_USEDEFAULT, win32con.CW_USEDEFAULT, 0, 0, NotificationWindow._wc.hInstance, None) win32gui.UpdateWindow(hwnd) # load icon image try: if icon_path is None: # use fall back raise Exception() hicon = win32gui.LoadImage( NotificationWindow._wc.hInstance, icon_path, win32con.IMAGE_ICON, 0, 0, win32con.LR_LOADFROMFILE | win32con.LR_DEFAULTSIZE, # flags ) except Exception: # noqa: B902 hicon = win32gui.LoadIcon(0, win32con.IDI_APPLICATION) # show the notification flags = win32gui.NIF_ICON | win32gui.NIF_MESSAGE | win32gui.NIF_TIP nid = (hwnd, 0, flags, win32con.WM_USER + 20, hicon, 'tooltip') try: win32gui.Shell_NotifyIcon( win32gui.NIM_ADD, nid) win32gui.Shell_NotifyIcon( win32gui.NIM_MODIFY, ( hwnd, 0, win32gui.NIF_INFO, win32con.WM_USER + 20, hicon, 'Balloon tooltip', message, 200, title)) except Exception as e: # noqa: F841 logger.debug( 'Failed to show the notification: {e}'.format_map(locals())) else: # wait a while before destroying the window time.sleep(5) finally: win32gui.DestroyWindow(hwnd)
def on_command(self, hwnd, msg, wparam, lparam): wid = win32api.LOWORD(wparam) if wid == 1024: WindowsNotifier.show_game_window() elif wid == 1025: win32gui.DestroyWindow(self.hwnd) win32gui.UnregisterClass(self.wc.lpszClassName, None) self.alive = False else: print(f"Unknown command: {wid}")
def OnClose(self, hwnd, msg, wparam, lparam): """ 收到关闭消息 :param hwnd: :param msg: :param wparam: :param lparam: :return: """ win32gui.DestroyWindow(self.hwnd)
def _remove_window(self): """Destroy window and free reserved resources.""" if self._window: win32gui.DestroyWindow(self._window) win32gui.UnregisterClass(self.__class__.__name__, None) self._window = None if self._screenshot: win32gui.DeleteObject(self._screenshot.GetHandle()) self._screenshot = None
def switchToPage(self, index): if self.currentPageHwnd is not None: if not self.currentPage.SaveAllControls(): win32gui.SendMessage(self.GetControl(), commctrl.TCM_SETCURSEL, self.currentPageIndex,0) return 1 win32gui.DestroyWindow(self.currentPageHwnd) self.currentPage = MakePropertyPage(self.GetControl(), self.window.manager, self.window.config, self.pages[index]) self.currentPageHwnd = self.currentPage.CreateWindow() self.currentPageIndex = index return 0