# -*-encoding:utf-8 -*-
"""
@Time : 2022/11/17 16:49
@Auth : ruqing
@File :winhwnd.py
@IDE :PyCharm
@Motto:ABC(Always Be Coding)
"""
import win32con
import win32gui
import win32com
from pymouse import PyMouse
from pykeyboard import PyKeyboard


class WinHwnd(object):

    def __init__(self):
        self.win32c = win32con
        self.win32g = win32gui
        self.win32m = win32com
        self.mouse = PyMouse()
        self.keyboard = PyKeyboard()

    def get_all_hwnd(self, windows=None):
        """
        获取所有的窗口,并且指定需要最大化和前置的窗口,
        例:192.168.110.208--7030--6865--BMC - SecureCRT
        "192.168.110.208--7030--6865--BMC"
        """

        def foo(hwnd, mouse):
            if (self.win32g.IsWindow(hwnd) and self.win32g.IsWindowEnabled(hwnd) and self.win32g.IsWindowVisible(
                    hwnd)) and self.win32g.GetWindowText(hwnd):
                hwnd_map.update({hwnd: self.win32g.GetWindowText(hwnd)})

        hwnd_map = {}
        self.win32g.EnumWindows(foo, 0)
        print(hwnd_map)
        windows = windows
        for h, t in hwnd_map.items():
            if t:
                if t == windows:
                    self.win32g.SetForegroundWindow(h)
                    self.win32g.ShowWindow(h, self.win32c.SW_MAXIMIZE)

    def get_set_mouse(self, x=876, y=481, button=1, n=1):
        """
        获取当前鼠标的坐标,并且把鼠标点到指定的坐标上,默认值为x=1215, y=386, button=1, n=1,可以根据需要指定对应的坐标值
        """
        self.mouse.click(x=x, y=y, button=button, n=n)
        self.mouse.screen_size()
        self.mouse.position()


if __name__ == '__main__':
    hw = WinHwnd()
    hw.get_all_hwnd(
        windows='窗口句柄值')
    #
    # a = {1: '1', 2: '2', 3: '3'}
    # for t, i in a.items():
    #     print(t)
    #     print(i)


 

posted on 2022-11-18 15:59  Star*S  阅读(315)  评论(0)    收藏  举报