1

I am trying to set the text value of an 'edit' control text box with the SendMessage() function. I am able to set the text about 75% of the time but sometimes the function fails. Why would it work sometimes and fail others? I am always getting the correct window handle and am confused as to what else it could be? Here's my code:

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
4

0 に答える 0