﻿id	summary	reporter	owner	description	type	status	milestone	component	version	severity	resolution	keywords	cc
3582	Bug in _WinAPI_GetGUIThreadInfo with caret rectangle	linton.miller@…	Jon	"The _WinAPI_GetGUIThreadInfo does not return correct information for the caret bounding rectangle, in elements 7-10 of the return array. That can be observed using the demo program from the help documentation for _WinAPI_GetGUIThreadInfo, or the following block
{{{
#include <WinAPISys.au3>
Local $iPID
Local $aInfo[11]
$aInfo = _WinAPI_GetGUIThreadInfo(_WinAPI_GetWindowThreadProcessId(WinGetHandle('[ACTIVE]'), $iPID))
MsgBox(0, ""_WinAPI_GetGUIThreadInfo Bug"", _
       ""Active window caret: ""&$ainfo[7]&"" ""&$ainfo[8]&"" ""&$ainfo[9]&"" ""&$ainfo[10] & @CRLF & _
       ""Caret window ""&$ainfo[6]&"" incorrectly equals caret x pos ""&$ainfo[7])
}}}

The bug is a straightforward error in the UDF, referencing the wrong element of the DLL return struct.
{{{
	For $i = 1 To 4
		$aResult[6 + $i] = DllStructGetData($tGTI, 6 + 2, $i) ;<-- Second arg should be element 9, not 8
	Next
}}}

Also noted, for strict compliance, the $tagGUITHREADINFO DLLStruct should be properly declared with struct to ensure alignment of the rcCaret rect.

While a slightly more verbose DLLStruct definition, spelling out each of the rect members results in simpler code to copy the data out of the struct (and solves the bug by simply getting rid of the need for the loop with the buggy reference).
{{{
Func _WinAPI_GetGUIThreadInfo($iThreadId)
    Local Const $tagGUITHREADINFO = 'dword Size;dword Flags;hwnd hWndActive;hwnd hWndFocus;hwnd hWndCapture;hwnd hWndMenuOwner;hwnd hWndMoveSize;hwnd hWndCaret;struct rcCaret;long left;long top;long right;long bottom;endstruct'
	Local $tGTI = DllStructCreate($tagGUITHREADINFO)
	DllStructSetData($tGTI, 1, DllStructGetSize($tGTI))

	Local $aRet = DllCall('user32.dll', 'bool', 'GetGUIThreadInfo', 'dword', $iThreadId, 'struct*', $tGTI)
	If @error Or Not $aRet[0] Then Return SetError(@error + 10, @extended, 0)

	Local $aResult[11]
	For $i = 0 To 10
		$aResult[$i] = DllStructGetData($tGTI, $i + 2)
	Next
	For $i = 9 To 10
		$aResult[$i] -= $aResult[$i - 2]
	Next
	Return $aResult
EndFunc   ;==>_WinAPI_GetGUIThreadInfo
}}}
"	Bug	closed	3.3.14.3	AutoIt	3.3.14.2	None	Fixed		
