sendmessage api 选择组合框控件的特定索引 [英] sendmessage api to select a specific index of combobox control

查看:23
本文介绍了sendmessage api 选择组合框控件的特定索引的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在编写一个应用程序,该应用程序可以使用特定索引选择另一个应用程序的 ComboBox.例如,我想通过钩子从我的应用程序中选择第二个列出的项目Adobe flash player".

I am coding an app that can select another app's ComboBox with a certain index. For example, I want to select the second listed item "Adobe flash player" from my app with hooking.

ComboBox 应用不是我的,所以我无法修改目标应用.

The ComboBox app is not mine so I cannot modify the target app.

通常,可以通过使用 VB.Net 中的 Sendmessage API 来放置文本或单击按钮.

Usually, putting a text or clicking a button can be done by using Sendmessage API in VB.Net.

可以检索该ComboBox 的句柄值(hWnd).我想知道使用哪个函数(api)以及应该使用哪个值.

The handle value(hWnd) of that ComboBox can be retrieved. I want to know which function(api) to use and which value should be used.

谢谢.

推荐答案

您可以发送 CB_SETCURSEL 消息到组合框.SendMessage 应该是您要设置为选定索引的项目的从零开始的索引和 lParam 在这里没用.

You can send CB_SETCURSEL message to the combo box. The wParam parameter of SendMessage should be zero-based index of the item which you want to set as selected index and the lParam is useless here.

应用程序发送 CB_SETCURSEL 消息来选择一个字符串组合框的列表.如有必要,列表会将字符串滚动到看法.组合框的编辑控件中的文本更改以反映新选择,以及列表中的任何先前选择.

An application sends a CB_SETCURSEL message to select a string in the list of a combo box. If necessary, the list scrolls the string into view. The text in the edit control of the combo box changes to reflect the new selection, and any previous selection in the list is removed.

  • wParam:指定要选择的字符串的从零开始的索引.如果这参数为 –1,列表中的任何当前选择都将被删除,并且编辑控制被清除.
  • lParam:未使用此参数.
  • wParam: Specifies the zero-based index of the string to select. If this parameter is –1, any current selection in the list is removed and the edit control is cleared.
  • lParam: This parameter is not used.

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

这篇关于sendmessage api 选择组合框控件的特定索引的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆