Exemplo n.º 1
0
    def getpausemenuitemid(self):  # get the pause menu item id

        w = self.gettaskman()
        m = win32gui.GetMenu(w)
        sm = win32gui.GetSubMenu(m, 2)
        ssm = win32gui.GetSubMenu(sm, 1)
        pauseID = win32gui.GetMenuItemID(ssm, 3)
        return pauseID
Exemplo n.º 2
0
    def get_menu(self):
        """menu操作(记事本)"""

        menu = win32gui.GetMenu(self.handle)
        menu1 = win32gui.GetSubMenu(menu, 0)  # 第几个菜单 0-第一个
        cmd_ID = win32gui.GetMenuItemID(menu1, 3)  # 第几个子菜单
        win32gui.PostMessage(self.handle, win32con.WM_COMMAND, cmd_ID, 0)
        menu_text1 = [self.get_menu_text(menu, i) for i in range(5)]
        menu_text2 = [self.get_menu_text(menu1, i) for i in range(9)]

        print(menu_text1)
        print(menu_text2)
Exemplo n.º 3
0
def AccountLogin_LoginFail():
    try:
        global_TB.status = 10
        if global_TB.TB_handle != 0:
            #times=1
            if win32gui.SendMessage(
                    win32gui.FindWindowEx(
                        win32gui.FindWindowEx(
                            win32gui.FindWindowEx(
                                global_TB.TB_handle,
                                win32gui.FindWindowEx(
                                    global_TB.TB_handle, 0, 'AfxControlBar110',
                                    None), 'AfxControlBar110', None), 0, None,
                            '帐户管理'), 0, 'SysListView32', None),
                    LVM_GETITEMCOUNT) < 1:
                if global_TB.times < 150:
                    Log('柜台关闭')
                    global_TB.status = 11
                    win32gui.PostMessage(
                        global_TB.TB_handle, win32con.WM_COMMAND,
                        win32gui.GetMenuItemID(
                            win32gui.GetSubMenu(
                                win32gui.GetMenu(global_TB.TB_handle), 7),
                            17), 0)  #帐户登录
                    win32gui.SendMessage(
                        win32gui.FindWindowEx(
                            win32gui.FindWindow('#32770', '帐户登录'), 0, 'Button',
                            '登录(&L)'), win32con.WM_ACTIVATE,
                        win32con.WA_ACTIVE, 0)  #激活窗口
                    time.sleep(4)
                    win32gui.SendMessage(
                        win32gui.FindWindowEx(
                            win32gui.FindWindow('#32770', '帐户登录'), 0, 'Button',
                            '登录(&L)'), win32con.BM_CLICK, 1, 0)
                    global_TB.times = global_TB.times + 1
                    Log(str(global_TB.times) + ' 次登录')
                    time.sleep(15)
                    global_TB.Accounts = win32gui.SendMessage(
                        win32gui.FindWindowEx(
                            win32gui.FindWindowEx(
                                win32gui.FindWindowEx(
                                    global_TB.TB_handle,
                                    win32gui.FindWindowEx(
                                        global_TB.TB_handle, 0,
                                        'AfxControlBar110', None),
                                    'AfxControlBar110', None), 0, None,
                                '帐户管理'), 0, 'SysListView32', None),
                        LVM_GETITEMCOUNT)
                    global_TB.Trade = 0
                #else:
                #break;
    except Exception as e:
        Log(str(e))
Exemplo n.º 4
0
def SaveWorkSpace():
    try:
        global_TB.status = 5
        if global_TB.TB_handle != 0:
            win32gui.PostMessage(global_TB.TB_handle, win32con.WM_COMMAND,
                                 win32gui.GetMenuItemID(
                                     win32gui.GetSubMenu(
                                         win32gui.GetMenu(global_TB.TB_handle),
                                         0), 9), 0)  #保存所有工作区
            Log('保存工作区')
        time.sleep(2)
    except Exception as e:
        Log(str(e))
Exemplo n.º 5
0
def TradeStar():
    if global_TB.TB_handle != 0 and global_TB.Accounts > 0 and global_TB.Monitor_handle == 0 and global_TB.Trade == 0:
        try:
            global_TB.status = 3
            win32gui.PostMessage(global_TB.TB_handle, win32con.WM_COMMAND,
                                 win32gui.GetMenuItemID(
                                     win32gui.GetSubMenu(
                                         win32gui.GetMenu(global_TB.TB_handle),
                                         0), 22), 0)  #启动所有自动交易
            Log('启动交易')
            global_TB.Trade = 1
            time.sleep(1)
        except Exception as e:
            Log(str(e))
Exemplo n.º 6
0
def TradeStop():
    try:
        global_TB.status = 7
        if global_TB.TB_handle != 0:
            win32gui.PostMessage(global_TB.TB_handle, win32con.WM_COMMAND,
                                 win32gui.GetMenuItemID(
                                     win32gui.GetSubMenu(
                                         win32gui.GetMenu(global_TB.TB_handle),
                                         0), 23), 0)  #停止所有自动交易
            #global global_TB.Trade
            global_TB.Trade = 0
            Log('停止交易')
            time.sleep(2)
    except Exception as e:
        Log(str(e))
Exemplo n.º 7
0
def MonitorStar():
    if win32gui.FindWindow('#32770', '自动交易头寸监控器') == 0:
        try:
            global_TB.status = 4
            if global_TB.TB_handle != 0 and global_TB.Accounts > 0 and global_TB.Monitor_handle == 0 and global_TB.Trade == 1:
                win32gui.PostMessage(global_TB.TB_handle, win32con.WM_COMMAND,
                                     win32gui.GetMenuItemID(
                                         win32gui.GetSubMenu(
                                             win32gui.GetMenu(
                                                 global_TB.TB_handle), 7), 11),
                                     0)  #监控器
                #print (st)
                Log('打开监控')
                time.sleep(1)
            #取得监控器句柄
            global_TB.Monitor_handle = win32gui.FindWindow(
                '#32770', '自动交易头寸监控器')
            #win32gui.SetForegroundWindow(global_TB.Monitor_handle)
            #win32gui.BringWindowToTop(global_TB.Monitor_handle)
            #win32gui.SetActiveWindow(global_TB.Monitor_handle)
            #win32gui.SetFocus(global_TB.Monitor_handle)
            #win32gui.ShowWindow(global_TB.Monitor_handle,win32con.SW_MINIMIZE)
            #win32gui.ShowWindow(global_TB.Monitor_handle,5)
            #win32gui.SetWindowPos(global_TB.TB_handle,win32con.HWND_TOPMOST,0,0,0,0,win32con.SWP_SHOWWINDOW)
            #win32gui.SetWindowPos(global_TB.Monitor_handle,win32con.HWND_TOP,0,0,0,0,win32con.SWP_SHOWWINDOW)
            #win32gui.PostMessage(global_TB.Monitor_handle,win32con.BM_CLICK,1,0)
            #pos=win32gui.GetWindowRect(global_TB.Monitor_handle)
            win32gui.ShowWindow(global_TB.TB_handle, win32con.SW_MINIMIZE)
            time.sleep(1)
            win32gui.ShowWindow(global_TB.TB_handle, win32con.SW_MAXIMIZE)
            '''
            win32api.SetCursorPos([1000,800])
            time.sleep(1)
            win32api.mouse_event(win32con.MOUSEEVENTF_LEFTDOWN,0,0,0,0)
            time.sleep(1)
            win32api.mouse_event(win32con.MOUSEEVENTF_LEFTUP,0,0,0,0)
            time.sleep(1)
            '''
        except Exception as e:
            Log(str(e))
Exemplo n.º 8
0
print("%x" %(handle) )


# 搜索子窗口
# 枚举子窗口
hwndChildList = []
win32gui.EnumChildWindows(handle, lambda hwnd, param: param.append(hwnd),  hwndChildList)

# FindWindowEx(hwndParent=0, hwndChildAfter=0, lpszClass=None, lpszWindow=None) 父窗口句柄 若不为0,则按照z-index的顺序从hwndChildAfter向后开始搜索子窗体,否则从第一个子窗体开始搜索。 子窗口类名 子窗口标题
subHandle = win32gui.FindWindowEx(handle, 0, "EDIT", None)

# 获得窗口的菜单句柄
menuHandle = win32gui.GetMenu(subHandle)
# 获得子菜单或下拉菜单句柄
# 参数:菜单句柄 子菜单索引号
subMenuHandle = win32gui.GetSubMenu(menuHandle, 0)
# 获得菜单项中的的标志符,注意,分隔符是被编入索引的
# 参数:子菜单句柄 项目索引号
menuItemHandle = win32gui.GetMenuItemID(subMenuHandle, 0)
# 发送消息,加入消息队列,无返回
# 参数:句柄 消息类型 WParam IParam
win32gui.postMessage(subHandle, win32con.WM_COMMAND, menuItemHandle, 0)


# wParam的定义是32位整型,high word就是他的31至16位,low word是它的15至0位。
# 当参数超过两个,wParam和lParam不够用时,可以将wParam就给拆成两个int16来使用。
# 这种时候在python里记得用把HIWORD的常数向左移16位,再加LOWORD,即wParam = HIWORD<<16+LOWORD。

# 下选框内容更改
# 参数:下选框句柄; 消息内容; 参数下选框的哪一个item,以0起始的待选选项的索引;如果该值为-1,将从组合框列表中删除当前选项,并使当前选项为空; 参数
# CB_Handle为下选框句柄,PCB_handle下选框父窗口句柄
Exemplo n.º 9
0
import win32api
import win32con
import win32gui

# 得到父窗体句柄(主窗体)
# handle = win32gui.FindWindow(None,"ToolbarWindow32")  # {窗口标题:Caption}, {窗口类名:Class}
handle = 0x00071180
menu = win32gui.GetMenu(handle) # 菜单
menu1 = win32gui.GetSubMenu(menu, 1) # 第几个菜单
cmd_ID = win32gui.GetMenuItemID(menu1, 10) # 第几个子菜单
# 发送事件消息给菜单
#win32gui.PostMessage(hwnd, win32con.WM_COMMAND, cmd_ID, 1)

# 获取菜单的文本内容
def get_menu_item_txt(menu, idx):
    import win32gui_struct
    mii, extra = win32gui_struct.EmptyMENUITEMINFO() # 新建一个win32gui的空的结构体mii
    win32gui.GetMenuItemInfo(menu, idx, True, mii)
    ftype, fstate, wid, hsubmenu, hbmpchecked, hbmpunchecked,\
    dwitemdata, text, hbmpitem = win32gui_struct.UnpackMENUITEMINFO(mii) # 解包mii
    return text

# 遍历显示出菜单文本
for i in range(5):
    print(get_menu_item_txt(menu, i))
for i in range(5):
    print(get_menu_item_txt(menu1, i))
Exemplo n.º 10
0
    def run(self):

        #delay 
        time.sleep(2)
        
        # """
        # 记事本实例
        # """
        #获取实例
        notepadHhandle = win32gui.FindWindow("Notepad", None)
        # notepadHhandle = win32gui.FindWindow(None,"text1.txt")
        print ("记事本实例 %x" % (notepadHhandle))

        #获取句柄
        editHandle = find_subHandle(notepadHhandle, [("Edit",0)])
        print ("句柄 %x" % (editHandle))

        """修改edit中的值"""
        # win32api.SendMessage(editHandle, win32con.WM_SETTEXT, 0, "测试1")
        
        command_dict = {  # [目录的编号, 打开的窗口名]  
                    "new": [0, u"新建"],
                    "newwin": [1, u"新窗口"],
                    "open": [2, u"打开"],
                    "save": [3, u"保存"],
                    "saveas": [4, u"另存为"],
                    "quit": [9, u"退出"],
                }  
        
        """操作菜单 另存为"""

        menu = win32gui.GetMenu(notepadHhandle)
        menu = win32gui.GetSubMenu(menu, 0)  
        cmd_ID = win32gui.GetMenuItemID(menu, command_dict["saveas"][0])
        if cmd_ID == -1:
            print("没有找到相应的菜单")
        else:
            print ("菜单id:%x" % (cmd_ID))
        win32gui.PostMessage(notepadHhandle, win32con.WM_COMMAND, cmd_ID, 0)  



        #window "另存为" 
        time.sleep(2)
        #获取实例
        notepadHhandle_save = win32gui.FindWindow(None,"另存为")
        print ("另存为 %x" % (notepadHhandle))


        #获取编码选择句柄
        notepadcombobox = win32gui.FindWindowEx(notepadHhandle_save,None,"ComboBox",None)
        print("编码 %x" % (notepadcombobox))

        #设置为ANSI
        ANSI=0
        UTF8=3
        win32gui.PostMessage(notepadcombobox,win32con.CB_SETCURSEL,ANSI,0)

        #获取保存按钮句柄
        notepadbutton = win32gui.FindWindowEx(notepadHhandle_save,None,"Button","保存(&S)")
        print("另存为按钮 %x" % (notepadbutton))


        #回车
        win32gui.PostMessage(notepadbutton, win32con.WM_KEYDOWN, win32con.VK_RETURN, 0)

        win32gui.PostMessage(notepadbutton, win32con.WM_KEYUP, win32con.VK_RETURN, 0)


        
        #window "确认另存为"
        time.sleep(2)
        #获取实例
        notepadHhandle_confirmsave = win32gui.FindWindow(None,"确认另存为")
        print ("确认另存为 %x" % (notepadHhandle_confirmsave))

        
        win32gui.EnumChildWindows(notepadHhandle_confirmsave,self.get_child_windows, None)


        for widget in self.widgets:
            # print(widget['handle'])
            # print(widget['class'])
            # print(widget['title'])
            # print(widget['pos'])

            if widget['title'] == "是(&Y)" and widget['class'] == "Button":

                print(widget['title'])
                print(widget['class'])
                print(widget['pos'])

                # print(widget['pos'][1])

                point = (widget['pos'][0], widget['pos'][1])
                win32api.SetCursorPos(point)
                #点击鼠标
                win32api.mouse_event(win32con.MOUSEEVENTF_LEFTUP | win32con.MOUSEEVENTF_LEFTDOWN, 0, 0, 0, 0)


        #关闭记事本
        time.sleep(2)
        cmd_ID = win32gui.GetMenuItemID(menu, command_dict["quit"][0])
        if cmd_ID == -1:
            print("没有找到相应的菜单")
        else:
            print ("菜单id:%x" % (cmd_ID))
        win32gui.PostMessage(notepadHhandle, win32con.WM_COMMAND, cmd_ID, 0)  
Exemplo n.º 11
0
def Export_fbk():
    try:
        while win32gui.FindWindow('#32770', '导入/导出公式') == 0:
            win32gui.EnumWindows(handle_window, '交易开拓者')
            if win32gui.FindWindow('#32770', '自动交易头寸监控器') != 0:
                time.sleep(2)
                win32gui.ShowWindow(win32gui.FindWindow('#32770', '自动交易头寸监控器'),
                                    win32con.SW_MINIMIZE)
                time.sleep(1)

            #win32gui.BringWindowToTop(global_TB.TB_handle)
            #win32gui.ShowWindow(win32gui.FindWindowEx(win32gui.FindWindowEx(win32gui.FindWindowEx(global_TB.TB_handle,None,'AfxControlBar110','PanelFrame'),None,0,'PanelFrame'),None,'AfxWnd110',None),win32con.SW_MAXIMIZE)
            time.sleep(1)
            win32gui.PostMessage(global_TB.TB_handle, win32con.WM_COMMAND,
                                 win32gui.GetMenuItemID(
                                     win32gui.GetSubMenu(
                                         win32gui.GetMenu(global_TB.TB_handle),
                                         1), 1), 0)  #面板 F3
            time.sleep(3)
            pos = win32gui.GetWindowRect(
                win32gui.FindWindowEx(
                    win32gui.FindWindowEx(
                        win32gui.FindWindowEx(global_TB.TB_handle, None,
                                              'AfxControlBar110',
                                              'PanelFrame'), None, 0,
                        'PanelFrame'), None, 'AfxWnd110', None))
            time.sleep(1)
            win32api.SetCursorPos([int((pos[0] + pos[2]) / 2), pos[3] - 35])
            time.sleep(1)
            win32api.mouse_event(win32con.MOUSEEVENTF_LEFTDOWN, 0, 0, 0, 0)
            time.sleep(1)
            win32api.mouse_event(win32con.MOUSEEVENTF_LEFTUP, 0, 0, 0, 0)
            time.sleep(1)

            win32api.SetCursorPos([int((pos[0] + pos[2]) / 2), pos[1] + 255])
            time.sleep(1)
            win32api.mouse_event(win32con.MOUSEEVENTF_LEFTDOWN, 0, 0, 0, 0)
            time.sleep(1)
            win32api.mouse_event(win32con.MOUSEEVENTF_LEFTUP, 0, 0, 0, 0)
            time.sleep(3)

        win32gui.PostMessage(
            win32gui.FindWindowEx(win32gui.FindWindow('#32770', '导入/导出公式'),
                                  None, 'Button', '下一步(&N) >'),
            win32con.BM_CLICK, 1, 0)
        time.sleep(1)
        win32gui.PostMessage(
            win32gui.FindWindowEx(
                win32gui.FindWindowEx(win32gui.FindWindow('#32770', '导出公式'),
                                      None, '#32770', '导出公式'), None, 'Button',
                '>>'), win32con.BM_CLICK, 1, 0)
        time.sleep(1)
        win32gui.PostMessage(
            win32gui.FindWindowEx(win32gui.FindWindow('#32770', '导出公式'), None,
                                  'Button', '下一步(&N) >'), win32con.BM_CLICK, 1,
            0)
        time.sleep(1)
        win32gui.PostMessage(
            win32gui.FindWindowEx(
                win32gui.FindWindowEx(win32gui.FindWindow('#32770', '导出公式'),
                                      None, '#32770', '导出公式'), None, 'Button',
                '浏览(&O)...'), win32con.BM_CLICK, 1, 0)
        time.sleep(1)
        win32gui.SendMessage(
            win32gui.FindWindowEx(
                win32gui.FindWindowEx(
                    win32gui.FindWindowEx(
                        win32gui.FindWindowEx(
                            win32gui.FindWindowEx(
                                win32gui.FindWindow('#32770', '保存公式备份文件'),
                                None, 'DUIViewWndClassName', None), None,
                            'DirectUIHWND', None), None, 'FloatNotifySink',
                        None), None, 'ComboBox', None), None, 'Edit', None),
            win32con.WM_SETTEXT, 0, global_TB.fbk)  #%H%M%S
        time.sleep(1)
        win32gui.PostMessage(
            win32gui.FindWindowEx(win32gui.FindWindow('#32770', '保存公式备份文件'),
                                  None, 'Button', '保存(&S)'), win32con.BM_CLICK,
            1, 0)
        time.sleep(1)
        win32gui.PostMessage(
            win32gui.FindWindowEx(win32gui.FindWindow('#32770', '导出公式'), None,
                                  'Button', '完成'), win32con.BM_CLICK, 1, 0)
        time.sleep(1)
        win32gui.PostMessage(
            win32gui.FindWindowEx(win32gui.FindWindow('#32770', '提示'), None,
                                  'Button', '确定'), win32con.BM_CLICK, 1, 0)
        time.sleep(1)
    except Exception as e:
        Log(str(e))
Exemplo n.º 12
0
 def getChildhandle(self, menuhandle):
     subMenuHandle = win32gui.GetSubMenu(menuhandle, 0)
     return subMenuHandle
Exemplo n.º 13
0
 def __init__(self, fgFilePath=None):
     self.Mhandle = win32gui.FindWindow("FaceGenMainWinClass", None)
     self.menu = win32gui.GetMenu(self.Mhandle)
     # the first sub menu to linitialize
     self.menu = win32gui.GetSubMenu(self.menu, 0)
     print "FaceGen initialization compeleted"
Exemplo n.º 14
0
import win32gui
import win32api
import win32con
import pyperclip
import win32ui
import time

mainWindow_name = u'YINCHUAN TERMINAL DVOR - Dual DVOR - SELEX Systems Integration Inc. PMDT'
MW_hwnd = win32gui.FindWindow(None, mainWindow_name)
main_menu = win32gui.GetMenu(MW_hwnd)
aim_menu = win32gui.GetSubMenu(main_menu, 2)
cmd_ID = win32gui.GetMenuItemID(aim_menu, 0)
win32gui.PostMessage(MW_hwnd, win32con.WM_COMMAND, cmd_ID, 0)
print("%x" % (MW_hwnd))

time.sleep(1)

dialog = win32gui.FindWindowEx(MW_hwnd, None, '#32770', None)
copy_btn = win32gui.FindWindowEx(dialog, None, 'Button', 'Copy')
print("%x" % (copy_btn))
win32gui.PostMessage(copy_btn, win32con.WM_LBUTTONDOWN, win32con.MK_LBUTTON, 0)
win32gui.PostMessage(copy_btn, win32con.WM_LBUTTONUP, win32con.MK_LBUTTON, 0)
# win32gui.PostMessage(dialog, win32con.WM_COMMAND, copy_btn, 0)
text = pyperclip.paste()
print(text)

# hwnd = win32gui.FindWindow(None, "YINCHUAN TERMINAL DVOR - Dual DVOR - SELEX Systems Integration Inc. PMDT")
# hwnd = win32gui.FindWindow(None, "PMDT")
# print(hwnd)
# name = 'hello'
# pyperclip.copy(name)