Modify

Opened 8 years ago

Closed 8 years ago

Last modified 8 years ago

#3582 closed Bug (Fixed)

Bug in _WinAPI_GetGUIThreadInfo with caret rectangle

Reported by: linton.miller@… Owned by: Jon
Milestone: 3.3.14.3 Component: AutoIt
Version: 3.3.14.2 Severity: None
Keywords: Cc:

Description

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

Attachments (0)

Change History (2)

comment:1 by J-Paul Mesnage, 8 years ago

Milestone: 3.3.15.1
Owner: set to J-Paul Mesnage
Resolution: Fixed
Status: newclosed

Fixed by revision [11941] in version: 3.3.15.1

comment:2 by Jon, 8 years ago

Milestone: 3.3.15.13.3.14.3
Owner: changed from J-Paul Mesnage to Jon

Fixed by revision [11942] in version: 3.3.14.3

Modify Ticket

Action
as closed The owner will remain Jon.

Add Comment


E-mail address and name can be saved in the Preferences .
 
Note: See TracTickets for help on using tickets.