Jump to content
_Vlad

Hiding many elements cause form flickering

Recommended Posts

Hello forum,

I want to create a program with multiple menus and many elements inside. The problem is my way of doing this and below I have an example of how I do these menus.

I know it's a bad way of doing them as using this method for more elements and menus cause big flickering.

 

Can someone please help me with some tips of optimizing this or tell me another way of creating that menus with many elements without cause flickering? From a long time ago I still try to solve this but without any results, just small improvements.

Many thanks for everyone.

#include <ButtonConstants.au3>
#include <GUIConstantsEx.au3>
#include <StaticConstants.au3>
#include <WindowsConstants.au3>

Global $MENU_HOVER = ''
Global $MENU_SELECTED = ''
Global $COLOR_STANDARD = 0x94A5E9
Global $COLOR_HOVER = 0x8292d1
Global $COLOR_SELECTED = 0x7584bf

$MENU = GUICreate("Menu", 615, 437, -1, -1, -1, -1, 0)
GUISetFont(10, 400, 0, "Arial")
$MENU_1 = GUICtrlCreateLabel("Menu 1", 8, 24, 106, 28, BitOR($SS_CENTER, $SS_CENTERIMAGE))
$MENU_2 = GUICtrlCreateLabel("Menu 2", 8, 56, 106, 28, BitOR($SS_CENTER, $SS_CENTERIMAGE))
$MENU_3 = GUICtrlCreateLabel("Menu 3", 8, 88, 106, 28, BitOR($SS_CENTER, $SS_CENTERIMAGE))

;MENU 1 ELEMENTS
$MENU_1_ELEMENT_1 = GUICtrlCreateButton("Menu1 Button", 128, 24, 147, 25)

;MENU 2 ELEMENTS
$MENU_2_ELEMENT_1 = GUICtrlCreateButton("Menu2 Button", 128, 24, 147, 25)
$MENU_2_ELEMENT_2 = GUICtrlCreateLabel("Another element", 128, 64, 99, 20)

_Design()
_Hide_All()
GUISetState(@SW_SHOW, $MENU)

While 1
    $Cursor = GUIGetCursorInfo($MENU)
    $nMsg = GUIGetMsg()
    Switch $nMsg
        Case $GUI_EVENT_CLOSE
            Exit

        Case $MENU_1
            _Previous_Selected_Cancel()
            $MENU_SELECTED = 'Menu1'
            GUICtrlSetBkColor($MENU_1, $COLOR_SELECTED)
            _Show('Menu1')

        Case $MENU_2
            _Previous_Selected_Cancel()
            $MENU_SELECTED = 'Menu2'
            GUICtrlSetBkColor($MENU_2, $COLOR_SELECTED)
            _Show('Menu2')

        Case $MENU_3
            _Previous_Selected_Cancel()
            $MENU_SELECTED = 'Menu3'
            GUICtrlSetBkColor($MENU_3, $COLOR_SELECTED)
            _Show('Menu3')

    EndSwitch

    If $Cursor[4] = $MENU_1 Then
        If $MENU_HOVER <> 'Menu1' And $MENU_SELECTED <> 'Menu1' Then
            _Previous_Hover_Cancel()
            GUICtrlSetBkColor($MENU_1, $COLOR_HOVER)
            $MENU_HOVER = 'Menu1'
        EndIf
    ElseIf $Cursor[4] = $MENU_2 Then
        If $MENU_HOVER <> 'Menu2' And $MENU_SELECTED <> 'Menu2' Then
            _Previous_Hover_Cancel()
            GUICtrlSetBkColor($MENU_2, $COLOR_HOVER)
            $MENU_HOVER = 'Menu2'
        EndIf
    ElseIf $Cursor[4] = $MENU_3 Then
        If $MENU_HOVER <> 'Menu3' And $MENU_SELECTED <> 'Menu3' Then
            _Previous_Hover_Cancel()
            GUICtrlSetBkColor($MENU_3, $COLOR_HOVER)
            $MENU_HOVER = 'Menu3'
        EndIf
    Else
        _Previous_Hover_Cancel()
        $MENU_HOVER = 'Idle'
    EndIf

WEnd

Func _Design()
    GUICtrlSetColor($MENU_1, 0xFFFFFF)
    GUICtrlSetBkColor($MENU_1, $COLOR_STANDARD)
    GUICtrlSetCursor($MENU_1, 0)
    GUICtrlSetColor($MENU_2, 0xFFFFFF)
    GUICtrlSetBkColor($MENU_2, $COLOR_STANDARD)
    GUICtrlSetCursor($MENU_2, 0)
    GUICtrlSetColor($MENU_3, 0xFFFFFF)
    GUICtrlSetBkColor($MENU_3, $COLOR_STANDARD)
    GUICtrlSetCursor($MENU_3, 0)
EndFunc   ;==>_Design

Func _Hide_All()
    GUICtrlSetState($MENU_1_ELEMENT_1, $GUI_HIDE)
    GUICtrlSetState($MENU_2_ELEMENT_1, $GUI_HIDE)
    GUICtrlSetState($MENU_2_ELEMENT_2, $GUI_HIDE)
EndFunc   ;==>_Hide_All

Func _Show($MENU_SHOW)

    _Hide_All()

    If $MENU_SHOW = 'Menu1' Then
        GUICtrlSetState($MENU_1_ELEMENT_1, $GUI_SHOW)
    ElseIf $MENU_SHOW = 'Menu2' Then
        GUICtrlSetState($MENU_2_ELEMENT_1, $GUI_SHOW)
        GUICtrlSetState($MENU_2_ELEMENT_2, $GUI_SHOW)
    ElseIf $MENU_SHOW = 'Menu3' Then
    EndIf

EndFunc   ;==>_Show

Func _Previous_Hover_Cancel()

    If $MENU_HOVER = 'Menu1' Then
        If $MENU_SELECTED <> 'Menu1' Then GUICtrlSetBkColor($MENU_1, $COLOR_STANDARD)
    ElseIf $MENU_HOVER = 'Menu2' Then
        If $MENU_SELECTED <> 'Menu2' Then GUICtrlSetBkColor($MENU_2, $COLOR_STANDARD)
    ElseIf $MENU_HOVER = 'Menu3' Then
        If $MENU_SELECTED <> 'Menu3' Then GUICtrlSetBkColor($MENU_3, $COLOR_STANDARD)
    EndIf

EndFunc   ;==>_Previous_Hover_Cancel

Func _Previous_Selected_Cancel()
    If $MENU_SELECTED = 'Menu1' Then GUICtrlSetBkColor($MENU_1, $COLOR_STANDARD)
    If $MENU_SELECTED = 'Menu2' Then GUICtrlSetBkColor($MENU_2, $COLOR_STANDARD)
    If $MENU_SELECTED = 'Menu3' Then GUICtrlSetBkColor($MENU_3, $COLOR_STANDARD)
EndFunc   ;==>_Previous_Selected_Cancel

 


Quote
Destiny is a name often given in retrospect to choices that had dramatic consequences.  J.K. Rowling

 

Share this post


Link to post
Share on other sites

There is no flickering here cause it's just an example of how I work around with multiple menus and elements. Try to add to this 5 more menus and 100+ elements, it will go crazy. :( This is why I want to discover another method of doing these better and optimized.


Quote
Destiny is a name often given in retrospect to choices that had dramatic consequences.  J.K. Rowling

 

Share this post


Link to post
Share on other sites
8 minutes ago, _Vlad said:

Try to add to this 5 more menus and 100+ elements, it will go crazy. :( 

Please provide an example with e.g. 10 menus and 100+ elements. This saves us time to create it ourselves ;).

EDIT : Oh, @Nine was a bit faster :lol:.

Edited by Musashi

Musashi-C64.png

"In the beginning the Universe was created. This has made a lot of people very angry and been widely regarded as a bad move."

Share this post


Link to post
Share on other sites

Is the same thing as the example above just with more menus and elements.

The whole way I do this is wrong, that's the problem. I want to find another way to create menus and elements more stable.


Quote
Destiny is a name often given in retrospect to choices that had dramatic consequences.  J.K. Rowling

 

Share this post


Link to post
Share on other sites

It's difficult to rebuild as an example as I have a big source code file, that I am not allowed to put here.

Let me put that problem different,

How would you build multiple menus with many elements, different than this?

I try to search different solutions for optimizing a form with many elements, that's all or some multiple methods of building it more stable.


Quote
Destiny is a name often given in retrospect to choices that had dramatic consequences.  J.K. Rowling

 

Share this post


Link to post
Share on other sites

Here is an example from @Melba23  :  creating-menus-using-arrays

Example from Melba23 :
https://www.autoitscript.com/forum/topic/136975-creating-menus-using-arrays/?do=findComment&comment=958203
#ce

#include <GUIConstantsEx.au3>

; Create an array to hold the menu items when created
Global $aMenuItems[1][2] = [[0]]

; Declare ini file
$sIni = @ScriptDir & "\Melba23.ini"

; Create GUI
$hGUI = GUICreate("Test", 500, 500)

; And start the menu creation process
_Fill_Menu(0, "MenuTitles")

GUISetState()

While 1

    ; Get the control ID
    $iMsg = GUIGetMsg()
    Switch $iMsg
        Case $GUI_EVENT_CLOSE
            Exit
        Case Else
            ; Loop through the array to see ifit is a menuitem controlID
            For $i = 1 To $aMenuItems[0][0]
                If $aMenuItems[$i][0] = $iMsg Then
                    ; It is!
                    MsgBox(0, "Menu", "You clicked " & @CRLF & $aMenuItems[$i][1])
                    ; No point in looking further
                    ExitLoop
                EndIf
            Next
    EndSwitch

WEnd



Func _Fill_Menu($hCID, $sText)

    ; Read next level down
    $aMenu = IniReadSection($sIni, $sText)
    If Not @error Then
        ; Now either create a further submenu or a menuitem
        For $i = 1 To $aMenu[0][0]
            Switch $aMenu[$i][0]
                Case "Item"
                    ; Increase the count of menuitems
                    $aMenuItems[0][0] += 1
                    ; Increase the array size by adding a new element
                    ReDim $aMenuItems[$aMenuItems[0][0] + 1][2]
                    ; Add the ControlID and text to the newly created array element
                    $aMenuItems[$aMenuItems[0][0]][0] = GUICtrlCreateMenuItem(StringReplace($aMenu[$i][1], "_", " "), $hCID)
                    $aMenuItems[$aMenuItems[0][0]][1] = StringReplace($aMenu[$i][1], "_", " ")
                Case "Menu"
                    ; Create menu
                    If $hCID Then
                        ; It is a submenu
                        $aMenu[$i][0] = GUICtrlCreateMenu(StringReplace($aMenu[$i][1], "_", " "), $hCID)
                    Else
                        ; It is a top level menu
                        $aMenu[$i][0] = GUICtrlCreateMenu(StringReplace($aMenu[$i][1], "_", " "))
                    EndIf
                    ; Fill menu - note this is a recursive call and we need to take care
                    _Fill_Menu($aMenu[$i][0], $aMenu[$i][1])
            EndSwitch
        Next
    EndIf

EndFunc

 

Melba23.ini


Musashi-C64.png

"In the beginning the Universe was created. This has made a lot of people very angry and been widely regarded as a bad move."

Share this post


Link to post
Share on other sites

Thanks for the answers but it seems my problem can't be re-created here as the source code file is too large.

I already know how to do this kind of menu, but it doesn't help me as now I work on a good looking interface and at this chapter probably I will go with GDI+.

 

Thank you one more time.

Have a good day!

Edited by _Vlad

Quote
Destiny is a name often given in retrospect to choices that had dramatic consequences.  J.K. Rowling

 

Share this post


Link to post
Share on other sites

it's simple, use GUICtrlCreateTab() and hide it  ;) 

#include <ButtonConstants.au3>
#include <GUIConstantsEx.au3>
#include <StaticConstants.au3>
#include <WindowsConstants.au3>

;~ Global $MENU_HOVER = ''
;~ Global $MENU_SELECTED = ''
;~ Global $COLOR_STANDARD = 0x94A5E9
;~ Global $COLOR_HOVER = 0x8292d1
;~ Global $COLOR_SELECTED = 0x7584bf

Global $aLabels[18][5]
$aLabels[0][0] = UBound($aLabels) -1
SplashTextOn("..loading many things..", "..wait a sec..")
$MENU = GUICreate("Menu", 615, 437, -1, -1, -1, $WS_EX_COMPOSITED)
GUISetFont(10, 400, 0, "Arial")
For $n = 1 To $aLabels[0][0]
$aLabels[$n][0] = GUICtrlCreateButton("Menu " & $n, 8, 8 + (24 * ($n - 1)), 106, 23)
Next

$aLabels[0][1] = GUICtrlCreateTab(200,100,300,300)
GUICtrlSetState(-1, $GUI_HIDE)

For $n = 1 To $aLabels[0][0]
    $aLabels[$n][1] = GUICtrlCreateTabItem("Tab " & $n)
    For $m = 1 To 17 ; or whatever
        For $o = 1 To 5
            Switch Random(1, 5, 1)
                Case 1
                    GUICtrlCreateLabel("entry " & $n & " (" &$o & "," & $m & ")",100 + (85 * $o) , 8 + (24 * ($m - 1)), 70)
                Case 2
                    GUICtrlCreateButton("entry " & $n & " (" &$o & "," & $m & ")",100 + (85 * $o) , 8 + (24 * ($m - 1)), 70)
                Case 3
                    GUICtrlCreateInput("entry " & $n & " (" &$o & "," & $m & ")",100 + (85 * $o) , 8 + (24 * ($m - 1)), 70)
                Case 4
                    GUICtrlCreateCheckbox("entry " & $n & " (" &$o & "," & $m & ")",100 + (85 * $o) , 8 + (24 * ($m - 1)), 70)
                Case 5
                    GUICtrlCreateRadio("entry " & $n & " (" &$o & "," & $m & ")",100 + (85 * $o) , 8 + (24 * ($m - 1)), 70)
            EndSwitch
        Next
    Next
Next

GUISetState(@SW_SHOW, $MENU)

SplashOff()

While 1
    $nMsg = GUIGetMsg()
    Switch $nMsg
        Case 0, -5, -6, -7, -8, -9, -10, -11
            ; save CPU
        Case $GUI_EVENT_CLOSE
            GUIDelete()
            Exit
        Case Else
            For $n = 1 To $aLabels[0][0]
                If $nMsg = $aLabels[$n][0] Then
                    GUICtrlSetState($aLabels[$n][1], $GUI_SHOW)
                EndIf
            Next
    EndSwitch
WEnd

 

Edited by argumentum
added code

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

  • Similar Content

    • By jantograaf
      Hi all,
      I've been looking around the forum and testing different ways of getting a 'drop zone' to work in my script, but I can't seem to get any response from the event listener. Code compiles perfectly. Chaning the control from a label to an input- or edit-field doesn't change its behaviour, still no response when a file is dropped on there...
      It might just be that I am overlooking a simple detail, so I'm hoping for an extra pair of eyes here or there who can spot why this isn't working as it should. 
      I have another 3500+ lines script where I have basically the same bit of code, and it seems to work in there without problems.
      So, here it goes:
      Global $DD_GUI = GUICreate("DicomDrop",200,200,-1,-1,BitOR($WS_SYSMENU,$WS_POPUP),$WS_EX_ACCEPTFILES) GUISetBkColor(0x030303,$DD_GUI) $DD_GUI_DRAGLABEL = GUICtrlCreateLabel("",0,0,32,32,-1, $GUI_WS_EX_PARENTDRAG) $DD_GUI_DRAGIMAGE = GUICtrlCreateIcon(@ScriptFullPath,201,0,0,32,32) $DD_GUI_TITLELABEL = GUICtrlCreateLabel("DicomDrop",50,10,100,20,$SS_CENTER) GUICtrlSetFont($DD_GUI_TITLELABEL,8,$FW_SEMIBOLD,$GUI_FONTNORMAL,"Verdana") GUICtrlSetColor($DD_GUI_TITLELABEL,0xFFFFFF) $DD_GUI_CLOSE = GUICtrlCreateButton("X",174,4,24,24,$BS_FLAT) GUICtrlSetBkColor($DD_GUI_CLOSE,0x030303) GUICtrlSetColor($DD_GUI_CLOSE,0xFFFFFF) Global $DD_GUI_DROPZONE = GUICtrlCreateLabel("",10,42,180,148) GUICtrlSetState(-1,8) GUICtrlSetBkColor($DD_GUI_DROPZONE,0x181818) GUISetState(@SW_SHOW,$DD_GUI) Local $DD_MSG = 0 While 1 $DD_MSG = GUIGetMsg() Select Case $DD_MSG = $GUI_EVENT_CLOSE ConsoleWrite(@CRLF & "Debug -- Closed by GUI_EVENT_CLOSE") DD_EXIT() Case $DD_MSG = $GUI_EVENT_DROPPED If @GUI_DropId = $DD_GUI_DROPZONE Then Local $DroppedFile = @GUI_DragFile GUIDelete() ConsoleWrite(@CRLF & "Debug -- Dropped file : " & $DroppedFile) EndIf Case $DD_MSG = $DD_GUI_CLOSE ConsoleWrite(@CRLF & "Debug -- Closed by DD_GUI_CLOSEIMAGE") DD_EXIT() EndSelect WEnd Func DD_EXIT() GUIDelete($DD_GUI) Exit EndFunc If anyone has any idea whatsoever, please let me know 🙂
      Thanks in advance and kind regards,
      Jan
    • By matwachich
      Hi AutoIters!
      Here is my new UDF about GUIs: it's an enhanced mixture of Advanced InputBox (deprecated) and KODA Parser (deprecated), with additional functions.
      What you can do with it:
      Parse KODA files and directly create GUIs (_GUIUtils_CreateFromKODA) Parse a simple JSON form definition to simply create advanced InputBoxes with any amount/type of input controls (_GUIUtils_CreateFromJSON) Created GUIs are returned as Scripting.Dictionary objects, and you have helper functions to access GUIs controls by their names (_GUIUtils_HWnd, _GUIUtils_CtrlID, _GUIUtils_HCtrl ...) A function that can make a GUI created from KODA/JSON (defined by it's $oForm object) and make it a modal InputDialogBox (just like InputBox, but returns all entered data as Scripting.Dictionary object) Functions are documented, and there are some examples.
      Consider this UDF as beta, but since I'm currently using it in a small commercial project, it should become production ready in near future.
      To always get the latest code version, get it from Github (more up to date than this topic).
      Update 04/02/2020:
      New simple application example Fixed focused control handling in _GUIUtils_InputDialog Reset input values before returning from _GUIUtils_InputDialog Fixed CloseOnEsc in _GUIUtils_InputDialog Fixed Input not reset Fixed all ListBox items are selected Project now on GitHub https://github.com/matwachich/autoit-guiutils/
      Update 05/02/2020:
      Support for nodate for Date and Time input controls (pass null value) New handling of focused control _GUIUtils_InputDialog: Now, you can specify the focused control in $oInitialData by setting "controlName:focus" = True Updated documentation of _GUIUtils_InputDialog Update 07/02/2020:
      Bug corrected when setting Data input control Added: abillity to read a single input control New functions (_GUIUtils_GetInputs, _GUIUtils_WriteInputs), documentation completion. Readme file and screenshots on Github Page  
      GUIUtils.zip
    • By antonioj84
      I am not able to use the $GUI_READ_EXTENDED with the  Metro UDF,  any work around ?
      Local $aPos[2] = [$Radio1, $Radio2] For $Radio In $aPos If GUICtrlRead($Radio) = $GUI_UNCHECKED Then ContinueLoop IniWrite($sGUIstate_IniFile, "Data", "POS", GUICtrlRead($Radio, $GUI_READ_EXTENDED)) ;; return the text of the menu item ExitLoop Next  
    • By Tony007
      Hi,
      is it possible to export only the area "$idOutput" with the TEXT as a PNG?
      Thanks
      #include <ButtonConstants.au3> #include <GUIConstantsEx.au3> #include <StaticConstants.au3> Example() Func Example() Local $hGUI = GUICreate("Test", 700, 700, -1, -1) Local $input1 = GUICtrlCreateInput("", 10, 10, 150, 20) Local $idButtonStart = GUICtrlCreateButton("Start", 200, 10, 50, 30) Local $idButtonClear = GUICtrlCreateButton("Clear", 260, 10, 50, 30) Local $idButtonExport = GUICtrlCreateButton("Export", 320, 10, 50, 30) Local $idOutput = GUICtrlCreateLabel("TEXT", 10, 50, 500, 500, BitOR($BS_PUSHLIKE, $SS_CENTER)) GUICtrlSetFont($idOutput, 45, 800, "", "Impact") GUISetState(@SW_SHOW, $hGUI) ; Run the GUI until the dialog is closed While 1 Switch GUIGetMsg() Case $GUI_EVENT_CLOSE ExitLoop Case $idButtonStart $ContentInput1 = GUICtrlRead($input1) GUICtrlSetData($idOutput, $ContentInput1) Case $idButtonClear GUICtrlSetData($input1, "") GUICtrlSetData($idOutput, "") Case $idButtonExport EndSwitch WEnd GUIDelete($hGUI) Exit EndFunc ;==>Example  
    • By muchki
      i am more or less happy with my code
      only the X button does not exit
      what can i do?
      I made an 'exit' button and it works
      pressing Esc works
      just the X button not working
       
      here's my code:
       
      URLTrimmer 1.5.2 12 21 2019.txt
×
×
  • Create New...