Sign in to follow this  
Followers 0
NiVofHiR

Handling multiple windows and controls using arrays example.

8 posts in this topic

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.

; 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

Share this post


Link to post
Share on other sites



One point is it's best to use Local or Global deceleration instead of Dim. I read this on the Forum!


_AdapterConnections()_AlwaysRun()_AppMon()_AppMonEx()_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 parsingAutoIt SearchAutoIt3 PortableAutoIt3WrapperToPragmaAutoItWinGetTitle()/AutoItWinSetTitle()CodingDirToHTML5FileInstallrFileReadLastChars()GeoIP databaseGUI - Only Close ButtonGUI ExamplesGUICtrlDeleteImage()GUICtrlGetBkColor()GUICtrlGetStyle()GUIEventsGUIGetBkColor()Int_Parse() & Int_TryParse()IsISBN()LockFile()Mapping CtrlIDsOOP in AutoItParseHeadersToSciTE()PasswordValidPasteBinPosts Per DayPreExpandProtect GlobalsQueue()Resource UpdateResourcesExSciTE JumpSettings INISHELLHOOKShunting-YardSignature CreatorStack()Stopwatch()StringAddLF()/StringStripLF()StringEOLToCRLF()VSCROLLWM_COPYDATAMore Examples...

Updated: 04/09/2015

Share this post


Link to post
Share on other sites

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.

; 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 ;-)

Share this post


Link to post
Share on other sites
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 ...
 

Share this post


Link to post
Share on other sites

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

Share this post


Link to post
Share on other sites

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!"

Share this post


Link to post
Share on other sites

Yea, well, I guess its either this, or meaningless "FREAKING FANTASTICALLY AWESOME!" posts.

:unsure:

... 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 ...
 

Share this post


Link to post
Share on other sites

#8 ·  Posted (edited)

#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 :huh2: always programmers have something to say! ;) if someone find a bug please post it. this is for fun

Edited by monoscout999

Share this post


Link to post
Share on other sites

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 account

Sign in

Already have an account? Sign in here.


Sign In Now
Sign in to follow this  
Followers 0