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


Python win32gui.FindWindow方法代碼示例

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


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

示例1: TestObjectFromWindow

# 需要導入模塊: import win32gui [as 別名]
# 或者: from win32gui import FindWindow [as 別名]
def TestObjectFromWindow():
    # Check we can use ObjectFromLresult to get the COM object from the
    # HWND - see KB Q249232
    # Locating the HWND is different than the KB says...
    hwnd = win32gui.FindWindow('IEFrame', None)
    for child_class in ['TabWindowClass', 'Shell DocObject View',
                        'Internet Explorer_Server']:
        hwnd = win32gui.FindWindowEx(hwnd, 0, child_class, None)
        assert hwnd, "Couldn't find '%s'" % (child_class,)
    # But here is the point - once you have an 'Internet Explorer_Server',
    # you can send a message and use ObjectFromLresult to get it back.
    msg = win32gui.RegisterWindowMessage("WM_HTML_GETOBJECT")
    rc, result = win32gui.SendMessageTimeout(hwnd, msg, 0, 0, win32con.SMTO_ABORTIFHUNG, 1000)
    ob = pythoncom.ObjectFromLresult(result, pythoncom.IID_IDispatch, 0)
    doc = Dispatch(ob)
    # just to prove it works, set the background color of the document.
    for color in "red green blue orange white".split():
        doc.bgColor = color
        time.sleep(0.2) 
開發者ID:IronLanguages,項目名稱:ironpython2,代碼行數:21,代碼來源:testExplorer.py

示例2: find_window_movetop

# 需要導入模塊: import win32gui [as 別名]
# 或者: from win32gui import FindWindow [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

示例3: GetHWND

# 需要導入模塊: import win32gui [as 別名]
# 或者: from win32gui import FindWindow [as 別名]
def GetHWND(self, wname = None):
        '''
        Gets handle of window to view
        wname:         Title of window to find
        Return:        True on success; False on failure
        '''
        if wname is None:
            self.hwnd = win32gui.GetDesktopWindow()
        else:
            self.hwnd = win32gui.FindWindow(None, wname)    
        if self.hwnd == 0:
            self.hwnd = None
            return False
        self.l, self.t, self.r, self.b = win32gui.GetWindowRect(self.hwnd)
        return True 
開發者ID:nicholastoddsmith,項目名稱:poeai,代碼行數:17,代碼來源:ScreenViewer.py

示例4: __init__

# 需要導入模塊: import win32gui [as 別名]
# 或者: from win32gui import FindWindow [as 別名]
def __init__(self):
        self.hwnd = FindWindow(None, "掃雷")  # 獲取掃雷遊戲窗口的句柄
        assert self.hwnd, "請先打開掃雷,再運行該腳本程序"
        SendMessage(self.hwnd, WM_SYSCOMMAND, SC_RESTORE, 0)  # 還原最小化
        SetForegroundWindow(self.hwnd)  # 窗口置頂

        self.pixel_size = 16  # 每個格子的大小固定,為16個像素
        self.left, self.top, self.right, self.bottom = GetWindowRect(self.hwnd)  # 獲取窗口坐標
        self.rank = None  # 掃雷遊戲的等級,分為:高級、中級、初級,不包含自定義模式
        self.max_mines = 0  # 掃雷遊戲的所有雷的數目

        # 去除窗口邊框,隻保留所有格子
        self.left = self.left + 15  # 左邊框15個像素寬
        self.right = self.right - 11  # 右邊框11個像素寬
        self.bottom = self.bottom - 11  # 下邊框11個像素寬
        self.top = self.top + 101  # 尚邊框101個像素寬

        # 獲得遊戲橫向和縱向的格子數目
        self.height = int((self.bottom - self.top) / self.pixel_size)  # 掃雷遊戲的縱向格子數目
        assert self.height in [16, 16, 9]
        self.length = int((self.right - self.left) / self.pixel_size)  # 掃雷遊戲的橫向格子數目
        assert self.length in [30, 16, 9]

        # 獲取遊戲難度級別
        self.get_rank()
        self.get_max_mines() 
開發者ID:buaazyc,項目名稱:Automatic-minesweeping,代碼行數:28,代碼來源:window.py

示例5: getGameWindowPosition

# 需要導入模塊: import win32gui [as 別名]
# 或者: from win32gui import FindWindow [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

示例6: _get_pageant_window_object

# 需要導入模塊: import win32gui [as 別名]
# 或者: from win32gui import FindWindow [as 別名]
def _get_pageant_window_object():
    if _has_win32all:
        try:
            hwnd = win32gui.FindWindow('Pageant', 'Pageant')
            return hwnd
        except win32gui.error:
            pass
    elif _has_ctypes:
        # Return 0 if there is no Pageant window.
        return ctypes.windll.user32.FindWindowA('Pageant', 'Pageant')
    return None 
開發者ID:iopsgroup,項目名稱:imoocc,代碼行數:13,代碼來源:win_pageant.py

示例7: new_icon

# 需要導入模塊: import win32gui [as 別名]
# 或者: from win32gui import FindWindow [as 別名]
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() 
開發者ID:IronLanguages,項目名稱:ironpython2,代碼行數:35,代碼來源:desktopmanager.py

示例8: shot

# 需要導入模塊: import win32gui [as 別名]
# 或者: from win32gui import FindWindow [as 別名]
def shot(cls,name= 'playing.png'):
        hwnd = win32gui.FindWindow(None, cls.processname)

        # Change the line below depending on whether you want the whole window
        # or just the client area. 
        left, top, right, bot = win32gui.GetClientRect(hwnd)
        #left, top, right, bot = win32gui.GetWindowRect(hwnd)
        w = right - left
        h = bot - top

        hwndDC = win32gui.GetWindowDC(hwnd)
        mfcDC  = win32ui.CreateDCFromHandle(hwndDC)
        saveDC = mfcDC.CreateCompatibleDC()

        saveBitMap = win32ui.CreateBitmap()
        saveBitMap.CreateCompatibleBitmap(mfcDC, w, h)

        saveDC.SelectObject(saveBitMap)

        # Change the line below depending on whether you want the whole window
        # or just the client area. 
        #result = windll.user32.PrintWindow(hwnd, saveDC.GetSafeHdc(), 1)
        result = windll.user32.PrintWindow(hwnd, saveDC.GetSafeHdc(), 0)

        bmpinfo = saveBitMap.GetInfo()
        bmpstr = saveBitMap.GetBitmapBits(True)

        im = Image.frombuffer(
            'RGB',
            (bmpinfo['bmWidth'], bmpinfo['bmHeight']),
            bmpstr, 'raw', 'BGRX', 0, 1)

        win32gui.DeleteObject(saveBitMap.GetHandle())
        saveDC.DeleteDC()
        mfcDC.DeleteDC()
        win32gui.ReleaseDC(hwnd, hwndDC)

        if result == 1:
            #PrintWindow Succeeded
            im.save("playing.png") 
開發者ID:Sunuba,項目名稱:roc,代碼行數:42,代碼來源:Screenshot.py

示例9: findTopWindow

# 需要導入模塊: import win32gui [as 別名]
# 或者: from win32gui import FindWindow [as 別名]
def findTopWindow(wantedText=None, wantedClass=None):
    '''
    :param wantedText: 標題名字
    :param wantedClass: 窗口類名
    :return: 返回頂層窗口的句柄
    '''
    return win32gui.FindWindow(wantedClass, wantedText) 
開發者ID:ynzheng,項目名稱:pyautotrade_tdx,代碼行數:9,代碼來源:winguiauto.py

示例10: _get_application_hwnd

# 需要導入模塊: import win32gui [as 別名]
# 或者: from win32gui import FindWindow [as 別名]
def _get_application_hwnd() -> int:
        """
        This finds the blender application window and collects the
        handler window ID

        Returns int: Handler Window ID
        """

        hwnd = win32gui.FindWindow(None, 'blender')
        return hwnd 
開發者ID:techartorg,項目名稱:bqt,代碼行數:12,代碼來源:win32_blender_application.py

示例11: findSpecifiedTopWindow

# 需要導入模塊: import win32gui [as 別名]
# 或者: from win32gui import FindWindow [as 別名]
def findSpecifiedTopWindow(wantedText=None, wantedClass=None):
    '''
    :param wantedText: 標題名字
    :param wantedClass: 窗口類名
    :return: 返回頂層窗口的句柄
    '''
    return win32gui.FindWindow(wantedClass, wantedText) 
開發者ID:bluestinger,項目名稱:PyAutoTrading,代碼行數:9,代碼來源:winguiauto.py

示例12: __init__

# 需要導入模塊: import win32gui [as 別名]
# 或者: from win32gui import FindWindow [as 別名]
def __init__(self, window_name=None, exe_file=None, exclude_border=True):
        hwnd = 0

        # first check window_name
        if window_name is not None:
            hwnd = win32gui.FindWindow(None, window_name)
            if hwnd == 0:
                def callback(h, extra):
                    if window_name in win32gui.GetWindowText(h):
                        extra.append(h)
                    return True
                extra = []
                win32gui.EnumWindows(callback, extra)
                if extra: hwnd = extra[0]
            if hwnd == 0:
                raise WindowsAppNotFoundError("Windows Application <%s> not found!" % window_name)

        # check exe_file by checking all processes current running.
        elif exe_file is not None:
            pid = find_process_id(exe_file)
            if pid is not None:
                def callback(h, extra):
                    if win32gui.IsWindowVisible(h) and win32gui.IsWindowEnabled(h):
                        _, p = win32process.GetWindowThreadProcessId(h)
                        if p == pid:
                            extra.append(h)
                        return True
                    return True
                extra = []
                win32gui.EnumWindows(callback, extra)
                #TODO: get main window from all windows.
                if extra: hwnd = extra[0]
            if hwnd == 0:
                raise WindowsAppNotFoundError("Windows Application <%s> is not running!" % exe_file)

        # if window_name & exe_file both are None, use the screen.
        if hwnd == 0:
            hwnd = win32gui.GetDesktopWindow()

        self.hwnd = hwnd
        self.exclude_border = exclude_border 
開發者ID:NetEaseGame,項目名稱:ATX,代碼行數:43,代碼來源:windows.py

示例13: save_win

# 需要導入模塊: import win32gui [as 別名]
# 或者: from win32gui import FindWindow [as 別名]
def save_win(filename=None, title=None, crop=True):
    """
    Saves a window with the title provided as a file using the provided filename.
    If one of them is missing, then a window is created and the information collected

    :param filename:
    :param title:
    :return:
    """
    C = 7 if crop else 0  # pixels to crop
    if filename is None or title is None:
        layout = [[sg.T('Choose window to save', font='Any 18')],
                  [sg.T('The extension you choose for filename will determine the image format')],
                  [sg.T('Window Title:', size=(12, 1)), sg.I(title if title is not None else '', key='-T-')],
                  [sg.T('Filename:', size=(12, 1)), sg.I(filename if filename is not None else '', key='-F-')],
                  [sg.Button('Ok', bind_return_key=True), sg.Button('Cancel')]]
        event, values = sg.Window('Choose Win Title and Filename', layout).read(close=True)
        if event != 'Ok':  # if cancelled or closed the window
            print('Cancelling the save')
            return
        filename, title = values['-F-'], values['-T-']
    try:
        fceuxHWND = win32gui.FindWindow(None, title)
        rect = win32gui.GetWindowRect(fceuxHWND)
        rect_cropped = (rect[0] + C, rect[1], rect[2] - C, rect[3] - C)
        frame = np.array(ImageGrab.grab(bbox=rect_cropped), dtype=np.uint8)
        frame = cv2.cvtColor(frame, cv2.COLOR_BGR2RGB)
        cv2.imwrite(filename, frame)
        sg.cprint('Wrote image to file:', filename)
    except Exception as e:
        sg.popup('Error trying to save screenshot file', e, keep_on_top=True) 
開發者ID:PySimpleGUI,項目名稱:PySimpleGUI,代碼行數:33,代碼來源:Demo_Save_Windows_As_Images.py

示例14: save_win

# 需要導入模塊: import win32gui [as 別名]
# 或者: from win32gui import FindWindow [as 別名]
def save_win(filename=None, title=None):
    """
    Saves a window with the title provided as a file using the provided filename.
    If one of them is missing, then a window is created and the information collected

    :param filename:
    :param title:
    :return:
    """
    C = 7   # pixels to crop
    if filename is None or title is None:
        layout = [[sg.T('Choose window to save', font='Any 18')],
                  [sg.T('The extension you choose for filename will determine the image format')],
                  [sg.T('Window Title:', size=(12,1)), sg.I(title if title is not None else '', key='-T-')],
                  [sg.T('Filename:', size=(12,1)), sg.I(filename if filename is not None else '', key='-F-')],
                  [sg.Button('Ok', bind_return_key=True), sg.Button('Cancel')]]
        event, values = sg.Window('Choose Win Title and Filename',layout).read(close=True)
        if event != 'Ok':   # if cancelled or closed the window
            print('Cancelling the save')
            return
        filename, title = values['-F-'], values['-T-']
    try:
        fceuxHWND = win32gui.FindWindow(None, title)
        rect = win32gui.GetWindowRect(fceuxHWND)
        rect_cropped = (rect[0]+C, rect[1], rect[2]-C, rect[3]-C)
        frame = np.array(ImageGrab.grab(bbox=rect_cropped), dtype=np.uint8)
        frame = cv2.cvtColor(frame, cv2.COLOR_BGR2RGB)
        cv2.imwrite(filename, frame)
        sg.popup('Wrote image to file:',filename)
    except Exception as e:
        sg.popup('Error trying to save screenshot file', e) 
開發者ID:PySimpleGUI,項目名稱:PySimpleGUI,代碼行數:33,代碼來源:Demo_Save_Any_Window_As_Image.py

示例15: checkWindow

# 需要導入模塊: import win32gui [as 別名]
# 或者: from win32gui import FindWindow [as 別名]
def checkWindow(self):
        # 查找
        hwnd = win32gui.FindWindow('Notepad', None)
        if self.tmpHwnd and not hwnd:
            # 表示記事本關閉了
            self.checkTimer.stop()
            self.close()  # 關閉自己
            return
        if not hwnd:
            return
        self.tmpHwnd = hwnd
        # 獲取位置
        rect = win32gui.GetWindowRect(hwnd)
        print(rect)
        self.move(rect[2], rect[1]) 
開發者ID:PyQt5,項目名稱:PyQt,代碼行數:17,代碼來源:FollowWindow.py


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