Why is guiInfo.hwndCaret = 0 when I use GetGUIThreadInfo on Chrome browser instead of Notepad?

Viewed 58

I use the following approach sucessfully to copy the selected text from other applications.

The following works fine for Notepad:

Dim ThreadID1&
Dim ThreadID2&
'
' First need to get the thread responsible for this window,
' and the thread for the foreground window.

Dim lFore&
lFore = GetForegroundWindow()

Debug.Print "foreground: " & modWindow.WindowTitleFromHwnd(lFore)

ThreadID1 = GetWindowThreadProcessId(lFore, ByVal 0&)

'By sharing input state, threads share their concept of
' the active window

Call AttachThreadInput(ThreadID1, ThreadID2, True)

Dim guiInfo As GUITHREADINFO
guiInfo.cbSize = Len(guiInfo)
    
Dim lRet&
lRet = GetGUIThreadInfo(ThreadID1, guiInfo)
    
Debug.Assert guiInfo.hwndCaret <> 0
    
If guiInfo.hwndCaret = 0 Then
    Debug.Print "lastdll error: " & Err.LastDLLError
    Debug.Assert False
End If
    
Dim s$
s = GetCaretWindowText(guiInfo.hwndCaret, true)
    
Debug.Print "Text: " & s

Call AttachThreadInput(ThreadID1, ThreadID2, False)

The problem is that - if I use Chrome browser instead of Notepad - the following occurs:

guiInfo.hwndCaret = 0

However, GetGUIThreadInfo returns True, so there is no obvious error in my approach, I think.

What might be my mistake here?

0 Answers
Related