So wie im Titel angegeben, mache ich es sehr oft mit ControlGetPos und hatte bis dato kein Problem damit gehabt... aber das hat sich nun geändert!
Die für den "Fehler" relevanten Zeilen:
_WinAPI_SetWindowLong($hEdit, $GWL_HWNDPARENT, $hListView) ; Setzt das Handle des Parentfensters für $hEdit auf $hListView - das allein löst aber keinen Fehler aus!
ControlFocus($hEdit, '', '') ; Das ist der Bösewicht... ControlGetPos($hListView, '', '') und ControlFocus($hListView, '', '') funktionieren danach nicht mehr richtig!
Lege ich den Fokus auf ein anderes Control, z.B. ControlFocus($hOK, '', ''), funktioniert wieder alles...
Was sagt ihr dazu?
Hier das Test-Script:
AutoIt
;-- TIME_STAMP 2021-01-16 03:58:11
#include <GUIConstantsEx.au3>
#include <Array.au3>
#include <WinAPISysWin.au3>
Example()
Func Example()
; Create a GUI with various controls.
Local $hGUI = GUICreate("Example")
Local $idOK = GUICtrlCreateButton("OK", 310, 370, 85, 25)
Local $hOK = GUICtrlGetHandle($idOK)
Local $idListview = GUICtrlCreateListView('Test', 2, 2, 300, 300)
Local $idItem2 = GUICtrlCreateListViewItem("item1", $idListview)
Local $idItem1 = GUICtrlCreateListViewItem("item2", $idListview)
Local $idItem3 = GUICtrlCreateListViewItem("item3", $idListview)
Local $hListview = GUICtrlGetHandle($idListview)
Local $idEdit = GUICtrlCreateInput('Input', 70, 120, 100, 20)
Local $hEdit = GUICtrlGetHandle($idEdit)
_WinAPI_SetWindowLong($hEdit, $GWL_HWNDPARENT, $hListView)
; Display the GUI.
GUISetState(@SW_SHOW, $hGUI)
ConsoleWrite("> $hGUI : " & $hGUI & @CRLF)
ConsoleWrite("> $hEdit : " & $hEdit & @CRLF)
ConsoleWrite("> $hListView : " & $hListView & @CRLF)
ConsoleWrite("> _WinAPI_GetParent($hListView) : " & _WinAPI_GetParent($hListView) & @CRLF)
ConsoleWrite("> _WinAPI_GetParent($hEdit) : " & _WinAPI_GetParent($hEdit) & @CRLF)
ConsoleWrite("> ControlGetFocus($hGUI) : " & ControlGetFocus($hGUI) & @CRLF & @CRLF)
ConsoleWrite("+ ControlGetPos($hEdit, '', '') : " & _ArrayToString(ControlGetPos($hEdit, '', ''), ', ') & @CRLF)
ConsoleWrite("+ ControlGetPos($hListView, '', '') : " & _ArrayToString(ControlGetPos($hListView, '', ''), ', ') & @CRLF & @CRLF)
ConsoleWrite("+ ControlFocus($hEdit, '', '') : " & ControlFocus($hEdit, '', '') & @CRLF)
ConsoleWrite("+ ControlGetFocus($hGUI) : " & ControlGetFocus($hGUI) & @CRLF)
ConsoleWrite("+ ControlGetPos($hEdit, '', '') : " & _ArrayToString(ControlGetPos($hEdit, '', ''), ', ') & @CRLF)
ConsoleWrite("! ControlGetPos($hListView, '', '') : " & _ArrayToString(ControlGetPos($hListView, '', ''), ', ') & @CRLF)
ConsoleWrite("+ ControlGetPos($hGUI, '', $hListView) : " & _ArrayToString(ControlGetPos($hGUI, '', $hListView), ', ') & @CRLF & @CRLF)
ConsoleWrite("! ControlFocus($hListView, '', '') : " & ControlFocus($hListView, '', '') & @CRLF)
ConsoleWrite("! ControlGetFocus($hGUI) : " & ControlGetFocus($hGUI) & @CRLF)
ConsoleWrite("+ ControlGetPos($hEdit, '', '') : " & _ArrayToString(ControlGetPos($hEdit, '', ''), ', ') & @CRLF)
ConsoleWrite("! ControlGetPos($hListView, '', '') : " & _ArrayToString(ControlGetPos($hListView, '', ''), ', ') & @CRLF)
ConsoleWrite("+ ControlGetPos($hGUI, '', $hListView) : " & _ArrayToString(ControlGetPos($hGUI, '', $hListView), ', ') & @CRLF & @CRLF)
ConsoleWrite("+ ControlFocus($hOK, '', '') : " & ControlFocus($hOK, '', '') & @CRLF)
ConsoleWrite("+ ControlGetFocus($hGUI) : " & ControlGetFocus($hGUI) & @CRLF)
ConsoleWrite("+ ControlGetPos($hEdit, '', '') : " & _ArrayToString(ControlGetPos($hEdit, '', ''), ', ') & @CRLF)
ConsoleWrite("+ ControlGetPos($hListView, '', '') : " & _ArrayToString(ControlGetPos($hListView, '', ''), ', ') & @CRLF)
; Loop until the user exits.
While 1
Switch GUIGetMsg()
Case $GUI_EVENT_CLOSE, $idOK
ExitLoop
EndSwitch
WEnd
; Delete the previous GUI and all controls.
GUIDelete($hGUI)
EndFunc ;==>Example
Alles anzeigen