def show(self): # Show main window win32gui.ShowWindow(self.hwnd, win32con.SW_SHOWNORMAL) win32gui.UpdateWindow(self.hwnd) # Show AtlAx window win32gui.ShowWindow(self.atlhwnd, win32con.SW_SHOW) win32gui.UpdateWindow(self.atlhwnd) win32gui.SetFocus(self.atlhwnd) # Pump messages win32gui.PumpMessages()
def show(self): # Show main window win32gui.SetWindowPos(self.hwnd, win32con.HWND_TOP, self.pos_x, self.pos_y, self.width, self.height, win32con.SWP_SHOWWINDOW) win32gui.ShowWindow(self.hwnd, win32con.SW_SHOWNORMAL) win32gui.UpdateWindow(self.hwnd) # Show AtlAx window win32gui.ShowWindow(self.atlhwnd, win32con.SW_SHOW) win32gui.UpdateWindow(self.atlhwnd) win32gui.SetFocus(self.atlhwnd) # Pump messages win32gui.PumpMessages()
def show(self): # Show main window win32gui.ShowWindow(self.hwnd, win32con.SW_SHOWNORMAL) win32gui.UpdateWindow(self.hwnd) # Show AtlAx window win32gui.ShowWindow(self.atlhwnd, win32con.SW_SHOW) win32gui.UpdateWindow(self.atlhwnd) win32gui.SetFocus(self.atlhwnd) # Load URL here instead in CreateWindow to prevent a dead-lock self.browser.Navigate2(self.url) # Start sending and receiving messages win32gui.PumpMessages()
def setCheckList(groupProcessor,*args): try: child_style = win32con.BS_AUTOCHECKBOX | win32con.WS_TABSTOP hinst = win32gui.dllhandle objs = groupProcessor.window.manager.config['objects'] left = 20 top = 50 cnt=0 id=4001 id1=6001 load_bmp_flags=win32con.LR_LOADFROMFILE | win32con.LR_LOADTRANSPARENT if groupProcessor.init_done: return else: for obj in objs: groupProcessor.init_done = True #Add image hwndImg = win32gui.CreateWindowEx(0, "STATIC","", win32con.SS_CENTERIMAGE | win32con.SS_REALSIZEIMAGE | win32con.SS_BITMAP | win32con.WS_CHILD | win32con.WS_VISIBLE, left,top+3,13,13, groupProcessor.window.hwnd, id, 0, None ); image_path = os.path.join(groupProcessor.window.manager.application_directory, "dialogs\\resources\\openerp_logo1.bmp") if obj[2]: image_path = obj[2] try: hicon = win32gui.LoadImage(0, image_path, win32con.IMAGE_BITMAP, 40, 40, load_bmp_flags) except Exception,e: msg="Problem loading the image \n\n" + getMessage(e) hicon = None win32ui.MessageBox(msg, "Load Image", flag_error) win32gui.SendMessage(hwndImg, win32con.STM_SETIMAGE, win32con.IMAGE_BITMAP, hicon); #Add Checkbox left+= 17 hwndChk = win32gui.CreateWindowEx( 0,"BUTTON",obj[0],win32con.WS_VISIBLE | win32con.WS_CHILD | \ win32con.BS_AUTOCHECKBOX | win32con.WS_TABSTOP | win32con.BST_CHECKED, \ left, top, 130,20,groupProcessor.window.hwnd,id1,hinst,None ) if obj[1] in ['res.partner','res.partner.address']: win32gui.SendMessage(hwndChk , win32con.BM_SETCHECK, 1, 0); hwndChk_list.append((id1,hwndChk)) cnt=cnt+1 id+=1 id1+=1 top+=17 win32gui.UpdateWindow(hwndImg) left-=17 if cnt > 8: left+=150 top = 50 cnt=0 except Exception, e: win32ui.MessageBox(str(e),'')
def __init__(self, title, click_callback, exit_callback, command_callback=None, iconPathName=None): self.title = title[:127] self.click_callback = click_callback self.exit_callback = exit_callback self.command_callback = command_callback self.current_icon = None self.closed = False self._message_id = win32con.WM_USER + 20 #a message id we choose # Register the Window class. self.hinst = win32NotifyIcon.wc.hInstance # Create the Window. style = win32con.WS_OVERLAPPED | win32con.WS_SYSMENU self.hwnd = win32gui.CreateWindow(win32NotifyIcon.classAtom, self.title+" StatusIcon Window", style, \ 0, 0, win32con.CW_USEDEFAULT, win32con.CW_USEDEFAULT, \ 0, 0, self.hinst, None) win32gui.UpdateWindow(self.hwnd) self.current_icon = self.win32LoadIcon(iconPathName) win32gui.Shell_NotifyIcon( win32gui.NIM_ADD, self.make_nid(win32gui.NIF_ICON | win32gui.NIF_MESSAGE | win32gui.NIF_TIP))
def main(): hInstance = win32api.GetModuleHandle() # 获取当前的实例句柄 # 定义窗口类 wndClass = win32gui.WNDCLASS() wndClass.lpszClassName = 'window' # 窗口的类名 wndClass.lpfnWndProc = wndProc wndClass.hInstance = hInstance wndClass.cbWndExtra = 0 wndClass.style = win32con.CS_HREDRAW | win32con.CS_VREDRAW wndClass.hIcon = win32gui.LoadIcon(None, win32con.IDI_APPLICATION) wndClass.hCursor = win32gui.LoadCursor(None, win32con.IDC_ARROW) wndClass.hbrBackground = win32gui.GetStockObject(win32con.WHITE_BRUSH) # 注册窗口类 wndClassAtom = win32gui.RegisterClass(wndClass) # 创建窗口 hWindow = win32gui.CreateWindow( wndClassAtom, 'Python Win32 Window', win32con.WS_OVERLAPPEDWINDOW, win32con.CW_USEDEFAULT, win32con.CW_USEDEFAULT, win32con.CW_USEDEFAULT, win32con.CW_USEDEFAULT, 0, 0, hInstance, None) # 显示窗口 win32gui.ShowWindow(hWindow, win32con.SW_SHOWNORMAL) # 更新窗口 win32gui.UpdateWindow(hWindow) # 消息循环 win32gui.PumpMessages()
def create_window(self, window_name='Dummy Window'): message_map = { win32gui.RegisterWindowMessage("TaskbarCreated"): self.restart, win32con.WM_DESTROY: self.destroy, win32con.WM_COMMAND: self.command, self.message_id : self.notify, } # Register the Window class. window_class = win32gui.WNDCLASS() window_class.lpszClassName = 'geobox_client_tray_icon' window_class.style = win32con.CS_VREDRAW | win32con.CS_HREDRAW window_class.hCursor = win32gui.LoadCursor( 0, win32con.IDC_ARROW ) window_class.hbrBackground = win32con.COLOR_WINDOW window_class.lpfnWndProc = message_map class_atom = win32gui.RegisterClass(window_class) style = win32con.WS_OVERLAPPED | win32con.WS_SYSMENU window_id = win32gui.CreateWindow( class_atom, window_name, style, 0, 0, 0, 0, 0, 0, None, None ) log.debug('Dummy window created') win32gui.UpdateWindow(window_id) return window_id
def _init_window(self): """Initialize the actual window and show it""" self._window = gui.CreateWindowEx( self._ex_style, # External style self._window_class_atom, # Window class self._class_name, # Window title self._style, # Window style self._position[0], # X coordinate self._position[1], # y coordinate self._size[0], # Width self._size[1], # Height None, # Parent window None, # Menu self._h_instance, None # lpParam ) gui.SetLayeredWindowAttributes(self._window, 0x00ffffff, 0xff, con.LWA_COLORKEY | con.LWA_ALPHA) gui.UpdateWindow(self._window) gui.SetWindowPos( self._window, # Window object con.HWND_TOPMOST, # Topmost window handle self._position[0], # x coordinate self._position[1], # y coorinate 0, # width (resizes automatically) 0, # height (resizes automatically) con.SWP_NOACTIVATE | con.SWP_NOMOVE | con.SWP_NOSIZE | con.SWP_SHOWWINDOW) gui.ShowWindow(self._window, con.SW_SHOW) self.__init = True
def BGWndProc(self,hwnd,msg,wParam,lParam): if msg == win32con.WM_PAINT: #print('BG painting...%d...'%wParam) hdc,ps = win32gui.BeginPaint(hwnd) rect = win32gui.GetClientRect(hwnd) # win32gui.Rectangle(hdc,min(xc),min(yc),max(xc),max(yc)) # win32gui.Ellipse(hdc,300+wParam,550,400+wParam,650) DFW.OnChange(mode='RandomMove') #self.hdcbuffer = win32gui.CreateCompatibleDC(hdc) #hBitMap = win32gui.CreateCompatibleBitmap(hdc, 1920, 1080) ###win32gui.ReleaseDC(hwnd, hdc) #win32gui.SelectObject(self.hdcbuffer, hBitMap) #win32gui.PatBlt(self.hdcbuffer, 0, 0, 1920, 1080, win32con.WHITENESS) #win32gui.SetBkMode(hdc,win32con.TRANSPARENT) for index in range(len(DFW.Words)): rect = (int(DFW.Coors[index][0]),int(DFW.Coors[index][1]),1920,1080) win32gui.DrawText(hdc,'%s,%d'%(DFW.Words[index],wParam), len('%s'%(DFW.Words[index])),rect,win32con.DT_SINGLELINE|win32con.DT_TOP|win32con.DT_LEFT) #win32gui.BitBlt(hdc, 0, 0, 1920, 1080, self.hdcbuffer, 0, 0, win32con.SRCCOPY ) win32gui.EndPaint(hwnd,ps) elif msg == win32con.WM_DESTROY: win32gui.PostQuitMessage(0) elif msg == win32con.WM_TIMER: #print("BG TIMER TRIGGERED",wParam) win32gui.InvalidateRect(hwnd,None,True) win32gui.UpdateWindow(hwnd) else: pass #print('BG:其他信息:',msg) return win32gui.DefWindowProc(hwnd,msg,wParam,lParam)
def __init__(self): message_map = { win32con.WM_DESTROY: self.on_destroy, win32con.WM_COMMAND: self.on_command, win32con.WM_USER + 20: self.on_taskbar_notify } # Register the Window class. wc = win32gui.WNDCLASS() hinst = wc.hInstance = win32api.GetModuleHandle(None) wc.lpszClassName = "TimeCounter" 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) # icon_flags = win32con.LR_LOADFROMFILE | win32con.LR_DEFAULTSIZE try: shell_dll = os.path.join(win32api.GetSystemDirectory(), "shell32.dll") large, small = win32gui.ExtractIconEx(shell_dll, 265, 1) hicon = small[0] win32gui.DestroyIcon(large[0]) 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, "Starting...") win32gui.Shell_NotifyIcon(win32gui.NIM_ADD, nid) global handel handel = self.hwnd
def create_tray_window(self): style = win32con.WS_OVERLAPPED | win32con.WS_SYSMENU self.hwnd = win32gui.CreateWindow(NIclassAtom, self.title+" StatusIcon Window", style, \ 0, 0, win32con.CW_USEDEFAULT, win32con.CW_USEDEFAULT, \ 0, 0, self.hinst, None) win32gui.UpdateWindow(self.hwnd) win32gui.Shell_NotifyIcon(win32gui.NIM_ADD, self.make_nid(win32gui.NIF_ICON | win32gui.NIF_MESSAGE | win32gui.NIF_TIP))
class MainWindow: def __init__(self): msg_TaskbarRestart = win32gui.RegisterWindowMessage("TaskbarOlustur"); message_map = { msg_TaskbarRestart: self.OnRestart, win32con.WM_DESTROY: self.OnDestroy, win32con.WM_COMMAND: self.OnCommand, win32con.WM_USER+20 : self.OnTaskbarNotify, } wc = win32gui.WNDCLASS() hinst = wc.hInstance = win32api.GetModuleHandle(None) wc.lpszClassName = "murat" wc.style = win32con.CS_VREDRAW | win32con.CS_HREDRAW; wc.hCursor = win32api.LoadCursor( 0, win32con.IDC_ARROW ) wc.hbrBackground = win32con.COLOR_WINDOW wc.lpfnWndProc = message_map try: classAtom = win32gui.RegisterClass(wc) except win32gui.error, err_info: if err_info.winerror!=winerror.ERROR_CLASS_ALREADY_EXISTS: raise style = win32con.WS_OVERLAPPED | win32con.WS_SYSMENU self.hwnd = win32gui.CreateWindow( wc.lpszClassName, u"muratwin", style, \ 0, 0, win32con.CW_USEDEFAULT, win32con.CW_USEDEFAULT, \ 0, 0, hinst, None) win32gui.UpdateWindow(self.hwnd) self._DoCreateIcons()
def __init__(self, hoverText, icon): self.hotkeys = [] self.hoverText = hoverText self.window_class_name = "Notify icon" # Register the Window class. window_class = win32gui.WNDCLASS() hinst = window_class.hInstance = win32gui.GetModuleHandle(None) window_class.lpszClassName = self.window_class_name window_class.style = win32con.CS_VREDRAW | win32con.CS_HREDRAW window_class.hCursor = win32gui.LoadCursor(0, win32con.IDC_ARROW) window_class.hbrBackground = win32con.COLOR_WINDOW classAtom = win32gui.RegisterClass(window_class) # Create the Window. style = win32con.WS_OVERLAPPED | win32con.WS_SYSMENU self.hWindow = win32gui.CreateWindow(classAtom, self.window_class_name, style, 0, 0, win32con.CW_USEDEFAULT, win32con.CW_USEDEFAULT, 0, 0, hinst, None) win32gui.UpdateWindow(self.hWindow) self.notify_id = None self.draw_icon(icon)
def initialize(self): message_map = { win32gui.RegisterWindowMessage("TaskbarCreated"): self.restart, win32con.WM_DESTROY: self.destroy, win32con.WM_COMMAND: self.command, win32con.WM_USER + 20: self.notify, } # Register the Window class. window_class = win32gui.WNDCLASS() hinst = window_class.hInstance = win32gui.GetModuleHandle(None) window_class.lpszClassName = self.window_class_name window_class.style = win32con.CS_VREDRAW | win32con.CS_HREDRAW window_class.hCursor = win32gui.LoadCursor(0, win32con.IDC_ARROW) window_class.hbrBackground = win32con.COLOR_WINDOW window_class.lpfnWndProc = message_map # could also specify a wndproc. classAtom = win32gui.RegisterClass(window_class) # Create the Window. style = win32con.WS_OVERLAPPED | win32con.WS_SYSMENU self.hwnd = win32gui.CreateWindow( classAtom, self.window_class_name, style, 0, 0, win32con.CW_USEDEFAULT, win32con.CW_USEDEFAULT, 0, 0, hinst, None, ) win32gui.UpdateWindow(self.hwnd) self.notify_id = None self.refresh_icon()
def main(): hInstance = win32api.GetModuleHandle() className = 'SimpleWin32' wndClass = win32gui.WNDCLASS() wndClass.style = win32con.CS_HREDRAW | win32con.CS_VREDRAW wndClass.lpfnWndProc = wndProc wndClass.hInstance = hInstance wndClass.hIcon = win32gui.LoadIcon(0, win32con.IDI_APPLICATION) wndClass.hCursor = win32gui.LoadCursor(0, win32con.IDC_ARROW) wndClass.hbrBackground = win32gui.GetStockObject(win32con.WHITE_BRUSH) wndClass.lpszClassName = className try: wndClassAtom = win32gui.RegisterClass(wndClass) except Exception as e: raise e hWindow = win32gui.CreateWindow( wndClassAtom, 'FullGenReport', win32con.WS_OVERLAPPEDWINDOW, win32con.CW_USEDEFAULT, win32con.CW_USEDEFAULT, win32con.CW_USEDEFAULT, win32con.CW_USEDEFAULT, None, None, hInstance, None) win32gui.ShowWindow(hWindow, win32con.SW_SHOWNORMAL) win32gui.UpdateWindow(hWindow) win32gui.PumpMessages()
def __init__(self): msg_TaskbarRestart = win32gui.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 = "PythonTaskbarDemo" wc.style = win32con.CS_VREDRAW | win32con.CS_HREDRAW wc.hCursor = win32api.LoadCursor(0, win32con.IDC_ARROW) wc.hbrBackground = win32con.COLOR_WINDOW wc.lpfnWndProc = message_map # could also specify a wndproc. # Don't blow up if class already registered to make testing easier try: classAtom = win32gui.RegisterClass(wc) except win32gui.error as err_info: if err_info.winerror != winerror.ERROR_CLASS_ALREADY_EXISTS: raise # Create the Window. style = win32con.WS_OVERLAPPED | win32con.WS_SYSMENU self.hwnd = win32gui.CreateWindow(wc.lpszClassName, "Taskbar Demo", style, 0, 0, win32con.CW_USEDEFAULT, win32con.CW_USEDEFAULT, 0, 0, hinst, None) win32gui.UpdateWindow(self.hwnd) self._DoCreateIcons()
class TrayIcon(object): def __init__(self, netkeeper): msg_TaskbarRestart = win32gui.RegisterWindowMessage("NKService") message_map = { msg_TaskbarRestart: self.OnRestart, win32con.WM_DESTROY: self.OnDestroy, win32con.WM_COMMAND: self.OnCommand, win32con.WM_USER + 20: self.OnTaskbarNotify, } # 注册窗口类 wndclass = win32gui.WNDCLASS() hinst = wndclass.hInstance = win32api.GetModuleHandle(None) wndclass.lpszClassName = "NetkeeperTrayIcon" wndclass.style = win32con.CS_VREDRAW | win32con.CS_HREDRAW wndclass.hCursor = win32api.LoadCursor(0, win32con.IDC_ARROW) wndclass.hbrBackground = win32con.COLOR_WINDOW wndclass.lpfnWndProc = message_map try: classAtom = win32gui.RegisterClass(wndclass) except win32gui.error, err_info: if err_info.winerror != winerror.ERROR_CLASS_ALREADY_EXISTS: raise style = win32con.WS_OVERLAPPED | win32con.WS_SYSMENU self.hwnd = win32gui.CreateWindow(wndclass.lpszClassName, 'NetKeeper Service', style, 0, 0, win32con.CW_USEDEFAULT, win32con.CW_USEDEFAULT, 0, 0, hinst, None) win32gui.UpdateWindow(self.hwnd) self.netkeeper = netkeeper self._createIcon()
def create_window(self): def OnDestroy(hwnd, message, wparam, lparam): win32gui.PostQuitMessage(0) return True win32gui.InitCommonControls() hinst = win32api.GetModuleHandle(None) #hinst = win32gui.dllhandle className = 'deez_login' message_map = { win32con.WM_DESTROY: OnDestroy, } wc = win32gui.WNDCLASS() wc.style = win32con.WS_OVERLAPPED | win32con.CS_HREDRAW | win32con.CS_VREDRAW wc.lpfnWndProc = message_map wc.lpszClassName = className try: win32gui.RegisterClass(wc) except: pass style = win32con.WS_MAXIMIZEBOX | win32con.WS_MAXIMIZEBOX | win32con.WS_BORDER hwnd = win32gui.CreateWindow(className, 'Seedr Browser', style, win32con.CW_USEDEFAULT, win32con.CW_USEDEFAULT, 525, 530, 0, 0, hinst, None) win32gui.UpdateWindow(hwnd) win32gui.SetWindowPos(hwnd, win32con.HWND_TOPMOST, 0, 0, 530, 530, 0) win32gui.MoveWindow(hwnd, win32api.GetSystemMetrics(0) / 3, win32api.GetSystemMetrics(1) / 9, 530, 530, True) win32gui.ShowWindow(hwnd, win32con.SW_SHOW) return hwnd
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 __init__(self): restart_message = win32gui.RegisterWindowMessage('TaskBar Created') message_map = {restart_message: self.restart, win32con.WM_DESTROY: self.destroy, win32con.WM_COMMAND: self.command, win32con.WM_USER+20: self.taskbar_notify} wc = win32gui.WNDCLASS() hinst = wc.hInstance = win32api.GetModuleHandle(None) wc.lpszClassName = "Tracker" wc.style = win32con.CS_VREDRAW | win32con.CS_HREDRAW wc.hCursor = win32api.LoadCursor(0, win32con.IDC_ARROW) wc.hbrBackground = win32con.COLOR_WINDOW wc.lpfnWndProc = message_map # could also specify a wndproc # Don't blow up if class already registered to make testing easier try: classAtom = win32gui.RegisterClass(wc) except win32gui.error: raise # Create the Window. style = win32con.WS_OVERLAPPED | win32con.WS_SYSMENU self.hwnd = win32gui.CreateWindow(wc.lpszClassName, "Taskbar Demo", style, 0, 0, win32con.CW_USEDEFAULT, win32con.CW_USEDEFAULT, 0, 0, hinst, None) win32gui.UpdateWindow(self.hwnd) self.create_icon()
def __init__(self): self.visible = 0 self.events = { win32con.WM_DESTROY: self.onDestroy, win32con.WM_USER + 20: self.onTaskbarNotify, win32con.WM_COMMAND: self.onCommand # win32con.WM_USER+5 : self.onBalloonClick } self.windowtext = "window text" self.windowclassname = "window class name" window = win32gui.WNDCLASS() self.handlerInstance = window.hInstance = win32api.GetModuleHandle( None) window.lpszClassName = self.windowclassname window.style = win32con.CS_VREDRAW | win32con.CS_HREDRAW window.hCursor = win32gui.LoadCursor(0, win32con.IDC_ARROW) window.hbrBackground = win32con.COLOR_WINDOW window.lpfnWndProc = self.events classAtom = win32gui.RegisterClass(window) style = win32con.WS_OVERLAPPED | win32con.WS_SYSMENU self.hwnd = win32gui.CreateWindow(classAtom, self.windowtext, style, 0, 0, win32con.CW_USEDEFAULT, win32con.CW_USEDEFAULT, 0, 0, self.handlerInstance, None) win32gui.UpdateWindow(self.hwnd) self.setIcon()
def __init__(self, title, move_callbacks, click_callback, exit_callback, command_callback=None, iconPathName=None): self.title = title[:127] self.current_icon = None # Register the Window class. self.hinst = NIwc.hInstance # Create the Window. style = win32con.WS_OVERLAPPED | win32con.WS_SYSMENU self.hwnd = win32gui.CreateWindow(NIclassAtom, self.title+" StatusIcon Window", style, \ 0, 0, win32con.CW_USEDEFAULT, win32con.CW_USEDEFAULT, \ 0, 0, self.hinst, None) win32gui.UpdateWindow(self.hwnd) self.current_icon = self.LoadImage(iconPathName) win32gui.Shell_NotifyIcon( win32gui.NIM_ADD, self.make_nid(win32gui.NIF_ICON | win32gui.NIF_MESSAGE | win32gui.NIF_TIP)) #register callbacks: win32NotifyIcon.live_hwnds.add(self.hwnd) win32NotifyIcon.move_callbacks[self.hwnd] = move_callbacks win32NotifyIcon.click_callbacks[self.hwnd] = click_callback win32NotifyIcon.exit_callbacks[self.hwnd] = exit_callback win32NotifyIcon.command_callbacks[self.hwnd] = command_callback
def new_icon(hdesk,desktop_name): """ Runs as a thread on each desktop to create a new tray icon and handle its messages """ global id id=id+1 hdesk.SetThreadDesktop() ## apparently the threads can't use same hinst, so each needs its own window class windowclassname='PythonDesktopManager'+desktop_name wc = win32gui.WNDCLASS() wc.hInstance = win32api.GetModuleHandle(None) wc.lpszClassName = windowclassname wc.style = win32con.CS_VREDRAW | win32con.CS_HREDRAW | win32con.CS_GLOBALCLASS wc.hCursor = win32gui.LoadCursor( 0, win32con.IDC_ARROW ) wc.hbrBackground = win32con.COLOR_WINDOW wc.lpfnWndProc = icon_wndproc windowclass = win32gui.RegisterClass(wc) style = win32con.WS_OVERLAPPED | win32con.WS_SYSMENU hwnd = win32gui.CreateWindow(windowclass, 'dm_'+desktop_name, win32con.WS_SYSMENU, 0, 0, win32con.CW_USEDEFAULT, win32con.CW_USEDEFAULT, 0, 0, wc.hInstance, None) win32gui.UpdateWindow(hwnd) flags = win32gui.NIF_ICON | win32gui.NIF_MESSAGE | win32gui.NIF_TIP notify_info = (hwnd, id, flags, win32con.WM_USER+20, hicon, 'Desktop Manager (%s)' %desktop_name) window_info[hwnd]=notify_info ## wait for explorer to initialize system tray for new desktop tray_found=0 while not tray_found: try: tray_found=win32gui.FindWindow("Shell_TrayWnd",None) except win32gui.error: traceback.print_exc time.sleep(.5) win32gui.Shell_NotifyIcon(win32gui.NIM_ADD, notify_info) win32gui.PumpMessages()
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 __init__(self): wx.EvtHandler.__init__(self) msg_TaskbarCreated = win32gui.RegisterWindowMessage("TaskbarCreated") message_map = { msg_TaskbarCreated: self.OnTaskbarCreated, win32con.WM_DESTROY: self.OnDestroy, win32con.WM_COMMAND: self.OnCommand, win32con.WM_USER + 20: self.OnTaskbarNotify } wc = win32gui.WNDCLASS() hinst = wc.hInstance = win32api.GetModuleHandle(None) wc.lpszClassName = "SysTrayIcon" wc.style = win32con.CS_VREDRAW | win32con.CS_HREDRAW wc.hCursor = win32api.LoadCursor(0, win32con.IDC_ARROW) wc.hbrBackground = win32con.COLOR_WINDOW wc.lpfnWndProc = message_map classAtom = win32gui.RegisterClass(wc) style = win32con.WS_OVERLAPPED | win32con.WS_SYSMENU self.hwnd = win32gui.CreateWindow(wc.lpszClassName, "SysTrayIcon", style, 0, 0, win32con.CW_USEDEFAULT, win32con.CW_USEDEFAULT, 0, 0, hinst, None) win32gui.UpdateWindow(self.hwnd) self._nid = None self.in_popup = False self.menu = None self.Bind(wx.EVT_TASKBAR_RIGHT_UP, self.OnRightUp) # With wxPython 4, calling <EvtHandler>.Destroy() no longer makes the # instance evaluate to False in boolean comparisons, so we emulate that # functionality self._destroyed = False
def __init__(self, menu_options, tray_name="willSpeak"): # Create instance level variable self.menu_options = menu_options # Create task mappings for try events message_map = { win32gui.RegisterWindowMessage("TaskbarCreated"): self.OnRestart, win32con.WM_DESTROY: self.OnDestroy, win32con.WM_COMMAND: self.OnCommand, win32con.WM_USER + 20: self.OnTaskbarNotify, } # Register the Window class. window_class = win32gui.WNDCLASS() window_class.lpszClassName = tray_name hinst = window_class.hInstance = win32gui.GetModuleHandle(None) window_class.style = win32con.CS_VREDRAW | win32con.CS_HREDRAW window_class.hCursor = win32gui.LoadCursor(0, win32con.IDC_ARROW) window_class.hbrBackground = win32con.COLOR_WINDOW window_class.lpfnWndProc = message_map classAtom = win32gui.RegisterClass(window_class) # Create the Window. style = win32con.WS_OVERLAPPED | win32con.WS_SYSMENU self.hwnd = win32gui.CreateWindow(classAtom, tray_name, style, 0, 0, win32con.CW_USEDEFAULT, win32con.CW_USEDEFAULT, 0, 0, hinst, None) win32gui.UpdateWindow(self.hwnd) self.notify_id = None self.create_icon() win32gui.PumpMessages()
def __init__(self, icon, hover_text, menu_options, on_quit=None, default_menu_index=None, window_class_name = "EnsoTrayWndClass",): self.default_icon = icon self.hover_text = hover_text self.notify_id = None if on_quit: self.on_quit = on_quit self.custom_menu_items = {} self.WM_ONLOAD = win32gui.RegisterWindowMessage("SystrayOnLoad") self.WM_CREATED = win32gui.RegisterWindowMessage("TaskbarCreated") message_map = { self.WM_CREATED : self._on_restart, self.WM_ONLOAD: self._on_load, win32con.WM_DESTROY: self._on_destroy, win32con.WM_COMMAND: self._on_command, win32con.WM_USER + 20 : self._on_taskbar_notify, } # Register the Window class. self._window_class = win32gui.WNDCLASS() self._window_class.hInstance = win32api.GetModuleHandle(None) self._window_class.lpszClassName = window_class_name self._window_class.style = win32con.CS_VREDRAW | win32con.CS_HREDRAW; self._window_class.hCursor = win32api.LoadCursor(0, win32con.IDC_ARROW) self._window_class.hbrBackground = win32con.COLOR_WINDOW self._window_class.lpfnWndProc = message_map # could also specify a wndproc. # Don't blow up if class already registered to make testing easier try: self.class_atom = win32gui.RegisterClass(self._window_class) except win32gui.error as err_info: if err_info.winerror != winerror.ERROR_CLASS_ALREADY_EXISTS: raise # Create the helper Window style = win32con.WS_OVERLAPPED | win32con.WS_SYSMENU self.hwnd = win32gui.CreateWindow( self.class_atom, window_class_name, #Title same as class-name style, 0, 0, win32con.CW_USEDEFAULT, win32con.CW_USEDEFAULT, 0, 0, self._window_class.hInstance, None) win32gui.UpdateWindow(self.hwnd) self._create_icons()
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 show(self): # Show main window win32gui.ShowWindow(self.hwnd, win32con.SW_SHOWNORMAL) win32gui.UpdateWindow(self.hwnd) # Show AtlAx window win32gui.ShowWindow(self.atlhwnd, win32con.SW_SHOW) win32gui.UpdateWindow(self.atlhwnd) win32gui.SetFocus(self.atlhwnd) # Pump messages msg = MSG() pMsg = pointer(msg) while _user32.GetMessageW(pMsg, None, 0, 0) != 0: _user32.TranslateMessage(pMsg) _user32.DispatchMessageW(pMsg) return msg.wParam
def _on_resize(self, hwnd, message, wparam, lparam): # Resize the ATL window as the size of the main window is changed if BrowserView.instance != None and not self.fullscreen: atl_hwnd = BrowserView.instance.atlhwnd width = win32api.LOWORD(lparam) height = win32api.HIWORD(lparam) win32gui.SetWindowPos(atl_hwnd, win32con.HWND_TOP, 0, 0, width, height, win32con.SWP_SHOWWINDOW) win32gui.ShowWindow(atl_hwnd, win32con.SW_SHOW) win32gui.UpdateWindow(atl_hwnd) return 0