Aelc Posted March 30, 2020 Share Posted March 30, 2020 Hey there I have got a problem with my gui... the script contains over 3000 lines so i wrote this little script to make it easier i want to click on one of the labels which should switch to an input then. after i changed the text i want to click anywhere else in GUI and transform the input back to an label it almost works but after i changed the text, i click e.g. on the input and it transforms twice -> to a label and again to an input.. so like when i click on an other label it transform to input, too. i just want to "deselect" it. - thats why i tried the Do Until loop but it doenst work ... if possible i dont want to loop something because other functions of the GUI doesnt work then. Thanks for help in advantage expandcollapse popup#include-once #include <GuiConstants.au3> #include <GUIConstantsEx.au3> #include <misc.au3> Global $show_panel_1[1][21] Global $hGUI = GUICreate("", 300, 800, -1, -1) Global $invisible_ctrl = False For $i = 1 To 20 $show_panel_1[0][$i] = GUICtrlCreateLabel("test" & $i, 10, 10 + (($i - 1) * 40), 200, 30) Next GUISetState() While 1 $nMsg = GUIGetMsg(1) Switch $nMsg[1] Case $hGUI Switch $nMsg[0] Case $GUI_EVENT_PRIMARYDOWN $aCursor = GUIGetCursorInfo($hGUI) If _IsPressed("01") Then Do Sleep(150) Until _IsPressed("01") <> True Else Sleep(150) EndIf If $aCursor[4] <> 0 Then For $i = 1 To 20 If $aCursor[4] = $show_panel_1[0][$i] Then $aCursor[4] = $show_panel_1[0][$i] $txt = ControlGetText ( $hGUI,"",$show_panel_1[0][$i] ) GUICtrlDelete ( $show_panel_1[0][$i] ) $show_panel_1[0][$i] = GUICtrlCreateInput ( $txt,10,10+(($i-1)*40),200,30 ) ControlFocus ( $hGUI,"",$show_panel_1[0][$i] ) Send ( "^a" ) Do Sleep ( 50 ) Until _IsPressed ( "01" ) = True Do Sleep ( 50 ) Until _IsPressed ( "01" ) <> True $txt = ControlGetText ( $hGUI,"",$show_panel_1[0][$i] ) GUICtrlDelete ( $show_panel_1[0][$i] ) $show_panel_1[0][$i] = GUICtrlCreateLabel($txt, 10, 10 + (($i - 1) * 40), 200, 30) EndIf Next EndIf Case -3 Exit EndSwitch EndSwitch WEnd why do i get garbage when i buy garbage bags? Link to comment Share on other sites More sharing options...
Aelc Posted March 30, 2020 Author Share Posted March 30, 2020 (edited) Got it expandcollapse popup#include-once #include <GuiConstants.au3> #include <GUIConstantsEx.au3> #include <misc.au3> Global $show_panel_1[1][21] Global $hGUI = GUICreate("", 300, 800, -1, -1) Global $label_input = False For $i = 1 To 20 $show_panel_1[0][$i] = GUICtrlCreateLabel("test" & $i, 10, 10 + (($i - 1) * 40), 200, 30) Next GUISetState() While 1 $nMsg = GUIGetMsg(1) Switch $nMsg[1] Case $hGUI Switch $nMsg[0] Case $GUI_EVENT_PRIMARYDOWN $aCursor = GUIGetCursorInfo($hGUI) If $label_input <> False And $aCursor[4] <> $show_panel_1[0][$label_input] Then $txt = ControlGetText ( $hGUI,"",$show_panel_1[0][$label_input] ) GUICtrlDelete ( $show_panel_1[0][$label_input] ) $show_panel_1[0][$label_input] = GUICtrlCreateLabel($txt, 10, 10 + (($label_input - 1) * 40), 200, 30) $label_input = False Else If _IsPressed("01") Then Do Sleep(150) Until _IsPressed("01") <> True Else Sleep(150) EndIf If $aCursor[4] <> 0 And $label_input = False Then For $i = 1 To 20 If $aCursor[4] = $show_panel_1[0][$i] Then $txt = ControlGetText ( $hGUI,"",$show_panel_1[0][$i] ) GUICtrlDelete ( $show_panel_1[0][$i] ) $show_panel_1[0][$i] = GUICtrlCreateInput ( $txt,10,10+(($i-1)*40),200,30 ) ControlFocus ( $hGUI,"",$show_panel_1[0][$i] ) Send ( "^a" ) $label_input = $i EndIf Next EndIf EndIf Case -3 Exit EndSwitch EndSwitch WEnd Edited March 30, 2020 by Aelc why do i get garbage when i buy garbage bags? Link to comment Share on other sites More sharing options...
Nine Posted March 30, 2020 Share Posted March 30, 2020 You may like to use something like this instead : expandcollapse popup#include <Constants.au3> #include <GUIConstants.au3> #include <WinAPI.au3> #include <WinAPIDlg.au3> Global $show_panel_1[1][21] Global $hGUI = GUICreate("", 300, 800, -1, -1) Global $show_input = False Global $wProcHandle = DllCallbackRegister("_WindowProc", "ptr", "hwnd;uint;wparam;lparam") $show_panel_1[0][1] = GUICtrlCreateLabel("test1", 10, 10, 200, 30) Global $wProcOld = _WinAPI_SetWindowLong(GUICtrlGetHandle($show_panel_1[0][1]), $GWL_WNDPROC, DllCallbackGetPtr($wProcHandle)) For $i = 2 To 20 $show_panel_1[0][$i] = GUICtrlCreateLabel("test" & $i, 10, 10 + (($i - 1) * 40), 200, 30) _WinAPI_SetWindowLong(GUICtrlGetHandle($show_panel_1[0][$i]), $GWL_WNDPROC, DllCallbackGetPtr($wProcHandle)) Next GUISetState() While 1 $nMsg = GUIGetMsg(1) Switch $nMsg[1] Case $hGUI Switch $nMsg[0] Case $GUI_EVENT_CLOSE ExitLoop EndSwitch EndSwitch WEnd GUIDelete($hGUI) DllCallbackFree($wProcHandle) Func _WindowProc($hWnd, $iMsg, $wParam, $lParam) Local Static $iPrev, $iInput Local $sLabel, $iId, $aPos Switch $iMsg Case $WM_LBUTTONDOWN $iId = _WinAPI_GetDlgCtrlID($hWnd) $show_input = Not $show_input If $show_input Then $aPos = ControlGetPos ($hGUI, "", $iId) $sLabel = GUICtrlRead ($iId) GUICtrlSetState ($iId, $GUI_HIDE) $iPrev = $iId $iInput = GUICtrlCreateInput ($sLabel, $aPos[0], $aPos[1], $aPos[2], $aPos[3]) Else GUICtrlSetData ($iPrev, GUICtrlRead ($iInput)) GUICtrlDelete ($iInput) GUICtrlSetState ($iPrev, $GUI_SHOW) EndIf EndSwitch Return _WinAPI_CallWindowProc($wProcOld, $hWnd, $iMsg, $wParam, $lParam) EndFunc ;==>_WindowProc Aelc 1 “They did not know it was impossible, so they did it” ― Mark Twain Spoiler Block all input without UAC Save/Retrieve Images to/from Text Monitor Management (VCP commands) Tool to search in text (au3) files Date Range Picker Virtual Desktop Manager Sudoku Game 2020 Overlapped Named Pipe IPC HotString 2.0 - Hot keys with string x64 Bitwise Operations Multi-keyboards HotKeySet Recursive Array Display Fast and simple WCD IPC Multiple Folders Selector Printer Manager GIF Animation (cached) Screen Scraping Multi-Threading Made Easy Link to comment Share on other sites More sharing options...
Aelc Posted March 30, 2020 Author Share Posted March 30, 2020 wow ty for that solution that looks interesting because i wouldn't have the For Next Loop inside the GUI in my main script there are so much of it so it would be an alternative solution for me to tidy up the GUI loop maybe. it's almost a must have i would say the only thing is i dont exactly know how it works because i never understood DLLCallbackRegister i will take a look on it tomorrow again - with more time why do i get garbage when i buy garbage bags? Link to comment Share on other sites More sharing options...
Aelc Posted March 31, 2020 Author Share Posted March 31, 2020 (edited) i dont get what the $wProcOld is doing which is actually annoying because i have Funcs which drawing my GUIs and now i have to adjust them... is there no way to start with For $i = 1 ? (without using [0]) but mostly i understand for now and trying to implement it to my main script thanks again Edited March 31, 2020 by Aelc why do i get garbage when i buy garbage bags? Link to comment Share on other sites More sharing options...
Nine Posted March 31, 2020 Share Posted March 31, 2020 9 hours ago, Aelc said: i dont get what the $wProcOld is doing It serves at calling the normal WindowProc to pursue the message management at the end of your own WindowProc. 9 hours ago, Aelc said: is there no way to start with For $i = 1 ? (without using [0]) Well you could add logic to get the $wProcOld the first time and then skip for the other. But it is VERY important that you set $wProcOld only once at the first statement otherwise you will loose the rightful address and you will break the message chain. Not a good idea. Aelc 1 “They did not know it was impossible, so they did it” ― Mark Twain Spoiler Block all input without UAC Save/Retrieve Images to/from Text Monitor Management (VCP commands) Tool to search in text (au3) files Date Range Picker Virtual Desktop Manager Sudoku Game 2020 Overlapped Named Pipe IPC HotString 2.0 - Hot keys with string x64 Bitwise Operations Multi-keyboards HotKeySet Recursive Array Display Fast and simple WCD IPC Multiple Folders Selector Printer Manager GIF Animation (cached) Screen Scraping Multi-Threading Made Easy Link to comment Share on other sites More sharing options...
Aelc Posted March 31, 2020 Author Share Posted March 31, 2020 (edited) Is this limited on CTRLs? Because when i have more than 42 the GUI just crashs. when is there a way around? Problem is on my main script there are so much CTRLs ... or did i something wrong there ? example script: expandcollapse popup#include <Constants.au3> #include <GUIConstants.au3> #include <WinAPI.au3> #include <WinAPIDlg.au3> Global $show_panel_1[1][101] Global $hGUI = GUICreate("", 1300, 800, -1, -1) Global $show_input = False Global $wProcHandle = DllCallbackRegister("_WindowProc", "ptr", "hwnd;uint;wparam;lparam") $show_panel_1[0][1] = GUICtrlCreateLabel("test1", 10, 10, 200, 30) Global $wProcOld = _WinAPI_SetWindowLong(GUICtrlGetHandle($show_panel_1[0][1]), $GWL_WNDPROC, DllCallbackGetPtr($wProcHandle)) $left = 10 $topadjust = 0 For $i = 1 To 100 $show_panel_1[0][$i] = GUICtrlCreateLabel("test" & $i, $left, ($i + $topadjust -1 ) * 40 + 10, 90, 30) _WinAPI_SetWindowLong(GUICtrlGetHandle($show_panel_1[0][$i]), $GWL_WNDPROC, DllCallbackGetPtr($wProcHandle)) If $i = 20 Or $i = 40 Or $i = 60 Or $i = 80 Then $left = $left + 100 $topadjust = $topadjust - 20 EndIf Next GUISetState() While 1 $nMsg = GUIGetMsg(1) Switch $nMsg[1] Case $hGUI Switch $nMsg[0] Case $GUI_EVENT_CLOSE ExitLoop EndSwitch EndSwitch WEnd GUIDelete($hGUI) DllCallbackFree($wProcHandle) Func _WindowProc($hWnd, $iMsg, $wParam, $lParam) Local Static $iPrev, $iInput Local $sLabel, $iId, $aPos Switch $iMsg Case $WM_LBUTTONDOWN $iId = _WinAPI_GetDlgCtrlID($hWnd) $show_input = Not $show_input If $show_input Then $aPos = ControlGetPos ($hGUI, "", $iId) $sLabel = GUICtrlRead ($iId) GUICtrlSetState ($iId, $GUI_HIDE) $iPrev = $iId $iInput = GUICtrlCreateInput ($sLabel, $aPos[0], $aPos[1], $aPos[2], $aPos[3]) ControlClick ( $hGUI,"",$iInput ) Else GUICtrlSetData ($iPrev, GUICtrlRead ($iInput)) GUICtrlDelete ($iInput) GUICtrlSetState ($iPrev, $GUI_SHOW) EndIf EndSwitch Return _WinAPI_CallWindowProc($wProcOld, $hWnd, $iMsg, $wParam, $lParam) EndFunc ;==>_WindowProc i also tried to get another dllcallback with seperate function but it dont works Edited March 31, 2020 by Aelc why do i get garbage when i buy garbage bags? Link to comment Share on other sites More sharing options...
Nine Posted March 31, 2020 Share Posted March 31, 2020 In my case, it doesn't crash but there is a strange behavior with the GUI. After 31 correct displays, the labels afterward are blank till I click on it. IDK, couldn't find any kind of limitation on MSDN, so I trust it is some kind of a bug with AutoIt. But changing a bit the script now works perfectly for me at 100. Remember to start your For loop at 2 not 1. Replace the beginning of the script with this, see if that works for you : Global $show_panel_1[1][101] Global $hGUI = GUICreate("", 1300, 800, -1, -1) Global $show_input = False Local $left = 10, $topadjust = 0 $show_panel_1[0][1] = GUICtrlCreateLabel("test1", 10, 10, 200, 30) For $i = 2 To 100 $show_panel_1[0][$i] = GUICtrlCreateLabel("test" & $i, $left, ($i + $topadjust -1 ) * 40 + 10, 90, 30) If $i = 20 Or $i = 40 Or $i = 60 Or $i = 80 Then $left = $left + 100 $topadjust = $topadjust - 20 EndIf Next GUISetState() Global $wProcHandle = DllCallbackRegister("_WindowProc", "ptr", "hwnd;uint;wparam;lparam") Global $wProcOld = _WinAPI_SetWindowLong(GUICtrlGetHandle($show_panel_1[0][1]), $GWL_WNDPROC, DllCallbackGetPtr($wProcHandle)) For $i = 2 to 100 _WinAPI_SetWindowLong(GUICtrlGetHandle($show_panel_1[0][$i]), $GWL_WNDPROC, DllCallbackGetPtr($wProcHandle)) Next Aelc 1 “They did not know it was impossible, so they did it” ― Mark Twain Spoiler Block all input without UAC Save/Retrieve Images to/from Text Monitor Management (VCP commands) Tool to search in text (au3) files Date Range Picker Virtual Desktop Manager Sudoku Game 2020 Overlapped Named Pipe IPC HotString 2.0 - Hot keys with string x64 Bitwise Operations Multi-keyboards HotKeySet Recursive Array Display Fast and simple WCD IPC Multiple Folders Selector Printer Manager GIF Animation (cached) Screen Scraping Multi-Threading Made Easy Link to comment Share on other sites More sharing options...
Aelc Posted March 31, 2020 Author Share Posted March 31, 2020 (edited) works fine just tried some things thats why the loop wasn't on 2 btw thanks again Edited March 31, 2020 by Aelc why do i get garbage when i buy garbage bags? Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now