Sign in to follow this  
Followers 0
bourny

Gui Help

4 posts in this topic

I am new to Gui and have created myself a gui for the job of tracking installations. My code is below. The only issue I am having is when I minimize the Gui the list box when the gui is restored has jumped into the top left corner,

I have a load of script that repositions the listbox dynamically depending on the text inside the window, If I minimize and reopen quick enough my UpdateGui function repositions the listbox automatically.

I would like to fix however the issue of the list box moving after being minimized

;¬¬¬¬¬¬¬¬¬
;INCLUDES > --------------------------- >
;¬¬¬¬¬¬¬¬¬
#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>
#include <GDIPlus.au3>
#include <Misc.au3>
#include <WinAPI.au3>
#include <Array.au3>
#include <GUIConstants.au3>
#Include <GuiListView.au3>
#include <Constants.au3>
#include <ListviewConstants.au3>
#include <ListboxConstants.au3>
#include <StaticConstants.au3>

;¬¬¬¬¬¬¬¬¬
;HOTKEYS > --------------------------- >
;¬¬¬¬¬¬¬¬¬


;¬¬¬¬¬¬¬¬¬¬¬
;VARIABLES > --------------------------- >
;¬¬¬¬¬¬¬¬¬¬¬
;Array Variables
Global $3dNetworkInstallArray
;Main Gui window variables
Global $gui
Global $GuiWidth = 500
Global $GuiHeight = 500
;---------------
;Table Variables
Global $listView
Global $ColumnTitles = "Application Name|Progress"

;¬¬¬¬¬¬¬¬¬¬¬¬¬
;SCRIPT CORE > --------------------------- >
;¬¬¬¬¬¬¬¬¬¬¬¬¬

ReadAppsToInstallList()
CreateMainGUI()
InstallApps()


;¬¬¬¬¬¬¬¬¬¬¬
;FUNCTIONS > --------------------------- >
;¬¬¬¬¬¬¬¬¬¬¬

Func ReadAppsToInstallList()

;PROCESS NETWORK ONLY INSTALLATIONS ARRAY
;----------------------------------------
    $ListofNetOnlyAppsFullPaths = "testPackage1:1.exe" & @LF & _
    "testPackage2:2.exe" & @LF & _
    "testPackage3:3.exe" & @LF & _
    "testPackage4:4.exe" & @LF & _
    "testPackage5:5.exe" & @LF & _
    "testPackage6:6.exe" & @LF & _
    "testPackage7:7.exe" & @LF & _
    "testPackage8:8.exe" & @LF & _
    "testPackage9:9.exe" & @LF & _
    "testPackage10:10.exe" & @LF & _
    "testPackage11:11.exe" & @LF & _
    "testPackage12:12.exe"

    
    msgbox(0, "", $ListofNetOnlyAppsFullPaths)
    If $ListofNetOnlyAppsFullPaths <> "" Then 
        $ArrayOfNetOnlyInstalls = StringSplit($ListofNetOnlyAppsFullPaths, @lf)
        
        dim $yPlace = 1
        Dim $y = 0
        Global $3dNetworkInstallArray[$yPlace][4] 
        
        
    ;Create 3D array of Network only applications  
    ;-------------------------  ARRAY ----------------------------
    ;---- Friendly Name --- Full Exe Path --- Completion State ---
    ;-------------------------  ARRAY ----------------------------
        
        For $Element in $ArrayOfNetOnlyInstalls 
            
            If $y <> 0 Then
                
                $yPlace = $yPlace + 1
                redim $3dNetworkInstallArray[$yPlace][4]
                
            EndIf
        
            $SplitUp = StringSplit($Element, ":")
            
            If IsArray($SplitUp) Then 
            
                $SizeOfArray =  Ubound($SplitUp)
                If $SizeOfArray <> 3 Then ContinueLoop
            
                $3dNetworkInstallArray[$y][0] = $SplitUp[1]
                $3dNetworkInstallArray[$y][1] = $SplitUp[2]
                $3dNetworkInstallArray[$y][2] = "???"
                
                $y = $y + 1
                
            EndIf
            
        Next
        
    EndIf


;PROCESS MULTICAST INSTALLATIONS ARRAY
;-------------------------------------
    $ListofMcastApps = RegRead("HKEY_LOCAL_MACHINE\SOFTWARE\AppLists", "PostAppConfig_Multicasts_Required")

    If $ListofMcastApps <> "" Then 
        $ArrayOfMulticastApps = StringSplit($ListofMcastApps, @lf)
        
        dim $yPlace = 1
        Dim $y = 0
        Global $2dMulticastArray[$yPlace][2] 
        
    ;Create 3D array of Network only applications  
    ;-------------------------  ARRAY ----------------------------
    ;---- Friendly Name --- Full Exe Path --- Completion State ---
    ;-------------------------  ARRAY ----------------------------
        
        For $Element in $ArrayOfMulticastApps
            
            If $y <> 0 Then
                
                $yPlace = $yPlace + 1
                redim $2dMulticastArray[$yPlace][2]
                
            EndIf
        
            $SplitUp = StringSplit($Element, ":")
            If IsArray($SplitUp) Then 
                
                $SizeOfArray =  Ubound($SplitUp)
                If $SizeOfArray <> 3 Then ContinueLoop
            
                $2dMulticastArray[$y][0] = $SplitUp[0]
                $2dMulticastArray[$y][1] = $SplitUp[1]
                
                $y = $y + 1
                
            EndIf
            
        Next

    EndIf
    
EndFunc

;---------------------------------

Func InstallApps()
    
;This function will simulate installing the applications in non orderly fashion
    
    TrayTip("Installing", "TestPackage1", 30, 1)
    Sleep(2000)
    UpdateGUI("TestPackage1", "Installed OK")
    
    
    TrayTip("Installing", "TestPackage5", 30, 1)
    Sleep(2000)
    UpdateGUI("TestPackage5", "Delaying until on network")
    
    TrayTip("Installing", "TestPackage2", 30, 1)
    Sleep(2000)
    UpdateGUI("TestPackage2", "Installed OK.................................")
    
    
    TrayTip("Installing", "TestPackage3", 30, 1)
    Sleep(2000)
    UpdateGUI("TestPackage3", "Installed OK")
    
    TrayTip("Installing", "TestPackage4", 30, 1)
    UpdateGUI("TestPackage4", "Failed to find package")
    Sleep(6000)
    
EndFunc

;---------------------------------

Func CreateMainGUI()

    Global $gui, $background, $pic
    
;---------------
;CREATE MAIN GUI
;---------------
    $gui = GUICreate("Delayed Application Installations", $GuiWidth, $GuiHeight )
    
    GUISetBkColor (0xCCCCCC) ; will change background color
    GUISetState(@SW_SHOW)

;--------
;ADD LIST
;--------
    PopulateGuiList()
    
EndFunc

;---------------------------------

Func PopulateGuiList()
    
;CREATE THE LIST BOX
;-------------------
;Set the List Boxes Styles and layout as an external variable
    $StandardListStyle = BitOr($WS_BORDER, $LVS_NOSORTHEADER)
    $ExtendedListStyle = BitOR($WS_HSCROLL, $WS_EX_CLIENTEDGE )
    
;Create the ListBox using the above syles
    $listview = GuiCtrlCreateListView ($ColumnTitles,10,10,300,200, $StandardListStyle, $ExtendedListStyle)
    GUICtrlSetBkColor ( -1, 0xFFFFFF)
    
;Create Title for GUI Window
    $Title = GUICtrlCreateLabel ( "Test System Software Delivery", 40, -1 , 400, 40 , $SS_CENTER,$WS_EX_CLIENTEDGE)
    GUICtrlSetBkColor ( -1, 0xFFFFFF)
    $font = "Comic Sans MS"
    GUICtrlSetFont(-1, 20, 500, 0, $font) 
    GUISetBkColor(0x00E0FFFF)
;-----------------------
    
;POPULATE THE LIST BOX WITH THE ARRAY VALUES
;-------------------------------------------
    $NumOfRows = ubound($3dNetworkInstallArray)
    Dim $y = 0
    Dim $counter
    Dim $ControlID = 1
    Dim $Item

    Dim $StartID = 0
    Do 
        
        GuiCtrlCreateListViewItem($3dNetworkInstallArray[$y][0] & "|" & $3dNetworkInstallArray[$y][2], $listview)
    ;GuiCtrlCreateListViewItem($StartID & "|" & $3dNetworkInstallArray[$y][0] & "|" & $3dNetworkInstallArray[$y][2], $listview)
        $3dNetworkInstallArray[$y][3] = $StartID
        $StartID = $StartID + 1
        $y = $y + 1
        $counter = $counter + 1
        
    Until $counter = $NumOfRows
;-------------------------
    
;RESIZE THE POLULATED LIST BOX TO MAKE IT LOOK NEAT
;--------------------------------------------------
    _GUICtrlListView_SetColumnWidth($ListView, 0,  $LVSCW_AUTOSIZE_USEHEADER)
    _GUICtrlListView_SetColumnWidth($ListView, 1,  $LVSCW_AUTOSIZE_USEHEADER)
    $iY = _GUICtrlListView_ApproximateViewHeight($listview) 
    $iX = _GUICtrlListView_ApproximateViewWidth($listview) + 5
    
;Control the table growing past the size of the main GUI window if the rezize value is to big for the main gui - 
;This will calculate if the New size is above the MainGui width and reduce it to within 10 pixels
    dim $XResizeMaxed
    dim $YExtendedDueToXMaxed
    dim $YExtendAmmount = 0
    If $iX > $GuiWidth Then 
        $iX = $GuiWidth - 20
        $XResizeMaxed = 1
    EndIf
    
;Calculate the height auto resize and reduce if the Width has maxed out to avoid a unnecessary vertical scrollbar
    If $XResizeMaxed = 1 and $YExtendedDueToXMaxed <> 1 Then $YExtendAmmount = 10
    $iY = _GUICtrlListView_ApproximateViewHeight($listview) + $YExtendAmmount
        
;Work out how to keep the list box in the center of the gui window
    $DifferenceBetweenGuiAndListBoxLength = $GuiWidth - $iX
    $PadLeft = $DifferenceBetweenGuiAndListBoxLength / 2
    
;Work out how to place the listbox at the bottom half of the GUI
    $HeightOfListBoxFromBottomOfGui = $GuiHeight - $iY - 10
    $StartHeightOfListBox = $GuiHeight - $HeightOfListBoxFromBottomOfGui
    $PadHeight = $StartHeightOfListBox
    
;Redraw List Box with new positions
    _WinAPI_SetWindowPos(GUICtrlGetHandle($listview), 0, $PadLeft, $PadHeight , $iX, $iY, $SWP_NOZORDER)
    
    
EndFunc

;---------------------------------

Func UpdateGUI($Package, $StatusOfPackage)
    
    $Result = _ArraySearch($3dNetworkInstallArray, $Package, 0, 0, 0, 1, 1)
    
    _GUICtrlListView_SetItemText($listView, $3dNetworkInstallArray[$Result][3], $StatusOfPackage, 1)
    
;Resize Table to cater for length of new text 
    _GUICtrlListView_SetColumnWidth($ListView, 0,  $LVSCW_AUTOSIZE_USEHEADER)
    _GUICtrlListView_SetColumnWidth($ListView, 1,  $LVSCW_AUTOSIZE_USEHEADER)
    
;Get the new size the rows should be to see all the information on the screen
    $iX = _GUICtrlListView_ApproximateViewWidth($listview) + 5
    
;Control the table growing past the size of the main GUI window if the rezize value is to big for the main gui - 
;This will calculate if the New size is above the MainGui width and reduce it to within 10 pixels
    Global $XResizeMaxed
    Global $YExtendedDueToXMaxed
    Global $YExtendAmmount = 0
    If $iX > $GuiWidth Then 
        $iX = $GuiWidth - 20
        $XResizeMaxed = 1
    EndIf
        
    If $XResizeMaxed = 1 and $YExtendedDueToXMaxed <> 1 Then $YExtendAmmount = 10
    
;Calculate the height auto resize and reduce if the Width has baxed out to avoid a unnecessary vertical scrollbar
    $iY = _GUICtrlListView_ApproximateViewHeight($listview) + $YExtendAmmount
    
;Work out how to keep the list box in the center of the gui window
    $DifferenceBetweenGuiAndListBoxLength = $GuiWidth - $iX
    $PadLeft = $DifferenceBetweenGuiAndListBoxLength / 2
    
;Work out how to place the listbox at the bottom half of the GUI
    $HeightOfListBoxFromBottomOfGui = $GuiHeight - $iY - 10
    $StartHeightOfListBox = $GuiHeight - $HeightOfListBoxFromBottomOfGui
    $PadHeight = $StartHeightOfListBox
    
    _WinAPI_SetWindowPos(GUICtrlGetHandle($listview), 0, $PadLeft, $PadHeight , $iX, $iY, $SWP_NOZORDER)
    
EndFunc

Share this post


Link to post
Share on other sites



I haven't tried your code, but have you looked at GUICtrlSetResizing and $GUI_DOCKALL ?

Bob


You can't see a rainbow without first experiencing the rain.

Share this post


Link to post
Share on other sites

I have looked at those but they dont seem to do anything different - I might be getting the usage wrong though.

I have discovered something though...... The List box seems to want to return to its original co-ordinates when first created. Its as if the _WinAPI_SetWindowPos function is cleared when the Gui is minimised then restored. I thought it was putting the listbox anywhere but it is actually returning to its original X Y values.

All I need to do is to get the _WinAPI_SetWindowPos values to stay active during a minimise and restore.

Any help appreciated.

Share this post


Link to post
Share on other sites

I appear to have resolved it myself. I decided to look for something other than _WinAPI_SetWindowPos to set my window - This is a UDF so I thought there must be a standard GUI move function in Autoit without having to use a UDF funcyion.

Sure enough there is and the below is what I am now using to set the new position of the window

GUICtrlSetPos ( $listview,$PadLeft, $PadHeight , $iX , $iY )

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