如何更改组合框选择其他应用程序的值?Visual Basic

基努·洛伦佐(Keanu Lorenzo)

我知道如何使用以下代码单击另一个应用程序的按钮。但是现在我需要知道如何更改组合框的选定值。

'Declaration
Private Declare Auto Function FindWindow Lib "user32.dll" (ByVal lpClassName As String, ByVal lpWindowName As String) As IntPtr
Private Declare Auto Function FindWindowEx Lib "user32.dll" (ByVal hWndParent As IntPtr, ByVal hWndChildAfter As IntPtr, ByVal lpszClass As String, ByVal lpszWindow As String) As IntPtr
Declare Auto Function PostMessage Lib "user32.dll" (ByVal hWnd As IntPtr, ByVal Msg As Integer, ByVal wParam As IntPtr, ByRef lParam As IntPtr) As IntPtr
Private Const BM_CLICK = &HF5

'Usage
Dim ButtonHandle As IntPtr
Dim MainWindowHandle As IntPtr
MainWindowHandle = FindWindow(FormClass, FormCaption)
ButtonHandle = FindWindowEx(MainWindowHandle, IntPtr.Zero, TargetClass, TargetCaption)
If ButtonHandle <> 0 Then
    PostMessage(ButtonHandle, BM_CLICK, 0, 0)
End If

我需要做的就是将其他应用程序的组合框选定值从其默认值Off更改为On值。很感谢任何形式的帮助。谢谢你。

基努·洛伦佐(Keanu Lorenzo)

最后,我现在知道如何执行此操作。我使用的代码如下所示。

'Declaration
Private Declare Auto Function FindWindow Lib "user32.dll" (ByVal lpClassName As String, ByVal lpWindowName As String) As IntPtr
Private Declare Auto Function FindWindowEx Lib "user32.dll" (ByVal hWndParent As IntPtr, ByVal hWndChildAfter As IntPtr, ByVal lpszClass As String, ByVal lpszWindow As String) As IntPtr
Declare Auto Function PostMessage Lib "user32.dll" (ByVal hWnd As IntPtr, ByVal Msg As Integer, ByVal wParam As IntPtr, ByRef lParam As IntPtr) As IntPtr

Private Const BM_CLICK = &HF5
Private Const CB_SETCURSEL = &H14E

'Usage
Dim MainWindowHandle As IntPtr
Dim ChildAfter As IntPtr
Dim ComboBoxHandle As IntPtr
'Get the Handle
MainWindowHandle = FindWindow(FormClass, FormCaption)
'Get the ChildAfter of the Combo Box
ChildAfter = FindWindowEx(MainWindowHandle, IntPtr.Zero, ChildClass, ChildCaption)
'Get the handle of the combobox dropdown
ComboBoxHandle = FindWindowEx(MainWindowHandle, ChildAfter, "ComboBox", vbNullString)
'Select combo box index(1)
PostMessage(ComboBoxHandle, CB_SETCURSEL, 1, 0)

FindWindowExMSDN文档中

hwndChildAfter [in,可选]

类型:HWND

子窗口的句柄。搜索从Z顺序的下一个子窗口开始。子窗口必须是hwndParent的直接子窗口,而不仅仅是后代窗口。

如果hwndChildAfter为NULL,则搜索从hwndParent的第一个子窗口开始。

@RemyLebeau非常感谢您帮助我做到这一点。

本文收集自互联网,转载请注明来源。

如有侵权,请联系[email protected] 删除。

编辑于
0

我来说两句

0条评论
登录后参与评论

相关文章

来自分类Dev

Visual Basic 应用程序

来自分类Dev

加载 Visual Basic 应用程序

来自分类Dev

如何使用VBA代码关闭Visual Basic应用程序

来自分类Dev

如何使Visual Basic 2015表单应用程序作为控制台应用程序运行

来自分类Dev

从.NET单击Visual Basic应用程序中的按钮

来自分类Dev

应用程序冻结,但不会崩溃?(VISUAL BASIC)

来自分类Dev

从.NET单击Visual Basic应用程序中的按钮

来自分类Dev

用 Visual Basic .NET 编写的跨平台应用程序

来自分类Dev

如何使文件在Visual Basic应用程序中可供所有用户访问

来自分类Dev

如何获得用户的全名以显示在我的Visual Basic应用程序中?

来自分类Dev

如何在Visual Basic中打开Windows应用程序“ .exe”文件以查看代码?

来自分类Dev

无法更改组合框选择的项目

来自分类Dev

如何设置/更改已安装的Visual Basic应用程序的目标平台?有关corflag.exe位置和实际命令执行的说明

来自分类Dev

BASIC与Visual Basic有关吗?

来自分类Dev

Visual Basic 程序表现奇怪

来自分类Dev

Visual Basic设置文件

来自分类Dev

Visual Basic解析

来自分类Dev

Visual Basic MsgBox退出

来自分类Dev

Visual Basic拖放窗口

来自分类Dev

WebBrowser Visual Basic

来自分类Dev

Visual Basic查询

来自分类Dev

Visual Basic中的矩阵

来自分类Dev

Excel Visual Basic问题

来自分类Dev

Visual Basic中的计算

来自分类Dev

Microsoft Visual Basic

来自分类Dev

Visual Basic和MySQL

来自分类Dev

Visual Basic标签间距

来自分类Dev

Visual Basic拆分功能

来自分类Dev

Visual Basic中的XPath