def runonce(mutex_name, register_msg="", exit=False): ''' 使用互斥量保证只运行一次,名称前加“Global\”为全局互斥量可用于多用户环境。 ''' result = False global g_hMutex if register_msg: # 如果直接import qt_utils2 会引入对PyQt的依赖, # 造成其他import runonce的程序在py2exe打包的时候体积增大 qt_utils2 = __import__('dglib.qt.qt_utils2') qt_utils2.UM_SHOW = win32api.RegisterWindowMessage(register_msg) runonce.UM_SHOW = qt_utils2.UM_SHOW g_hMutex = win32event.CreateMutex(None, 0, mutex_name) if g_hMutex: err = win32api.GetLastError() if err == winerror.ERROR_ALREADY_EXISTS: if register_msg: win32api.PostMessage(win32con.HWND_BROADCAST, qt_utils2.UM_SHOW, 0, 0) if exit: sys.exit() else: result = True else: win32api.MessageBox(0, '创建Mutex失败!', '提示', win32con.MB_ICONERROR) return result
def findWindows(): ret = [] sdi = win32api.RegisterWindowMessage("SciTEDirectorInterface") w = win32gui.GetWindow(win32gui.GetDesktopWindow(), win32con.GW_CHILD) while w: res = win32gui.SendMessage(w, sdi, 0, 0) if res == sdi: ret.append(w) w = win32gui.GetWindow(w, win32con.GW_HWNDNEXT) return ret
def __start__(self): msg_TaskbarRestart = win32api.RegisterWindowMessage("TaskbarCreated") message_map = { msg_TaskbarRestart: self.OnRestart, win32con.WM_DESTROY: self.OnDestroy, win32con.WM_COMMAND: self.OnCommand, win32con.WM_USER + 20: self.OnTaskbarNotify, } # Register the Window class. wc = win32gui.WNDCLASS() hinst = wc.hInstance = win32gui.GetModuleHandle(None) wc.lpszClassName = "MaayTaskbar" wc.style = win32con.CS_VREDRAW | win32con.CS_HREDRAW wc.hCursor = win32gui.LoadCursor(0, win32con.IDC_ARROW) wc.hbrBackground = win32con.COLOR_WINDOW 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, "Maay", style, \ 0, 0, win32con.CW_USEDEFAULT, win32con.CW_USEDEFAULT, \ 0, 0, hinst, None) win32gui.UpdateWindow(self.hwnd) # Try and find a custom icon hinst = win32gui.GetModuleHandle(None) # iconPathName = os.path.abspath(os.path.join( os.path.split(sys.executable)[0], "maaymain.exe" )) icon_flags = win32con.LR_LOADFROMFILE | win32con.LR_DEFAULTSIZE self.hicon = win32gui.LoadImage(hinst, "maay.ico", win32con.IMAGE_ICON, 0, 0, icon_flags) self.hicon_idle = win32gui.LoadImage(hinst, "maayred.ico", win32con.IMAGE_ICON, 0, 0, icon_flags) self.hicon_paused = win32gui.LoadImage(hinst, "maaybw.ico", win32con.IMAGE_ICON, 0, 0, icon_flags) flags = win32gui.NIF_ICON | win32gui.NIF_MESSAGE | win32gui.NIF_TIP nid = (self.hwnd, 0, flags, win32con.WM_USER + 20, self.hicon, "Maay") win32gui.Shell_NotifyIcon(win32gui.NIM_ADD, nid) self.__startedLock.release() win32gui.PumpMessages() # win32gui.PumpWaitingMessages maay.globalvars.logger.info("STOP MAAY TASK BAR")
def __init__(self, iconPath=None): self.iconPath = iconPath self.status = [] msg_TaskbarRestart = \ win32api.RegisterWindowMessage('TaskbarCreated') message_map = { msg_TaskbarRestart: self.OnRestart, win32con.WM_DESTROY: self.OnDestroy, win32con.WM_COMMAND: self.OnCommand, win32con.WM_USER + 20: self.OnTaskbarNotify, } # Register the Window class. wc = win32gui.WNDCLASS() hinst = wc.hInstance = win32api.GetModuleHandle(None) wc.lpszClassName = 'web2pyTaskbar' wc.style = win32con.CS_VREDRAW | win32con.CS_HREDRAW wc.hCursor = win32gui.LoadCursor(0, win32con.IDC_ARROW) wc.hbrBackground = win32con.COLOR_WINDOW 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, 'web2pyTaskbar', style, 0, 0, win32con.CW_USEDEFAULT, win32con.CW_USEDEFAULT, 0, 0, hinst, None, ) win32gui.UpdateWindow(self.hwnd) self.SetServerStopped()
def SetAppBar(appbarWindow, edge): info = _GetRegisterInfo(appbarWindow) info.edge = edge abd = APPBARDATA() abd.cbSize = wintypes.DWORD(sizeof(abd)) abd.hWnd = wintypes.HWND(appbarWindow.GetHandle()) if (edge == ABEdge.Float) and info.isRegistered: shell32.SHAppBarMessage(ABMsg.ABM_REMOVE, PAPPBARDATA(abd)) info.isRegistered = False _RestoreWindow(appbarWindow) return elif not info.isRegistered: info.isRegistered = True info.callbackId = win32api.RegisterWindowMessage("AppBarMessage") shell32.SHAppBarMessage(ABMsg.ABM_NEW, PAPPBARDATA(abd)) appbarWindow.SetWindowStyle(wx.FRAME_NO_TASKBAR | wx.CLIP_CHILDREN | wx.STAY_ON_TOP) _ABSetPos(info.edge, appbarWindow)
def setHooks(self): self.msgNotify = win32api.RegisterWindowMessage("SHELLHOOK") user32.RegisterShellHookWindow(self.hwnd) user32.SetShellWindow(self.hwnd) user32.SetTaskmanWindow(self.hwnd)
.. seealso:: Additional configuration constants: :mod:`~labtools.conf` """ try: import win32api except ImportError: from ._test import win32api from labtools.conf import * #: Here a string identifier for alv software is specified. Must be a valid software name. ALV_SOFTWARE_NAME = 'ALV-5000/E Correlator for WINDOWS-NT 4.0' #some of ALV messages are registered here SET_START_MSG = win32api.RegisterWindowMessage('ALV5000_SET_START') SET_STOP_MSG = win32api.RegisterWindowMessage('ALV5000_SET_STOP') START_MSG = win32api.RegisterWindowMessage('ALV5000_START') STOP_MSG = win32api.RegisterWindowMessage('ALV5000_STOP') ACKNOWLEDGE_MSG = win32api.RegisterWindowMessage('ALV5000_ACKNOWLEDGE') STORE_FILE_MSG = win32api.RegisterWindowMessage('ALV5000_STORE_FILE') SET_DUR_MSG = win32api.RegisterWindowMessage('ALV5000_SET_DUR') SET_SINGLE_MSG = win32api.RegisterWindowMessage('ALV5000_SET_SINGLE') SET_DUAL_MSG = win32api.RegisterWindowMessage('ALV5000_SET_DUAL') SET_CROSS_MSG = win32api.RegisterWindowMessage('ALV5000_SET_CROSS') SET_AUTO_MSG = win32api.RegisterWindowMessage('ALV5000_SET_AUTO') SET_SCALING_MSG = win32api.RegisterWindowMessage('ALV5000_SET_SCALING') SCALING_VALUES = (1, 0, 2, 3, 4) SCALING_NAMES = ('Normal', 'Off', 'Conservative', 'Secure', 'Fixed')
def StartHook(Hwnd): """开始窗口消息钩子""" global lpPrevWndProc,msgShellHook msgShellHook=win32api.RegisterWindowMessage("SHELLHOOK") ctypes.windll.user32.RegisterShellHookWindow(Hwnd) lpPrevWndProc=win32gui.SetWindowLong(Hwnd,win32con.GWL_WNDPROC,WindowProc)