def MyWndProc(self, hwnd, msg, wParam, lParam): # Display what we've got. if PRINT_MESSAGES: print(msgdict.get(msg), msg, wParam, lParam) # Restore the old WndProc. Notice the use of win32api # instead of win32gui here. This is to avoid an error due to # not passing a callable object. if msg == win32con.WM_DESTROY: win32api.SetWindowLong(self.GetHandle(), win32con.GWL_WNDPROC, _oldWndProc) stopproc = False for cb, cbtrigger in CALLBACKS[self]: if cbtrigger(self, msg, wParam, lParam): if not cb(self, msg, wParam, lParam): stopproc = True break if stopproc: return # Pass all messages (in this case, yours may be different) on to # the original WndProc return win32gui.CallWindowProc(_oldWndProc, hwnd, msg, wParam, lParam)
def run(self): #actually this can put in def refresh,to get the remote desktop size #and i just set to 4000 #what? you have a 8k screen,nevermind width = 4000 #win32api.GetSystemMetrics(0) height = 4000 #win32api.GetSystemMetrics(1) self.overrideredirect(True) #hide the window bounding box self.geometry("+0+0") #set window position or size self.lift() #set window on top self.attributes("-alpha", 0.6) #make watermark transparent self.wm_attributes("-topmost", True) #always set window on top self.wm_attributes("-disabled", True) #disable window,so mouse can not click self.wm_attributes( "-transparentcolor", "white") #window background set white and transparent hwindow = pywintypes.HANDLE(int(self.frame(), 16)) exStyle = win32con.WS_EX_COMPOSITED | win32con.WS_EX_LAYERED | win32con.WS_EX_NOACTIVATE | win32con.WS_EX_TOPMOST | win32con.WS_EX_TRANSPARENT win32api.SetWindowLong(hwindow, win32con.GWL_EXSTYLE, exStyle) #set text / font / text color / background color label = tkinter.Label(textvariable=self.text, font=("Times New Roman", "40"), fg="#d5d5d5", bg="white") label.pack() self.withdraw() self.procHide = True self.refresh() self.mainloop()
def MakeTransparent(self, alpha): import os, sys # input parameter Excel you from 0 to 100 to be consistent with other # transparency models. # The method below takes a value from 0 to 255. Need to make the mapping. winAlpha = int(alpha * 2.55) if sys.platform == 'win32': hwnd = self.GetHandle() try: import ctypes # DLL library interface constants' definitions _winlib = ctypes.windll.user32 # create object to access DLL file user32.dll style = _winlib.GetWindowLongA(hwnd, 0xffffffecL) style |= 0x00080000 _winlib.SetWindowLongA(hwnd, 0xffffffecL, style) _winlib.SetLayeredWindowAttributes(hwnd, 0, winAlpha, 2) except ImportError: import win32api, win32con, winxpgui _winlib = win32api.LoadLibrary("user32") pSetLayeredWindowAttributes = win32api.GetProcAddress( _winlib, "SetLayeredWindowAttributes") if pSetLayeredWindowAttributes == None: return exstyle = win32api.GetWindowLong(hwnd, win32con.GWL_EXSTYLE) if 0 == (exstyle & 0x80000): win32api.SetWindowLong(hwnd, win32con.GWL_EXSTYLE, exstyle | 0x80000) winxpgui.SetLayeredWindowAttributes(hwnd, 0, amount, 2) else: print '#### OS Platform must be MS Windows' self.Destroy()
def MakeTransparent(self, amount): """ This is how the method SetTransparent() is implemented on all MS Windows platforms. """ import os if os.name == 'nt': # could substitute: sys.platform == 'win32' hwnd = self.GetHandle() try: import ctypes # DLL library interface constants' definitions _winlib = ctypes.windll.user32 # create object to access DLL file user32.dll style = _winlib.GetWindowLongA(hwnd, '0xffff') style |= 0x00080000 _winlib.SetWindowLongA(hwnd, '0xffff', style) _winlib.SetLayeredWindowAttributes(hwnd, 0, amount, 2) except ImportError: import win32api import win32con import winxpgui _winlib = win32api.LoadLibrary("user32") pSetLayeredWindowAttributes = win32api.GetProcAddress( _winlib, "SetLayeredWindowAttributes") if pSetLayeredWindowAttributes == None: return exstyle = win32api.GetWindowLong(hwnd, win32con.GWL_EXSTYLE) if 0 == (exstyle & 0x80000): win32api.SetWindowLong(hwnd, win32con.GWL_EXSTYLE, exstyle | 0x80000) winxpgui.SetLayeredWindowAttributes(hwnd, 0, amount, 2) else: print('OS Platform must be MS Windows') self.Destroy()
def display_lockscreen_text(): root = tkinter.Tk() root.protocol("WM_DELETE_WINDOW", root.quit) label = tkinter.Label(root, text='Computer is Locked', font=('Times New Roman','80'), fg='green', bg='white') label.master.overrideredirect(True) label.master.geometry("+250+250") label.master.lift() label.master.wm_attributes("-topmost", True) label.master.wm_attributes("-disabled", True) label.master.wm_attributes("-transparentcolor", "white") hWindow = pywintypes.HANDLE(int(label.master.frame(), 16)) exStyle = win32con.WS_EX_COMPOSITED | win32con.WS_EX_LAYERED | win32con.WS_EX_NOACTIVATE | win32con.WS_EX_TOPMOST | win32con.WS_EX_TRANSPARENT win32api.SetWindowLong(hWindow, win32con.GWL_EXSTYLE, exStyle) label.pack() while True: root.update() try: with open("match_face_result2", 'rb') as f: matched = f.read() if matched: os.remove('match_face_result2') break except: continue if matched: break root.quit()
def __init__(self): self.win = tkinter.Tk() self.var = tkinter.StringVar() self.ctr = [] self.var.set("Fetching data...") # change your color here self.label = tkinter.Label(self.win, textvariable=self.var, font=('Consolas', '11'), fg='white', bg='black') self.label.master.wm_attributes("-transparentcolor", "black") self.label.master.overrideredirect(True) self.label.master.lift() self.label.master.wm_attributes("-disabled", True) res = "+" + str(width) + "+" + str(0) self.label.master.geometry(res) # if you want always on top, uncomment this line # self.label.master.wm_attributes("-topmost", True) hWindow = pywintypes.HANDLE(int(self.label.master.frame(), 16)) exStyle = win32con.WS_EX_COMPOSITED | win32con.WS_EX_LAYERED | win32con.WS_EX_NOACTIVATE | win32con.WS_EX_TOPMOST | win32con.WS_EX_TRANSPARENT win32api.SetWindowLong(hWindow, win32con.GWL_EXSTYLE, exStyle) self.label.pack() self.updater() self.label.mainloop()
def set_clickthrough(self): """ Allow for making mouse clicks pass through the window, in case you want to use it as an overlay in your game Also makes the window transparent to visualize this effect. Calling the function again reverts the window to normal state. """ hwnd = win32gui.FindWindow(None, self.title) if self.clickable: # Get window style and perform a 'bitwise or' operation to make the style layered and transparent, achieving # the clickthrough property l_ex_style = win32gui.GetWindowLong(hwnd, win32con.GWL_EXSTYLE) l_ex_style |= win32con.WS_EX_TRANSPARENT | win32con.WS_EX_LAYERED win32gui.SetWindowLong(hwnd, win32con.GWL_EXSTYLE, l_ex_style) # Set the window to be transparent and appear always on top win32gui.SetLayeredWindowAttributes(hwnd, win32api.RGB(0, 0, 0), 190, win32con.LWA_ALPHA) # transparent win32gui.SetWindowPos(hwnd, win32con.HWND_TOPMOST, self.root.winfo_x(), self.root.winfo_y(), 0, 0, 0) self.clickable = False else: # Calling the function again sets the extended style of the window to zero, reverting to a standard window win32api.SetWindowLong(hwnd, win32con.GWL_EXSTYLE, 0) if not self.always_on_top: # Remove the always on top property again, in case always on top was set to false in options win32gui.SetWindowPos(hwnd, win32con.HWND_NOTOPMOST, self.root.winfo_x(), self.root.winfo_y(), 0, 0, 0) self.clickable = True
def __init__(self, master, canvas_elements, reload_fcn): self.master = master self.canvas_elements = canvas_elements self.reload_fcn = reload_fcn self.toplevel = tk.Toplevel(self.master) self.label = tk.Label(self.toplevel, text='Climb Rate', font=('Courier New', '14', 'bold'), fg='white', bg='black', justify=tk.LEFT) # make HUD transparent, non clickable and always-on-top self.toplevel.overrideredirect(True) self.toplevel.geometry('+25+500') self.toplevel.lift() self.toplevel.wm_attributes('-topmost', True) self.toplevel.wm_attributes('-disabled', True) self.toplevel.wm_attributes('-transparentcolor', 'black') self.data_valid = False self.was_valid = False hWindow = pywintypes.HANDLE(int(self.toplevel.frame(), 16)) # http://msdn.microsoft.com/en-us/library/windows/desktop/ff700543(v=vs.85).aspx # The WS_EX_TRANSPARENT flag makes events (like mouse clicks) fall through the window. exStyle = win32con.WS_EX_COMPOSITED | win32con.WS_EX_LAYERED | win32con.WS_EX_NOACTIVATE | win32con.WS_EX_TOPMOST | win32con.WS_EX_TRANSPARENT win32api.SetWindowLong(hWindow, win32con.GWL_EXSTYLE, exStyle) self.label.pack()
def run_win32(app: object) -> object: app.lift() h_window = pywintypes.HANDLE(int(app.frame(), 16)) ex_style = win32con.WS_EX_COMPOSITED | win32con.WS_EX_LAYERED | win32con.WS_EX_NOACTIVATE win32api.SetWindowLong(h_window, win32con.GWL_EXSTYLE, ex_style) return app.mainloop()
def OnInitialUpdate(self): hwnd = self._obj_.GetSafeHwnd() style = win32api.GetWindowLong(hwnd, win32con.GWL_STYLE); win32api.SetWindowLong(hwnd, win32con.GWL_STYLE, (style & ~commctrl.LVS_TYPEMASK) | commctrl.LVS_REPORT); itemDetails = (commctrl.LVCFMT_LEFT, 100, "Name", 0) self.InsertColumn(0, itemDetails) itemDetails = (commctrl.LVCFMT_LEFT, 500, "Data", 0) self.InsertColumn(1, itemDetails)
def remove_taskbar_button(self): """Hide window from taskbar and ALT+TAB dialog.""" win32gui.ShowWindow(self.hwnd, win32con.SW_HIDE) win32api.SetWindowLong( self.hwnd, win32con.GWL_EXSTYLE, win32api.GetWindowLong(self.hwnd, win32con.GWL_EXSTYLE) | win32con.WS_EX_NOACTIVATE | win32con.WS_EX_TOOLWINDOW) win32gui.ShowWindow(self.hwnd, win32con.SW_SHOW)
def remove_taskbar_button(self): """隐藏窗口从任务栏和ALT+TAB对话框。""" win32gui.ShowWindow(self.hwnd, win32con.SW_HIDE) win32api.SetWindowLong( self.hwnd, win32con.GWL_EXSTYLE, win32api.GetWindowLong(self.hwnd, win32con.GWL_EXSTYLE) | win32con.WS_EX_NOACTIVATE | win32con.WS_EX_TOOLWINDOW) win32gui.ShowWindow(self.hwnd, win32con.SW_SHOW)
def WndProc(self, hWnd, msg, wParam, lParam): if msg == win32con.WM_USER: if wParam == 0 and lParam == 1: self.Show() self.Raise() elif msg == win32con.WM_DESTROY: win32api.SetWindowLong(self.GetHandle(), win32con.GWL_WNDPROC, self.oldWndProc) return win32gui.CallWindowProc(self.oldWndProc, hWnd, msg, wParam, lParam)
def main(args=None): if args == None: args = sys.argv[1:] if len(args) < 1: print "Usage: w32toggletitle.py <'part of title'>" sys.exit(0) titlematch = ".*%s.*" % args[0] try: emacsHwnd = findwindows.find_window(title_re=titlematch) except: print "Window not found : %s " % titlematch sys.exit(0) current = win32api.GetWindowLong(emacsHwnd, -16) if current == withTitle: win32api.SetWindowLong(emacsHwnd, -16, woTitle) else: win32api.SetWindowLong(emacsHwnd, -16, withTitle)
def setIgnoresFocus(self, value): if skos.WIN: dprint("value = %s" % value) hwnd = skwin.hwnd_from_wid(self.winId()) style = win32api.GetWindowLong(hwnd, win32con.GWL_EXSTYLE) if value != bool(style & win32con.WS_EX_NOACTIVATE): style = (style | win32con.WS_EX_NOACTIVATE if value else style & ~win32con.WS_EX_NOACTIVATE) #win32gui.ShowWindow(hwnd, win32con.SW_HIDE) win32api.SetWindowLong(hwnd, win32con.GWL_EXSTYLE, style)
def deactivate(): restore_data = vim.vars.get('fullscreen_restoredata') win32gui.DestroyWindow(restore_data.get('bkgnd_wnd')) win32gui.UnregisterClass(restore_data.get('class_atom'), None) top_wnd = win32gui.FindWindow('Vim', None) win32api.SetWindowLong(top_wnd, win32con.GWL_STYLE, restore_data.get('style')) win32api.SetWindowLong(top_wnd, win32con.GWL_EXSTYLE, restore_data.get('exstyle')) win32gui.SetWindowPlacement(top_wnd, restore_data.get('window_placement')) if restore_data.get('window_placement')[1] == win32con.SW_SHOWMAXIMIZED: win32api.SendMessage(top_wnd, win32con.WM_SYSCOMMAND, win32con.SC_RESTORE, 0) win32api.SendMessage(top_wnd, win32con.WM_SYSCOMMAND, win32con.SC_MAXIMIZE, 0) vim.vars.update({'fullscreen_restoredata': {}}) vim.vars.update({'fullscreen_active': 0})
def OnInitDialog(self): self.SetWindowText("Enter new value") self.GetDlgItem(win32con.IDCANCEL).ShowWindow(win32con.SW_SHOW) self.edit = self.GetDlgItem(win32ui.IDC_EDIT1) # Modify the edit windows style style = win32api.GetWindowLong(self.edit.GetSafeHwnd(), win32con.GWL_STYLE) style = style & (~win32con.ES_WANTRETURN) win32api.SetWindowLong(self.edit.GetSafeHwnd(), win32con.GWL_STYLE, style) self.edit.SetWindowText(str(self.item)) self.edit.SetSel(-1) return dialog.Dialog.OnInitDialog(self)
def set_top(hwnd): win32gui.SetWindowPos(hwnd,win32con.HWND_TOPMOST,0,0,width,height,win32con.SWP_NOACTIVATE) logging.log(logging.DEBUG,"SetWindowPos to HWND_TOPMOST and SWP_NOACTIVATE") style = win32api.GetWindowLong(hwnd, win32con.GWL_EXSTYLE) logging.log(logging.DEBUG,"Got style %X before" % style) style = style | win32con.WS_EX_LAYERED | win32con.WS_EX_TRANSPARENT | win32con.WS_EX_TOPMOST logging.log(logging.DEBUG,"Setting style %X" % style) win32api.SetWindowLong(hwnd, win32con.GWL_EXSTYLE, style) logging.log(logging.DEBUG,"Set style %X" % style) style = win32api.GetWindowLong(hwnd, win32con.GWL_EXSTYLE) logging.log(logging.DEBUG,"Got style %X after" % style)
def set_top(hwnd): win32gui.SetWindowPos(hwnd,win32con.HWND_TOPMOST,x,y,w,h,win32con.SWP_NOACTIVATE) twitch_bot_utils.printer("SetWindowPos to HWND_TOPMOST and SWP_NOACTIVATE") style = win32api.GetWindowLong(hwnd, win32con.GWL_EXSTYLE) twitch_bot_utils.printer("Got style %X before" % style) style = style | win32con.WS_EX_LAYERED | win32con.WS_EX_TRANSPARENT | win32con.WS_EX_TOPMOST twitch_bot_utils.printer("Setting style %X" % style) win32api.SetWindowLong(hwnd, win32con.GWL_EXSTYLE, style) twitch_bot_utils.printer("Set style %X" % style) style = win32api.GetWindowLong(hwnd, win32con.GWL_EXSTYLE) twitch_bot_utils.printer("Got style %X after" % style)
def stop_win32_session_events(self): if not self.old_win32_proc: return try: if self.hwnd: win32api.SetWindowLong(self.hwnd, win32con.GWL_WNDPROC, self.old_win32_proc) self.old_win32_proc = None win32ts.WTSUnRegisterSessionNotification(self.hwnd) else: log.warn("stop_win32_session_events() missing handle!") except: log.error("stop_win32_session_events", exc_info=True)
def __WndProc(self, hWnd, msg, wParam, lParam): if msg == win32con.WM_DESTROY: win32api.SetWindowLong(self.GetHandle(), win32con.GWL_WNDPROC, self.__oldProc) if msg == win32con.WM_POWERBROADCAST: if wParam == win32con.PBT_APMSUSPEND: wx.CallAfter(self.OnPowerState, self.POWEROFF) elif wParam == win32con.PBT_APMRESUMESUSPEND: wx.CallAfter(self.OnPowerState, self.POWERON) return win32gui.CallWindowProc(self.__oldProc, hWnd, msg, wParam, lParam)
def activate(): bkgndWndClass = win32gui.WNDCLASS() bkgndWndClass.hbrBackground = win32gui.GetStockObject(win32con.BLACK_BRUSH) bkgndWndClass.hCursor = win32gui.LoadCursor(0, win32con.IDC_ARROW) bkgndWndClass.lpszClassName = 'VimFullscreenBkgnd' class_atom = win32gui.RegisterClass(bkgndWndClass) top_wnd = win32gui.FindWindow('Vim', None) mon = win32api.MonitorFromRect(win32gui.GetWindowRect(top_wnd), win32con.MONITOR_DEFAULTTONEAREST) (x, y, dx, dy) = win32api.GetMonitorInfo(mon)['Monitor'] old_window_placement = win32gui.GetWindowPlacement(top_wnd) old_style = win32api.GetWindowLong(top_wnd, win32con.GWL_STYLE) old_exstyle = win32api.GetWindowLong(top_wnd, win32con.GWL_EXSTYLE) win32api.SetWindowLong( top_wnd, win32con.GWL_STYLE, old_style & ~(win32con.WS_CAPTION | win32con.WS_BORDER | win32con.WS_THICKFRAME)) win32api.SetWindowLong(top_wnd, win32con.GWL_EXSTYLE, old_exstyle & ~win32con.WS_EX_WINDOWEDGE) win32gui.SetWindowPos(top_wnd, win32con.HWND_TOP, x, y, dx - x, dy - y, win32con.SWP_SHOWWINDOW | win32con.SWP_FRAMECHANGED) # Black background bkgnd_wnd = win32gui.CreateWindow(class_atom, '', win32con.WS_CHILD, 0, 0, dx - x, dy - y, top_wnd, None, win32api.GetModuleHandle(None), None) win32gui.SetWindowPos( bkgnd_wnd, win32con.HWND_BOTTOM, 0, 0, 0, 0, win32con.SWP_NOACTIVATE | win32con.SWP_NOMOVE | win32con.SWP_NOSIZE | win32con.SWP_SHOWWINDOW) restore_data = { 'window_placement': old_window_placement, 'style': old_style, 'exstyle': old_exstyle, 'class_atom': class_atom, 'bkgnd_wnd': bkgnd_wnd } vim.vars.update({'fullscreen_restoredata': restore_data}) vim.vars.update({'fullscreen_active': 1})