NiVofHiR Posted May 16, 2011 Share Posted May 16, 2011 I figured out how a way to control multiple windows and controls using arrays. Just though I would post this small example for others to build on. expandcollapse popup; Handling multiple windows and controls using arrays ; by neoNiV of HiR 2011 (Public Domain) #Include <WinAPI.au3> #Include <WindowsConstants.au3> #include <GUIConstantsEx.au3> Global $winNum = 3 Dim $winHiR[$winNum] Dim $okbutton[$winNum] ;Dim $screenSize[2] ;$screenSize = WinGetClientSize ( "desktop" ) ;MsgBox(0, "width", $screenSize[0]) ;MsgBox(0, "height", $screenSize[1]) $winHiR[0] = GUICreate("Hello World", 200, 100) GUICtrlCreateLabel("Hello world! How are you?", 30, 10) $okbutton[0] = GUICtrlCreateButton("OK", 70, 50, 60) _WinAPI_MoveWindow($winHiR[0], (@DesktopWidth/2)-300, (@DesktopHeight/2)-50, 200, 100 , True) $winHiR[1] = GUICreate("Dummy window for testing ", 200, 100) $okbutton[1] = GUICtrlCreateButton("OK", 70, 50, 60) _WinAPI_MoveWindow($winHiR[1], (@DesktopWidth/2)-100, (@DesktopHeight/2)-50, 200, 100 , True) GUISetState(@SW_SHOW) $winHiR[2] = GUICreate("Dummy window 2 for testing ", 200, 100) $okbutton[2] = GUICtrlCreateButton("OK", 70, 50, 60) _WinAPI_MoveWindow($winHiR[2], (@DesktopWidth/2)+100, (@DesktopHeight/2)-50, 200, 100 , True) GUISetState(@SW_SHOW) GUISwitch($winHiR[0]) GUISetState(@SW_SHOW) While 1 $msg = GUIGetMsg(1) ; main window close event triggered If $msg[0] = $GUI_EVENT_CLOSE And $msg[1] = $winHiR[0] Then ExitLoop EndIf ; loop through open windows for $loop = 0 to $winNum -1 ; ok button was pressed If $msg[0] = $okbutton[$loop] And $msg[1] = $winHiR[$loop] Then MsgBox(0, "GUI Event", "You pressed OK on win " & $loop + "!") ; window close event generated If $msg[0] = $GUI_EVENT_CLOSE And $msg[1] = $winHiR[$loop] Then MsgBox(0, "GUI Event", "Closing window: " & $loop) GUISwitch($msg[1]) GUIDelete() EndIf next WEnd Link to comment Share on other sites More sharing options...
guinness Posted May 16, 2011 Share Posted May 16, 2011 One point is it's best to use Local or Global deceleration instead of Dim. I read this on the Forum! UDF List: _AdapterConnections() • _AlwaysRun() • _AppMon() • _AppMonEx() • _ArrayFilter/_ArrayReduce • _BinaryBin() • _CheckMsgBox() • _CmdLineRaw() • _ContextMenu() • _ConvertLHWebColor()/_ConvertSHWebColor() • _DesktopDimensions() • _DisplayPassword() • _DotNet_Load()/_DotNet_Unload() • _Fibonacci() • _FileCompare() • _FileCompareContents() • _FileNameByHandle() • _FilePrefix/SRE() • _FindInFile() • _GetBackgroundColor()/_SetBackgroundColor() • _GetConrolID() • _GetCtrlClass() • _GetDirectoryFormat() • _GetDriveMediaType() • _GetFilename()/_GetFilenameExt() • _GetHardwareID() • _GetIP() • _GetIP_Country() • _GetOSLanguage() • _GetSavedSource() • _GetStringSize() • _GetSystemPaths() • _GetURLImage() • _GIFImage() • _GoogleWeather() • _GUICtrlCreateGroup() • _GUICtrlListBox_CreateArray() • _GUICtrlListView_CreateArray() • _GUICtrlListView_SaveCSV() • _GUICtrlListView_SaveHTML() • _GUICtrlListView_SaveTxt() • _GUICtrlListView_SaveXML() • _GUICtrlMenu_Recent() • _GUICtrlMenu_SetItemImage() • _GUICtrlTreeView_CreateArray() • _GUIDisable() • _GUIImageList_SetIconFromHandle() • _GUIRegisterMsg() • _GUISetIcon() • _Icon_Clear()/_Icon_Set() • _IdleTime() • _InetGet() • _InetGetGUI() • _InetGetProgress() • _IPDetails() • _IsFileOlder() • _IsGUID() • _IsHex() • _IsPalindrome() • _IsRegKey() • _IsStringRegExp() • _IsSystemDrive() • _IsUPX() • _IsValidType() • _IsWebColor() • _Language() • _Log() • _MicrosoftInternetConnectivity() • _MSDNDataType() • _PathFull/GetRelative/Split() • _PathSplitEx() • _PrintFromArray() • _ProgressSetMarquee() • _ReDim() • _RockPaperScissors()/_RockPaperScissorsLizardSpock() • _ScrollingCredits • _SelfDelete() • _SelfRename() • _SelfUpdate() • _SendTo() • _ShellAll() • _ShellFile() • _ShellFolder() • _SingletonHWID() • _SingletonPID() • _Startup() • _StringCompact() • _StringIsValid() • _StringRegExpMetaCharacters() • _StringReplaceWholeWord() • _StringStripChars() • _Temperature() • _TrialPeriod() • _UKToUSDate()/_USToUKDate() • _WinAPI_Create_CTL_CODE() • _WinAPI_CreateGUID() • _WMIDateStringToDate()/_DateToWMIDateString() • Au3 script parsing • AutoIt Search • AutoIt3 Portable • AutoIt3WrapperToPragma • AutoItWinGetTitle()/AutoItWinSetTitle() • Coding • DirToHTML5 • FileInstallr • FileReadLastChars() • GeoIP database • GUI - Only Close Button • GUI Examples • GUICtrlDeleteImage() • GUICtrlGetBkColor() • GUICtrlGetStyle() • GUIEvents • GUIGetBkColor() • Int_Parse() & Int_TryParse() • IsISBN() • LockFile() • Mapping CtrlIDs • OOP in AutoIt • ParseHeadersToSciTE() • PasswordValid • PasteBin • Posts Per Day • PreExpand • Protect Globals • Queue() • Resource Update • ResourcesEx • SciTE Jump • Settings INI • SHELLHOOK • Shunting-Yard • Signature Creator • Stack() • Stopwatch() • StringAddLF()/StringStripLF() • StringEOLToCRLF() • VSCROLL • WM_COPYDATA • More Examples... Updated: 22/04/2018 Link to comment Share on other sites More sharing options...
MariusN Posted May 18, 2011 Share Posted May 18, 2011 I figured out how a way to control multiple windows and controls using arrays. Just though I would post this small example for others to build on. expandcollapse popup; Handling multiple windows and controls using arrays ; by neoNiV of HiR 2011 (Public Domain) #Include <WinAPI.au3> #Include <WindowsConstants.au3> #include <GUIConstantsEx.au3> Global $winNum = 3 Dim $winHiR[$winNum] Dim $okbutton[$winNum] ;Dim $screenSize[2] ;$screenSize = WinGetClientSize ( "desktop" ) ;MsgBox(0, "width", $screenSize[0]) ;MsgBox(0, "height", $screenSize[1]) $winHiR[0] = GUICreate("Hello World", 200, 100) GUICtrlCreateLabel("Hello world! How are you?", 30, 10) $okbutton[0] = GUICtrlCreateButton("OK", 70, 50, 60) _WinAPI_MoveWindow($winHiR[0], (@DesktopWidth/2)-300, (@DesktopHeight/2)-50, 200, 100 , True) $winHiR[1] = GUICreate("Dummy window for testing ", 200, 100) $okbutton[1] = GUICtrlCreateButton("OK", 70, 50, 60) _WinAPI_MoveWindow($winHiR[1], (@DesktopWidth/2)-100, (@DesktopHeight/2)-50, 200, 100 , True) GUISetState(@SW_SHOW) $winHiR[2] = GUICreate("Dummy window 2 for testing ", 200, 100) $okbutton[2] = GUICtrlCreateButton("OK", 70, 50, 60) _WinAPI_MoveWindow($winHiR[2], (@DesktopWidth/2)+100, (@DesktopHeight/2)-50, 200, 100 , True) GUISetState(@SW_SHOW) GUISwitch($winHiR[0]) GUISetState(@SW_SHOW) While 1 $msg = GUIGetMsg(1) ; main window close event triggered If $msg[0] = $GUI_EVENT_CLOSE And $msg[1] = $winHiR[0] Then ExitLoop EndIf ; loop through open windows for $loop = 0 to $winNum -1 ; ok button was pressed If $msg[0] = $okbutton[$loop] And $msg[1] = $winHiR[$loop] Then MsgBox(0, "GUI Event", "You pressed OK on win " & $loop + "!") ; window close event generated If $msg[0] = $GUI_EVENT_CLOSE And $msg[1] = $winHiR[$loop] Then MsgBox(0, "GUI Event", "Closing window: " & $loop) GUISwitch($msg[1]) GUIDelete() EndIf next WEnd ...nice idea you got here...i'll use it in some of my upcomming scripts as a guid-line....thx NiVofHiR ;-) Link to comment Share on other sites More sharing options...
MvGulik Posted May 18, 2011 Share Posted May 18, 2011 Mmm, What was the "Graphical User Interface (GUI) Help and Support" question again ? "Straight_and_Crooked_Thinking" : A "classic guide to ferreting out untruths, half-truths, and other distortions of facts in political and social discussions.""The Secrets of Quantum Physics" : New and excellent 2 part documentary on Quantum Physics by Jim Al-Khalili. (Dec 2014) "Believing what you know ain't so" ... Knock Knock ... Link to comment Share on other sites More sharing options...
Blue_Drache Posted May 19, 2011 Share Posted May 19, 2011 Mmm, What was the "Graphical User Interface (GUI) Help and Support" question again ?Off Topic: Agreed. This is more of an "Example Script".On Topic: Why are you tying all of your arrays to the size of a single variable? This would only be viable in a few, niche applications, such as making a "Form Letter" style of Program UI. Lofting the cyberwinds on teknoleather wings, I am...The Blue Drache Link to comment Share on other sites More sharing options...
GEOSoft Posted May 19, 2011 Share Posted May 19, 2011 He doesn't have enough posts to post in Example Scripts. The thread could get moved later. George Question about decompiling code? Read the decompiling FAQ and don't bother posting the question in the forums.Be sure to read and follow the forum rules. -AKA the AutoIt Reading and Comprehension Skills test.*** The PCRE (Regular Expression) ToolKit for AutoIT - (Updated Oct 20, 2011 ver:3.0.1.13) - Please update your current version before filing any bug reports. The installer now includes both 32 and 64 bit versions. No change in version number. Visit my Blog .. currently not active but it will soon be resplendent with news and views. Also please remove any links you may have to my website. it is soon to be closed and replaced with something else. "Old age and treachery will always overcome youth and skill!" Link to comment Share on other sites More sharing options...
MvGulik Posted May 19, 2011 Share Posted May 19, 2011 Yea, well, I guess its either this, or meaningless "FREAKING FANTASTICALLY AWESOME!" posts. ... dislike the latter more btw. ... "Straight_and_Crooked_Thinking" : A "classic guide to ferreting out untruths, half-truths, and other distortions of facts in political and social discussions.""The Secrets of Quantum Physics" : New and excellent 2 part documentary on Quantum Physics by Jim Al-Khalili. (Dec 2014) "Believing what you know ain't so" ... Knock Knock ... Link to comment Share on other sites More sharing options...
monoscout999 Posted June 2, 2011 Share Posted June 2, 2011 (edited) expandcollapse popup#include <WindowsConstants.au3> #include <GUIConstantsEx.au3> Global Const $SS_CENTER = 0x01 Global $Width Global $Height Global $winNum Do $winNum = InputBox("Window creator and handling", "¿How many windows we shall create?" & @CRLF & " < 15 and > 0 ", 3) $winNum = Int($winNum) Until $winNum < 16 And $winNum > 0 And IsInt($winNum) Do $Width = InputBox("Window creator and handling", "Width of the windows" & @CRLF & " < 300 and > 100 ", 200) $Width = Int($Width) Until $Width < 301 And $Width > 99 And IsInt($Width) Do $Height = InputBox("Window creator and handling", "Height of the windows" & @CRLF & " < 200 and > 100", 100) $Height = Int($Height) Until $Height < 201 And $Height > 99 And IsInt($Height) Global $winHiR[$winNum] Global $okbutton[$winNum] $Rows = Int(Sqrt($winNum & @CRLF)) Local $BoxWidth = $Width * $winNum / $Rows Local $boxHeight = $Height * $Rows Local $BoxRight = (@DesktopWidth / 2) - ($BoxWidth / 2) Local $BoxTop = (@DesktopHeight / 2) - ($boxHeight / 2) Local $winpos[$winNum][2] Local $Px = 0 Local $Py = 0 For $i = 0 To $winNum - 1 If $BoxRight + ($Width * $Px) >= $BoxWidth + $BoxRight Then $Px = 0 $Py += 1 EndIf $winHiR[$i] = GUICreate(_Iif($i = 0, "Hello World! how are you?", "Dummy window " & $i & " for testing "), $Width, $Height, $BoxRight + ($Width * $Px), $BoxTop + ($Height * $Py)) If $i = 0 Then GUICtrlCreateLabel("Hello world! How are you?", 0, $Height / 4, $Width, 13, $SS_CENTER) $okbutton[$i] = GUICtrlCreateButton("OK", ($Width / 2) - 30, $Height / 4 * 2.5, 60) GUISetState(@SW_SHOW) $Px += 1 Next $i = 0 While 1 $msg = GUIGetMsg(1) If $msg[1] Then If $msg[0] = $GUI_EVENT_CLOSE Then GUIDelete($msg[1]) $i += 1 EndIf If $msg[0] > 0 Then MsgBox(0, "You press...", "The OK button on the " & WinGetTitle($msg[1])) EndIf EndIf If $i = $winNum Then Exit WEnd Func _Iif($fTest, $vTrueVal, $vFalseVal) If $fTest Then Return $vTrueVal Else Return $vFalseVal EndIf EndFunc ;==>_Iif my version always programmers have something to say! if someone find a bug please post it. this is for fun Edited June 2, 2011 by monoscout999 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