使用SendMessage()设置文本框文本

时间:2015-08-06 15:26:25

标签: vb6 sendmessage windows-api-code-pack

我正在尝试设置'编辑'的文本值。使用SendMessage()函数控制文本框。我能够在75%的时间内设置文本,但有时功能失败。为什么它有时会起作用并使其他人失败?我总是得到正确的窗口句柄,并对它还能做什么感到困惑?这是我的代码:

attempt = 1
retry:
    'Find open window textbox
    temp_id = 0
    temp_id = FindWindowEx(open_id, ByVal 0&, "ComboBoxEx32", vbNullString)
    temp_id = FindWindowEx(temp_id, ByVal 0&, "ComboBox", vbNullString)
    text_id = FindWindowEx(temp_id, ByVal 0&, "Edit", vbNullString)

    'Select textbox and enter text then press open button
    Call SendMessage(text_id, WM_LBUTTONDBLCLK, 0, 0)
    Sleep 100
    text = filename

    Call SendMessage(text_id, WM_SETTEXT, 0&, ByVal text)
    DoEvents
    Sleep 100

    If GetWindowTextLength(text_id) = 0 Then
        If attempt < 3 Then
            attempt = attempt + 1
            GoTo retry
        End If
    End If

0 个答案:

没有答案