![](/img/trans.png)
[英]Retrieve a ComboBox counts and items by using SendMessage API
[英]sendmessage api to select a specific index of combobox control
我正在编写一个应用程序,它可以选择另一个应用程序的具有特定索引的ComboBox
。 例如,我想通过挂钩从我的应用程序中选择第二个列出的项目“Adobe flash player”。
ComboBox
应用程序不是我的,因此我无法修改目标应用程序。
通常,在 VB.Net 中使用Sendmessage
API 可以完成放置文本或单击按钮。
可以检索该ComboBox
的句柄值 (hWnd)。 我想知道要使用哪个函数 (api) 以及应该使用哪个值。
谢谢你。
您可以将CB_SETCURSEL
消息发送到组合框。 SendMessage
的wParam
参数应该是要设置为选定索引的项目的从零开始的索引, lParam
在这里无用。
应用程序发送
CB_SETCURSEL
消息以选择组合框列表中的字符串。 如有必要,列表会将字符串滚动到视图中。 组合框的编辑控件中的文本会发生变化以反映新的选择,并且删除列表中任何先前的选择。
wParam
:指定要选择的字符串的从零开始的索引。 如果此参数为 –1,则删除列表中的任何当前选择并清除编辑控件。lParam
:不使用此参数。
C# 示例
[System.Runtime.InteropServices.DllImport("user32.dll")]
static extern IntPtr SendMessage(IntPtr hWnd, int Msg, int wParam, int lParam);
const int CB_SETCURSEL = 0x014E;
void SetSelectedIndex(IntPtr comboBoxHandle, int index)
{
SendMessage(comboBoxHandle, CB_SETCURSEL, index, 0);
}
VB.NET 范例
<System.Runtime.InteropServices.DllImport("user32.dll")> _
Shared Function SendMessage(ByVal hWnd As IntPtr, ByVal Msg As Integer, _
ByVal wParam As Integer, ByVal lParam As Integer) As IntPtr
End Function
Const CB_SETCURSEL As Integer = &H14E
Sub SetSelectedIndex(comboBoxHandle As IntPtr, index As Integer)
SendMessage(comboBoxHandle, CB_SETCURSEL, index, 0)
End Sub
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.