當前位置: 首頁>>代碼示例>>Python>>正文


Python win32gui.SetForegroundWindow方法代碼示例

本文整理匯總了Python中win32gui.SetForegroundWindow方法的典型用法代碼示例。如果您正苦於以下問題:Python win32gui.SetForegroundWindow方法的具體用法?Python win32gui.SetForegroundWindow怎麽用?Python win32gui.SetForegroundWindow使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在win32gui的用法示例。


在下文中一共展示了win32gui.SetForegroundWindow方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。

示例1: OnTaskbarNotify

# 需要導入模塊: import win32gui [as 別名]
# 或者: from win32gui import SetForegroundWindow [as 別名]
def OnTaskbarNotify(self, hwnd, msg, wparam, lparam):
        if lparam==win32con.WM_LBUTTONUP:
            print "You clicked me."
        elif lparam==win32con.WM_LBUTTONDBLCLK:
            print "You double-clicked me - goodbye"
            win32gui.DestroyWindow(self.hwnd)
        elif lparam==win32con.WM_RBUTTONUP:
            print "You right clicked me."
            menu = win32gui.CreatePopupMenu()
            win32gui.AppendMenu( menu, win32con.MF_STRING, 1023, "Display Dialog")
            win32gui.AppendMenu( menu, win32con.MF_STRING, 1024, "Say Hello")
            win32gui.AppendMenu( menu, win32con.MF_STRING, 1025, "Exit program" )
            pos = win32gui.GetCursorPos()
            # See http://msdn.microsoft.com/library/default.asp?url=/library/en-us/winui/menus_0hdi.asp
            win32gui.SetForegroundWindow(self.hwnd)
            win32gui.TrackPopupMenu(menu, win32con.TPM_LEFTALIGN, pos[0], pos[1], 0, self.hwnd, None)
            win32gui.PostMessage(self.hwnd, win32con.WM_NULL, 0, 0)
        return 1 
開發者ID:IronLanguages,項目名稱:ironpython2,代碼行數:20,代碼來源:win32gui_taskbar.py

示例2: show_menu

# 需要導入模塊: import win32gui [as 別名]
# 或者: from win32gui import SetForegroundWindow [as 別名]
def show_menu(self):
        menu = win32gui.CreatePopupMenu()
        self.create_menu(menu, self.menu_options)
        # win32gui.SetMenuDefaultItem(menu, 1000, 0)

        pos = win32gui.GetCursorPos()
        # See http://msdn.microsoft.com/library/default.asp?url=/library/en-us/winui/menus_0hdi.asp
        win32gui.SetForegroundWindow(self.hwnd)
        win32gui.TrackPopupMenu(menu,
                                win32con.TPM_LEFTALIGN,
                                pos[0],
                                pos[1],
                                0,
                                self.hwnd,
                                None)
        win32gui.PostMessage(self.hwnd, win32con.WM_NULL, 0, 0) 
開發者ID:samclane,項目名稱:LIFX-Control-Panel,代碼行數:18,代碼來源:SysTrayIcon.py

示例3: find_window_movetop

# 需要導入模塊: import win32gui [as 別名]
# 或者: from win32gui import SetForegroundWindow [as 別名]
def find_window_movetop(cls):
        hwnd = win32gui.FindWindow(None, cls.processname)
        win32gui.ShowWindow(hwnd,5)
        win32gui.SetForegroundWindow(hwnd)
        rect = win32gui.GetWindowRect(hwnd)
        sleep(0.2)
        return rect 
開發者ID:Sunuba,項目名稱:roc,代碼行數:9,代碼來源:Clicker.py

示例4: enumCallback

# 需要導入模塊: import win32gui [as 別名]
# 或者: from win32gui import SetForegroundWindow [as 別名]
def enumCallback(hwnd, self):
        title = win32gui.GetWindowText(hwnd)

        if title.find(self.windowName) > -1:
            try:
                win32gui.SetActiveWindow(hwnd)
                win32gui.SetForegroundWindow(hwnd)

                FInputs = Input * 1
                extra = c_ulong(0)
                ii_ = Input_I()
                ii_.ki = KeyBdInput(win32con.VK_F5, 0x3f, 0, 0, pointer(extra))
                x = FInputs(( 1, ii_ ))
                windll.user32.SendInput(1, pointer(x), sizeof(x[0]))

            except:
                pass

        return True 
開發者ID:MozillaSecurity,項目名稱:peach,代碼行數:21,代碼來源:process.py

示例5: bring_to_front

# 需要導入模塊: import win32gui [as 別名]
# 或者: from win32gui import SetForegroundWindow [as 別名]
def bring_to_front(self, new=True):
        """Bring a window into focus.
        Kept the old way just to be on the safe side.
        """
        if new:
            win32gui.ShowWindow(self.hwnd, True)
        else:
            self.restore()
            
        #Sometimes it seems to fail but then work a second time
        try:
            win32gui.SetForegroundWindow(self.hwnd)
        except pywintypes.error:
            time.sleep(0.5)
            win32gui.ShowWindow(self.hwnd, True)
            try:
                win32gui.SetForegroundWindow(self.hwnd)
            except pywintypes.error:
                pass 
開發者ID:Peter92,項目名稱:MouseTracks,代碼行數:21,代碼來源:main.py

示例6: show_menu

# 需要導入模塊: import win32gui [as 別名]
# 或者: from win32gui import SetForegroundWindow [as 別名]
def show_menu(self):
        """Draw the popup menu."""
        menu = win32gui.CreatePopupMenu()
        self._create_menu(menu, self.menu_options)
        
        pos = win32gui.GetCursorPos()
        # See http://msdn.microsoft.com/library/default.asp?url=/library/en-us/winui/menus_0hdi.asp
        win32gui.SetForegroundWindow(self.hwnd)
        win32gui.TrackPopupMenu(menu,
                                win32con.TPM_LEFTALIGN,
                                pos[0],
                                pos[1],
                                0,
                                self.hwnd,
                                None)
        win32gui.PostMessage(self.hwnd, win32con.WM_NULL, 0, 0)
        self.logger.debug('Menu displayed.') 
開發者ID:Peter92,項目名稱:MouseTracks,代碼行數:19,代碼來源:tray.py

示例7: _notify

# 需要導入模塊: import win32gui [as 別名]
# 或者: from win32gui import SetForegroundWindow [as 別名]
def _notify(klass, hwnd, msg, wparam, lparam):
        self = klass._instance[hwnd]
        if lparam == win32con.WM_LBUTTONDBLCLK:
            menu = self.get_popup()
            wid = win32gui.GetMenuDefaultItem(menu, 0, 0)
            if 0 < wid:
                win32gui.PostMessage(hwnd, win32con.WM_COMMAND, wid, 0)
        elif lparam == win32con.WM_RBUTTONUP:
            menu = self.get_popup()
            pos = win32gui.GetCursorPos()
            win32gui.SetForegroundWindow(hwnd)
            win32gui.TrackPopupMenu(
                menu, win32con.TPM_LEFTALIGN,
                pos[0], pos[1], 0, hwnd, None)
            win32gui.PostMessage(hwnd, win32con.WM_NULL, 0, 0)
        elif lparam == win32con.WM_LBUTTONUP:
            pass
        return True 
開發者ID:euske,項目名稱:pyrexecd,代碼行數:20,代碼來源:__init__.py

示例8: show_menu

# 需要導入模塊: import win32gui [as 別名]
# 或者: from win32gui import SetForegroundWindow [as 別名]
def show_menu(self):
        menu = win32gui.CreatePopupMenu()
        self.create_menu(menu, self.menu_options)
        #win32gui.SetMenuDefaultItem(menu, 1000, 0)
        
        pos = win32gui.GetCursorPos()
        # See http://msdn.microsoft.com/library/default.asp?url=/library/en-us/winui/menus_0hdi.asp
        win32gui.SetForegroundWindow(self.hwnd)
        win32gui.TrackPopupMenu(menu,
                                win32con.TPM_LEFTALIGN,
                                pos[0],
                                pos[1],
                                0,
                                self.hwnd,
                                None)
        win32gui.PostMessage(self.hwnd, win32con.WM_NULL, 0, 0) 
開發者ID:beville,項目名稱:ComicStreamer,代碼行數:18,代碼來源:gui_win.py

示例9: _show_menu

# 需要導入模塊: import win32gui [as 別名]
# 或者: from win32gui import SetForegroundWindow [as 別名]
def _show_menu( self ):
        menu = win32gui.CreatePopupMenu()
        for action in self.menu_actions:
            if action:
                flags = win32con.MF_STRING
                if not action.sensitive:
                    flags |= win32con.MF_GRAYED
                win32gui.AppendMenu( menu, flags, action.get_id(), action.label )
            else:
                win32gui.AppendMenu( menu, win32con.MF_SEPARATOR, 0, '' )
        
        pos = win32gui.GetCursorPos()
        
        win32gui.SetForegroundWindow( self.window_handle )
        win32gui.TrackPopupMenu( menu,
                                 win32con.TPM_LEFTALIGN | win32con.TPM_BOTTOMALIGN,
                                 pos[ 0 ],
                                 pos[ 1 ],
                                 0,
                                 self.window_handle,
                                 None )
        win32gui.PostMessage( self.window_handle, win32con.WM_NULL, 0, 0 ) 
開發者ID:mailpile,項目名稱:gui-o-matic,代碼行數:24,代碼來源:winapi.py

示例10: set_window_coordinates

# 需要導入模塊: import win32gui [as 別名]
# 或者: from win32gui import SetForegroundWindow [as 別名]
def set_window_coordinates(hwnd, window_info):
    if win32gui.IsWindowVisible(hwnd):
        if WINDOW_SUBSTRING in win32gui.GetWindowText(hwnd):
            rect = win32gui.GetWindowRect(hwnd)
            x = rect[0]
            y = rect[1]
            w = rect[2] - x
            h = rect[3] - y
            window_info['x'] = x
            window_info['y'] = y
            window_info['width'] = w
            window_info['height'] = h
            window_info['name'] = win32gui.GetWindowText(hwnd)
            win32gui.SetForegroundWindow(hwnd) 
開發者ID:maaaxim,項目名稱:bot,代碼行數:16,代碼來源:functions.py

示例11: snapshot

# 需要導入模塊: import win32gui [as 別名]
# 或者: from win32gui import SetForegroundWindow [as 別名]
def snapshot(self, filename=None ):
        ''' Capture device screen '''
        range_ = self._range()
        win32gui.SetForegroundWindow(self.HWND)
        time.sleep(0.1)
        pic = ImageGrab.grab(range_)
        if filename !=None:
            pic.save(filename)
        return pic 
開發者ID:NetEase,項目名稱:airtest,代碼行數:11,代碼來源:windows.py

示例12: focusWindow

# 需要導入模塊: import win32gui [as 別名]
# 或者: from win32gui import SetForegroundWindow [as 別名]
def focusWindow(hwnd):
    '''
    捕捉窗口焦點
    :param hwnd: 窗體句柄
    :return:
    '''
    win32gui.ShowWindow(hwnd, win32con.SW_SHOWMAXIMIZED)
    win32gui.SetForegroundWindow(hwnd) 
開發者ID:ynzheng,項目名稱:pyautotrade_tdx,代碼行數:10,代碼來源:winguiauto.py

示例13: enum_window_callback

# 需要導入模塊: import win32gui [as 別名]
# 或者: from win32gui import SetForegroundWindow [as 別名]
def enum_window_callback(hwnd, pid):
    tid, current_pid = win32process.GetWindowThreadProcessId(hwnd)
    if pid == current_pid and win32gui.IsWindowVisible(hwnd):
        win32gui.SetForegroundWindow(hwnd)
        l("window activated") 
開發者ID:xulusjb,項目名稱:PUBG,代碼行數:7,代碼來源:main.py

示例14: swap_focus

# 需要導入模塊: import win32gui [as 別名]
# 或者: from win32gui import SetForegroundWindow [as 別名]
def swap_focus(func):
    """
    Use this decorator for any method that does an action in premiere. Not needed for queries but for any action
    that will change something in the UI we have to give focus to Premiere
    """
    def wrapper(self, *args, **kwargs):
        win32gui.SetForegroundWindow(self.premiere_window_id)
        result = func(self, *args, **kwargs)
        win32gui.SetForegroundWindow(self.ui_id)
        return result
    return wrapper 
開發者ID:qmasingarbe,項目名稱:pymiere,代碼行數:13,代碼來源:demo_ui.py

示例15: getGameWindowPosition

# 需要導入模塊: import win32gui [as 別名]
# 或者: from win32gui import SetForegroundWindow [as 別名]
def getGameWindowPosition():
    # FindWindow(lpClassName=None, lpWindowName=None)  窗口類名 窗口標題名
    window = win32gui.FindWindow(None,WINDOW_TITLE)
    # 沒有定位到遊戲窗體
    while not window:
        print('定位遊戲窗體失敗,5秒後重試...')
        time.sleep(5)
        window = win32gui.FindWindow(None,WINDOW_TITLE)
    # 定位到遊戲窗體
    win32gui.SetForegroundWindow(window) # 將窗體頂置
    pos = win32gui.GetWindowRect(window)
    print("定位到遊戲窗體:" + str(pos))
    return (pos[0],pos[1])

# 獲取一張完整的屏幕截圖 
開發者ID:TheThreeDog,項目名稱:Auto-Lianliankan,代碼行數:17,代碼來源:run.py


注:本文中的win32gui.SetForegroundWindow方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。