Jump to content

GUI Speed affected by size of array?


Recommended Posts

I think I'd glanced at this code a week ago, a thread about screen flicker?

I run it and sure enough, it works with the pages set to 10 or 20, set it much higher and the gui's don't display.

I untangled the example a little and this one below, set to 40 pages, stops displaying at # 35. XP SP3 here.

#include <GUIConstants.au3>
#include <GUIConstantsEX.au3>
#include <windowsconstants.au3>
#include <StaticConstants.au3>
#Include <WinAPI.au3>
#Include <File.au3>
#Include <Array.au3>
Opt("WinDetectHiddenText", 0)
const $TransparentColour = 0xABCDEF  ;any element this colour will be transparent
Global $pages = 40, $labels = 10, $aGuis[$pages + 1], $aLabels[$pages + 1][$labels + 1]
Global $gui1, $width = 1024, $height = 768, $curpage, $index
Initialization()
While 1
    Switch GUIGetMsg()
        Case $GUI_EVENT_CLOSE
            Exit
    EndSwitch
$index += 1
If $index > $pages Then $index = 1
_ShowPage($index)
WEnd
Func _showPage($index)
ToolTip($index)
GUISetState(@SW_HIDE, $aGuis[$curpage])
GUISetState(@SW_SHOW, $aGuis[$index])
$curpage = $index
sleep(500)
EndFunc
;===================================================================================================================================
func Initialization()
Local $caption
For $i = 1 to $pages
;  $aGuis[$i] = GUICreate("", $width, $height, 0, 0, $WS_POPUP, $WS_EX_TOOLWINDOW)
  $aGuis[$i] = GUICreate("", $width, $height, 0, 0, $WS_POPUP, BitOR($WS_EX_LAYERED, $WS_EX_TOOLWINDOW))
  GUISetBkColor($TransparentColour, $aGuis[$i])
  _API_SetLayeredWindowAttributes($aGuis[$i], $TransparentColour);set special colour fully transparent
  for $j = 1 to $labels
   $caption = "Label" & $j & " on Page " & $i
   $aLabels[$i][$j] = GUICtrlCreateLabel($caption, 100, 100 + $j * 40, 100, 20, BitOr($SS_LeftNoWordWrap, $SS_CenterImage))
   GUICtrlSetBkColor(-1, 0xECE9D8)
  Next
Next
EndFunc
;===============================================================================
; Function Name:   _API_SetLayeredWindowAttributes
; Description:: Sets Layered Window Attributes:) See MSDN for more informaion
; Parameter(s):
;              $hwnd - Handle of GUI to work on
;              $i_transcolor - Transparent color
;              $Transparency - Set Transparancy of GUI
;              $isColorRef - If True, $i_transcolor is a COLORREF-Strucure, else an RGB-Color
; Requirement(s):  Layered Windows
; Return Value(s): Success: 1
;              Error: 0
;                  @error: 1 to 3 - Error from DllCall
;                  @error: 4 - Function did not succeed - use
;                              _WinAPI_GetLastErrorMessage or _WinAPI_GetLastError to get more information
; Author(s):    Prog@ndy
;===============================================================================
Func _API_SetLayeredWindowAttributes($hwnd, $i_transcolor, $Transparency = 255, $isColorRef = False)
    If Not $isColorRef Then
        $i_transcolor = Hex(String($i_transcolor), 6)
        $i_transcolor = '0x' & StringMid($i_transcolor, 5, 2) & StringMid($i_transcolor, 3, 2) & StringMid($i_transcolor, 1, 2)
    EndIf
    Local $Ret = DllCall("user32.dll", "int", "SetLayeredWindowAttributes", "hwnd", $hwnd, "long", $i_transcolor, "byte", $Transparency, "long", $LWA_COLORKEY + $LWA_ALPHA)
    Select
  Case @error
            Return SetError(@error, 0, 0)
        Case $Ret[0] = 0
            Return SetError(4, 0, 0)
    EndSelect
    Return 1
EndFunc ;==>_API_SetLayeredWindowAttributes

Edit: On subsequent passes of the loop, the same GUI's 1-35 will display and the same losers 36-40 will not. Set $pages to 100, and my PC stops displaying after #21. Go figure... So... why not do it all with one gui? Have a table to reload (not recreate) and reposition one batch of labels depending on which "page" you're showing?

Edited by Spiff59
Link to comment
Share on other sites

I tried this at home on another (XP Pro SP3) machine. I got the same failing result. Seems to be, as you said, some sort of glitch with $WS_EX_LAYERED and multiple GUI's.

You could try a single GUI approach. It gets rid of you defining 1000's of labels, doesn't encouter the $WS_EX_LAYERED bug, and would likely solve your speed issue. Something like:

#include <GUIConstants.au3>
#include <GUIConstantsEX.au3>
#include <windowsconstants.au3>
#include <StaticConstants.au3>
#Include <WinAPI.au3>
#Include <File.au3>
#Include <Array.au3>
Opt("WinDetectHiddenText", 0)
Global Const $TransparentColour = 0xABCDEF  ;any element this colour will be transparent
Global Const $pages = 40, $labels = 20
Global Const $width = 1024, $height = 768
Global $Stable_Label_Table[$pages + 1][$labels + 1][3] ; xpos, ypos, data
Global $alabel[$labels + 1], $curpage, $index
; load random test data
For $x = 1 to $pages
$Stable_Label_Table[$x][0][0] = Random(1, $labels, 1) ; store number of labels on page in [page][0][0] element
For $y = 1 to $Stable_Label_Table[$x][0][0]
  $Stable_Label_Table[$x][$y][0] = Random(1, 20, 1) * 50 ; random x position
  $Stable_Label_Table[$x][$y][1] = Random(1, 20, 1) * 40 ; random y position
  $Stable_Label_Table[$x][$y][2] = "Page" & $x & " Label" & $y
Next
Next
; create GUI
$Main_GUI = GUICreate("", $width, $height, 0, 0, $WS_POPUP, BitOR($WS_EX_LAYERED, $WS_EX_TOOLWINDOW))
GUISetBkColor($TransparentColour, $Main_GUI)
_API_SetLayeredWindowAttributes($Main_GUI, $TransparentColour) ; set special colour fully transparent
For $i = 1 to $labels
   $aLabel[$i] = GUICtrlCreateLabel("", 0, 0, 100, 16, BitOr($SS_LeftNoWordWrap, $SS_CenterImage))
   GUICtrlSetBkColor(-1, 0xECE9D8)
Next
GUISetState()
; main loop
For $index = 1 to $pages
    Switch GUIGetMsg()
        Case $GUI_EVENT_CLOSE
            Exit
    EndSwitch
_ShowPage($index)
Next
;===================================================================================================================================
Func _showPage($index)
ToolTip($index)
For $x = 1 to $Stable_Label_Table[$index][0][0]
  GUICtrlSetPos($alabel[$x], $Stable_Label_Table[$index][$x][0], $Stable_Label_Table[$index][$x][1])
  GUICtrlSetData($alabel[$x], $Stable_Label_Table[$index][$x][2])
  GUICtrlSetState($alabel[$x], $GUI_SHOW)
Next
If $curpage Then
  For $x = $x to $labels
   GUICtrlSetState($alabel[$x], $GUI_HIDE)
  Next
EndIf
$curpage = $index
sleep(600)
EndFunc
;===============================================================================
; Function Name:   _API_SetLayeredWindowAttributes
; Description:: Sets Layered Window Attributes:) See MSDN for more informaion
; Parameter(s):
;             $hwnd - Handle of GUI to work on
;             $i_transcolor - Transparent color
;             $Transparency - Set Transparancy of GUI
;             $isColorRef - If True, $i_transcolor is a COLORREF-Strucure, else an RGB-Color
; Requirement(s):  Layered Windows
; Return Value(s): Success: 1
;             Error: 0
;                 @error: 1 to 3 - Error from DllCall
;                 @error: 4 - Function did not succeed - use
;                             _WinAPI_GetLastErrorMessage or _WinAPI_GetLastError to get more information
; Author(s):    Prog@ndy
;===============================================================================
Func _API_SetLayeredWindowAttributes($hwnd, $i_transcolor, $Transparency = 255, $isColorRef = False)
    If Not $isColorRef Then
        $i_transcolor = Hex(String($i_transcolor), 6)
        $i_transcolor = '0x' & StringMid($i_transcolor, 5, 2) & StringMid($i_transcolor, 3, 2) & StringMid($i_transcolor, 1, 2)
    EndIf
    Local $Ret = DllCall("user32.dll", "int", "SetLayeredWindowAttributes", "hwnd", $hwnd, "long", $i_transcolor, "byte", $Transparency, "long", $LWA_COLORKEY + $LWA_ALPHA)
    Select
  Case @error
            Return SetError(@error, 0, 0)
        Case $Ret[0] = 0
            Return SetError(4, 0, 0)
    EndSelect
    Return 1
EndFunc ;==>_API_SetLayeredWindowAttributes

Edit: Put my text back above the snippet <grumble>

Edited by Spiff59
Link to comment
Share on other sites

I tried this at home on another (XP Pro SP3) machine. I got the same failing result. Seems to be, as you said, some sort of glitch with $WS_EX_LAYERED and multiple GUI's.

You could try a single GUI approach. It gets rid of you defining 1000's of labels, doesn't encouter the $WS_EX_LAYERED bug, and would likely solve your speed issue. Something like:

#include <GUIConstants.au3>
#include <GUIConstantsEX.au3>
#include <windowsconstants.au3>
#include <StaticConstants.au3>
#Include <WinAPI.au3>
#Include <File.au3>
#Include <Array.au3>
Opt("WinDetectHiddenText", 0)
Global Const $TransparentColour = 0xABCDEF  ;any element this colour will be transparent
Global Const $pages = 40, $labels = 20
Global Const $width = 1024, $height = 768
Global $Stable_Label_Table[$pages + 1][$labels + 1][3] ; xpos, ypos, data
Global $alabel[$labels + 1], $curpage, $index
; load random test data
For $x = 1 to $pages
$Stable_Label_Table[$x][0][0] = Random(1, $labels, 1) ; store number of labels on page in [page][0][0] element
For $y = 1 to $Stable_Label_Table[$x][0][0]
  $Stable_Label_Table[$x][$y][0] = Random(1, 20, 1) * 50 ; random x position
  $Stable_Label_Table[$x][$y][1] = Random(1, 20, 1) * 40 ; random y position
  $Stable_Label_Table[$x][$y][2] = "Page" & $x & " Label" & $y
Next
Next
; create GUI
$Main_GUI = GUICreate("", $width, $height, 0, 0, $WS_POPUP, BitOR($WS_EX_LAYERED, $WS_EX_TOOLWINDOW))
GUISetBkColor($TransparentColour, $Main_GUI)
_API_SetLayeredWindowAttributes($Main_GUI, $TransparentColour) ; set special colour fully transparent
For $i = 1 to $labels
   $aLabel[$i] = GUICtrlCreateLabel("", 0, 0, 100, 16, BitOr($SS_LeftNoWordWrap, $SS_CenterImage))
   GUICtrlSetBkColor(-1, 0xECE9D8)
Next
GUISetState()
; main loop
For $index = 1 to $pages
    Switch GUIGetMsg()
        Case $GUI_EVENT_CLOSE
            Exit
    EndSwitch
_ShowPage($index)
Next
;===================================================================================================================================
Func _showPage($index)
ToolTip($index)
For $x = 1 to $Stable_Label_Table[$index][0][0]
  GUICtrlSetPos($alabel[$x], $Stable_Label_Table[$index][$x][0], $Stable_Label_Table[$index][$x][1])
  GUICtrlSetData($alabel[$x], $Stable_Label_Table[$index][$x][2])
  GUICtrlSetState($alabel[$x], $GUI_SHOW)
Next
If $curpage Then
  For $x = $x to $labels
   GUICtrlSetState($alabel[$x], $GUI_HIDE)
  Next
EndIf
$curpage = $index
sleep(600)
EndFunc
;===============================================================================
; Function Name:   _API_SetLayeredWindowAttributes
; Description:: Sets Layered Window Attributes:) See MSDN for more informaion
; Parameter(s):
;             $hwnd - Handle of GUI to work on
;             $i_transcolor - Transparent color
;             $Transparency - Set Transparancy of GUI
;             $isColorRef - If True, $i_transcolor is a COLORREF-Strucure, else an RGB-Color
; Requirement(s):  Layered Windows
; Return Value(s): Success: 1
;             Error: 0
;                 @error: 1 to 3 - Error from DllCall
;                 @error: 4 - Function did not succeed - use
;                             _WinAPI_GetLastErrorMessage or _WinAPI_GetLastError to get more information
; Author(s):    Prog@ndy
;===============================================================================
Func _API_SetLayeredWindowAttributes($hwnd, $i_transcolor, $Transparency = 255, $isColorRef = False)
    If Not $isColorRef Then
        $i_transcolor = Hex(String($i_transcolor), 6)
        $i_transcolor = '0x' & StringMid($i_transcolor, 5, 2) & StringMid($i_transcolor, 3, 2) & StringMid($i_transcolor, 1, 2)
    EndIf
    Local $Ret = DllCall("user32.dll", "int", "SetLayeredWindowAttributes", "hwnd", $hwnd, "long", $i_transcolor, "byte", $Transparency, "long", $LWA_COLORKEY + $LWA_ALPHA)
    Select
  Case @error
            Return SetError(@error, 0, 0)
        Case $Ret[0] = 0
            Return SetError(4, 0, 0)
    EndSelect
    Return 1
EndFunc ;==>_API_SetLayeredWindowAttributes

Edit: Put my text back above the snippet <grumble>

You know, that might just work! I will have to do some speed tests to see if it will be adequate.

I had just decided that I needed to move to C# using the AutoIt simply for interacting with the underlying program. AutoIt just seems to be too unpredictable when dealing with masses of GUIs and labels.

Thanks Melba (for highlighting the fact that my workstation may be to blame for some of my issues) and Spiffy.

D

Link to comment
Share on other sites

  • 2 weeks later...

You know, that might just work! I will have to do some speed tests to see if it will be adequate.

D

Thanks for the spiffing idea, Spiff59.

As it turns out, the most labels I'll need on a page is around 50, so I create 50 labels, and then just reconfigure as you suggested on page change. Its very fast, and much lower on resources.

Thanks again to everybody for the help.

D

Edited by RagsRevenge
Link to comment
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
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...