通过python中的winapi选择组合框

通过python中的winapi选择组合框,python,winapi,Python,Winapi,如何在python中选择带有winapi的ComboBox? 我目前的代码如下。 它选择combobox项,但对程序没有影响。 似乎没有触发任何事件 import win32gui import win32api import win32con class CBoxChanger: def run(): #init vars self.count=0 #get the desktop window lhWnd = wi

如何在python中选择带有winapi的ComboBox? 我目前的代码如下。 它选择combobox项,但对程序没有影响。 似乎没有触发任何事件

import win32gui
import win32api
import win32con

class CBoxChanger:

    def run():
        #init vars
        self.count=0

        #get the desktop window
        lhWnd = win32gui.GetDesktopWindow()

        #get the window window
        win32gui.EnumChildWindows(lhWnd, self.appHandler, l)

        #select toolbar
        win32gui.EnumChildWindows(self.window_hwnd, self.toolBarHandler, l)

        #select dialogbox
        GW_CHILD=5
        self.dialogbox_hwnd=win32gui.GetWindow(self.toolbar_hwnd,GW_CHILD)

        #select item nr 3
        index=2
        win32gui.SendMessage(self.dialogbox_hwnd,win32con.CB_SETCURSEL,index,0)



    def appHandler(self,lhWnd,lParam):
        text = win32gui.GetWindowText(lhWnd)
        if text=="WINDOWTITLE":
        self.window_hwnd=lhWnd

    def toolBarHandler(self,lhWnd,lParam):
        self.count+=1 
        if self.count==5:
            self.toolbar_hwnd=lhWnd

那么,我如何触发程序在所选组合框上处理重新定义所需的事件(如onclick或onselect事件)

找到了解决方案:扩展此

        #select item nr 3
        index=2
        win32gui.SendMessage(self.dialogbox_hwnd,win32con.CB_SETCURSEL,index,0)
与:


我不确定这是否是最简单的解决方案,但它是有效的

请看我的回答,在选择更改后,您可能必须通知家长。
        #select item nr 3
        index=2
        win32gui.SendMessage(self.dialogbox_hwnd,win32con.CB_SETCURSEL,index,0)

        #trigger event
        win32gui.SendMessage(self.dialogbox_hwnd, win32con.WM_LBUTTONDOWN, 0, 0)
        win32gui.SendMessage(self.dialogbox_hwnd, win32con.WM_LBUTTONUP, 0, 0)
        win32gui.SendMessage(self.dialogbox_hwnd, win32con.WM_KEYDOWN, win32con.VK_RETURN, 0)
        win32gui.SendMessage(self.dialogbox_hwnd, win32con.WM_KEYUP, win32con.VK_RETURN, 0)
        win32gui.SendMessage(self.dialogbox_hwnd, win32con.CBN_SELCHANGE)
        win32gui.SendMessage(self.dialogbox_hwnd, win32con.CBN_SELENDOK)