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
1 minute ago, _Vlad said:

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

Could you upload an example of that kind of script so I can see what is the issue.

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

If it's necessary, give me a few minutes I will upscale this.


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
3 minutes ago, _Vlad said:

If it's necessary, give me a few minutes I will upscale this.

Yes, that would at least give us an impression of how strong the flickering is.


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

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

Many thanks, @argumentum.

I will do some tests with that function and come later with an answer.

 

Have a nice day :) 


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

@argumentum I want to thank you. I tested that and helped me optimize.

This is a good solution.


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

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

  • Recently Browsing   0 members

    No registered users viewing this page.

  • Similar Content

    • By Rskm
      Hi, recently i created a GUI for some calculations in AutoIT.  The GUI has 2 tabs and on the first tab, it has few inputboxes where i use to click with mouse and start entering the inputs. i recently made some changes in the position of these textboxes. I made this by changing the autoit code file instead of making changes in KODA. Now i cannot click inside these textboxes with mouse. However, i can use TAB key to cycle through/enter input in these input boxes. what could have made the inputboxes not responding to mouseclicks. thanks
    • By TheDcoder
      Hi everyone,
      I am bit stumped as to why I am not able to set the time in the Date control
      #include <DateTimeConstants.au3> #include <GUIConstantsEx.au3> #include <MsgBoxConstants.au3> Example() Func Example() GUICreate("My GUI get date", 200, 200, 800, 200) Local $idDate = GUICtrlCreateDate("1953/04/25", 10, 10, 185, 20, $DTS_TIMEFORMAT) ; to select a specific default format Local $sStyle = "HH:mm:ss" GUICtrlSendMsg($idDate, $DTM_SETFORMATW, 0, $sStyle) ; Set time Local $iRet = GUICtrlSetData($idDate, '13:33:37') ConsoleWrite('GUICtrlSetData returned ' & ($iRet = 1 ? 'success' : 'failure') & @CRLF) GUISetState(@SW_SHOW) ; Loop until the user exits. While GUIGetMsg() <> $GUI_EVENT_CLOSE WEnd MsgBox($MB_SYSTEMMODAL, "Time", GUICtrlRead($idDate)) EndFunc ;==>Example The documentation for GUICtrlSetData clearly mentions that it uses the same format as GUICtrlRead:
      But I get failure
      What gives?
      Thanks for the help in advance!
    • By thedemons
      Introduction
      ImGui is a popular library written by ocornut, it can make awesome user interface based on directx. It is being used by many big apps/games.  The UI is nice and flexible, easy to use because of frame-by-frame drawing. So I decided to convert the entire ImGui library to AutoIt
      At first it's just an experiment, i converted some basic draw functions of imgui, compile to a dll, then using DllCall in autoit to call the functions. I was testing to see how much FPS i can get in autoit, and i was expected a low FPS, since autoit is slow. Suprisingly, the FPS turned out to be so high, it works really fast, even when drawing 1000 buttons at the same time. Features
      More than +270 functions converted from ImGui (compiled dll). Has 90% of the capability of what you can do in C++; Usable ImGuiIO and ImGuiStyle, so you can set whatever configurations you like. Preview
          
      Usage
      #include <WinAPI.au3> #include "ImGui.au3" ; Create a window Local $hwnd = _ImGui_GUICreate("AutoIt ImGui", 1024, 768) _WinAPI_ShowWindow($hwnd) ; Set style color _ImGui_StyleColorsLight() ;~ _ImGui_StyleColorsDark() Local $f_value = 5 While 1 ; when the user click close button on the window, this will return false if Not _ImGui_PeekMsg() Then Exit ; must call _ImGui_BeginFrame() _ImGui_Begin("Another window") _ImGui_Text("Hello there..") If _ImGui_Button("click me") Then $f_value = 5 _ImGui_SliderFloat("slider", $f_value, 2, 20) If _ImGui_IsItemHovered() Then _ImGui_ToolTip("what r u doing?") _ImGui_End() ; must call _ImGui_EndFrame() Wend  
      Remark
      Most of the functions were converted automatically. I haven't tested all of them yet, if some function doesn't work for you, please tell me. Still missing some features of ImGui, please tell me if you needed any. Run \tools\imgui-au3-setup.au3 to add _ImGui functions to SciTE auto-complete. Source Code
      Require: DirectX GitHub: imgui-autoit
    • By MesterPerfect
      good morning
      this is the first post here in the autoit forums
      i hope that you can help me in my problem
      i have a JSON encoded
      it a map of my forums
      where i want to make a treeview that have the same type of map
      e.g
      a system (as category)
      windows (as sub category)
      software (as an child item in the windows category)
      .....
      i don't know how to do that
      so, i know that i can do that using the json functions
      but i need your help about how we can do it as the type that i told you
      by the way i need to put the sub info for each item in an array that give me the ability to manage my items
      e.g
      can post thread
      can reply
      message cound ...
      you just give me a small example and i can continue.
      am sorry if this against the rules of the forum.
      but i realy searched a lot but i couldn't
      i hope some one give me the way.
      thank you very much in advance
       
      here is the link of json forum
      https://www.autoitscript.com/forum/topic/148114-a-non-strict-json-udf-jsmn/
      and here is my encoded json file
       
      { "tree_map": { "0": [ 1, 5, 6, 7 ], "1": [ 2 ], "2": [ 4 ], "5": [ 3 ], "6": [ 8 ], "8": [ 9, 10 ] }, "nodes": [ { "breadcrumbs": [], "description": "", "display_in_list": true, "display_order": 1, "node_id": 1, "node_name": null, "node_type_id": "Category", "parent_node_id": 0, "title": "Main category", "type_data": {} }, { "breadcrumbs": [ { "node_id": 1, "title": "Main category", "node_type_id": "Category" } ], "description": "", "display_in_list": true, "display_order": 1, "node_id": 2, "node_name": null, "node_type_id": "Forum", "parent_node_id": 1, "title": "Main forum", "type_data": { "allow_poll": true, "allow_posting": true, "can_create_thread": true, "can_upload_attachment": true, "discussion_count": 0, "last_post_date": 0, "last_post_id": 0, "last_post_username": "", "last_thread_id": 0, "last_thread_prefix_id": 0, "last_thread_title": "", "message_count": 0, "min_tags": 0, "require_prefix": false } }, { "breadcrumbs": [ { "node_id": 1, "title": "Main category", "node_type_id": "Category" }, { "node_id": 2, "title": "Main forum", "node_type_id": "Forum" } ], "description": "", "display_in_list": true, "display_order": 1, "node_id": 4, "node_name": null, "node_type_id": "Forum", "parent_node_id": 2, "title": "my forums1", "type_data": { "allow_poll": true, "allow_posting": true, "can_create_thread": true, "can_upload_attachment": true, "discussion_count": 0, "last_post_date": 0, "last_post_id": 0, "last_post_username": "", "last_thread_id": 0, "last_thread_prefix_id": 0, "last_thread_title": "", "message_count": 0, "min_tags": 0, "require_prefix": false } }, { "breadcrumbs": [], "description": "", "display_in_list": true, "display_order": 2, "node_id": 5, "node_name": null, "node_type_id": "Category", "parent_node_id": 0, "title": "Perfect", "type_data": {} }, { "breadcrumbs": [ { "node_id": 5, "title": "Perfect", "node_type_id": "Category" } ], "description": "", "display_in_list": true, "display_order": 2, "node_id": 3, "node_name": null, "node_type_id": "Forum", "parent_node_id": 5, "title": "ahmed", "type_data": { "allow_poll": true, "allow_posting": true, "can_create_thread": true, "can_upload_attachment": true, "discussion_count": 0, "last_post_date": 0, "last_post_id": 0, "last_post_username": "", "last_thread_id": 0, "last_thread_prefix_id": 0, "last_thread_title": "", "message_count": 0, "min_tags": 0, "require_prefix": false } }, { "breadcrumbs": [], "description": "", "display_in_list": true, "display_order": 3, "node_id": 6, "node_name": null, "node_type_id": "Forum", "parent_node_id": 0, "title": "autoit", "type_data": { "allow_poll": true, "allow_posting": true, "can_create_thread": true, "can_upload_attachment": true, "discussion_count": 0, "last_post_date": 0, "last_post_id": 0, "last_post_username": "", "last_thread_id": 0, "last_thread_prefix_id": 0, "last_thread_title": "", "message_count": 0, "min_tags": 0, "require_prefix": false } }, { "breadcrumbs": [ { "node_id": 6, "title": "autoit", "node_type_id": "Forum" } ], "description": "", "display_in_list": true, "display_order": 3, "node_id": 8, "node_name": null, "node_type_id": "Forum", "parent_node_id": 6, "title": "examples", "type_data": { "allow_poll": true, "allow_posting": true, "can_create_thread": true, "can_upload_attachment": true, "discussion_count": 0, "last_post_date": 0, "last_post_id": 0, "last_post_username": "", "last_thread_id": 0, "last_thread_prefix_id": 0, "last_thread_title": "", "message_count": 0, "min_tags": 0, "require_prefix": false } }, { "breadcrumbs": [ { "node_id": 6, "title": "autoit", "node_type_id": "Forum" }, { "node_id": 8, "title": "examples", "node_type_id": "Forum" } ], "description": "", "display_in_list": true, "display_order": 3, "node_id": 9, "node_name": null, "node_type_id": "Forum", "parent_node_id": 8, "title": "GUI", "type_data": { "allow_poll": true, "allow_posting": true, "can_create_thread": true, "can_upload_attachment": true, "discussion_count": 0, "last_post_date": 0, "last_post_id": 0, "last_post_username": "", "last_thread_id": 0, "last_thread_prefix_id": 0, "last_thread_title": "", "message_count": 0, "min_tags": 0, "require_prefix": false } }, { "breadcrumbs": [ { "node_id": 6, "title": "autoit", "node_type_id": "Forum" }, { "node_id": 8, "title": "examples", "node_type_id": "Forum" } ], "description": "", "display_in_list": true, "display_order": 31, "node_id": 10, "node_name": null, "node_type_id": "Forum", "parent_node_id": 8, "title": "windowEX", "type_data": { "allow_poll": true, "allow_posting": true, "can_create_thread": true, "can_upload_attachment": true, "discussion_count": 0, "last_post_date": 0, "last_post_id": 0, "last_post_username": "", "last_thread_id": 0, "last_thread_prefix_id": 0, "last_thread_title": "", "message_count": 0, "min_tags": 0, "require_prefix": false } }, { "breadcrumbs": [], "description": "", "display_in_list": true, "display_order": 4, "node_id": 7, "node_name": null, "node_type_id": "Category", "parent_node_id": 0, "title": "vbs", "type_data": {} } ] }  
    • By Tosyk
      Hi,
      Please help me to beat the flashing of input field:
      #include <File.au3> #Include <GUIConstantsEx.au3> #include <StaticConstants.au3> #include <WindowsConstants.au3> #include <ColorConstants.au3> AutoItSetOption("MustDeclareVars", 1) HotKeySet("{ESC}", "Terminate") Local $i Local $sSourceFile, $sDestFileA, $sDestFile3, $sRunWaitA, $sParamsA, $sNewFileNameA, $sFileLogPath, $iFileSize, $ScriptNameWoExt Local $hGUI, $ProgressBar1, $Label, $Progress, $Progress1, $inpVal, $CheckKeepAlpha, $v1, $sNewFileName, $sDestFile, $sParams, $sRunWait, $LabelStatus, $bMover, $cMover, $qMover, $ExtractAlpha, $FlipY, $ExtractBlue Local $sDrive, $sFolder, $sFileName, $sExt ;path to image magick tools Local $sIMConv = 'magick.exe', $sIMPathFull = 'C:\Program Files\ImageMagick\', $sIMPath = FileGetShortName($sIMPathFull & $sIMConv) ;supported input file extensions Local $Exts = "tga|jpg|bmp|dds|png|tif|jpeg", $sPattern = "\.(?i:" & $Exts & ")", $ExtsPreview = " tga | jpg | bmp | dds | png | tif | jpeg " Local $ExtOutput = "jpg", $ExtOutput2 = "png" Local $LogDefaultSize = '70' If Not $CmdLine[0] Then MsgBox($MB_SYSTEMMODAL, "Usage", "Drop " & $ExtsPreview & " file(s)" & @LF & "on " & @ScriptName) ConsoleWrite("Usage: " & @ScriptName & " <file>" & @CRLF) Exit EndIf If $CmdLine[0] <> 0 Then If FileExists($sIMPath) Then ProcessFiles() Else MsgBox(0, $sIMConv & " not found", "File [" & $sIMPathFull & $sIMConv & "] not found" & @CRLF) ConsoleWrite("Download Image Magick: " & $sIMConv & " to use this tool." & @CRLF) EndIf Else MsgBox(0, "Usage", "Drop file(s) on " & @ScriptName) ConsoleWrite("Usage: " & @ScriptName & " <file>" & @CRLF) EndIf Func ProcessFiles() #Region ### START Koda GUI section ### Form= $hGUI = GUICreate("Converting to PNG", 300, 285, -1, -1, BitXOR($GUI_SS_DEFAULT_GUI, $WS_MINIMIZEBOX)) GUISetOnEvent($GUI_EVENT_CLOSE, "Terminate") ;PNG Option group $cMover = 0 Local $Group2 = GUICtrlCreateGroup("Options (PNG):", 8, 5+$cMover, 284, 56) $CheckKeepAlpha = GUICtrlCreateCheckbox("Keep alpha channel", 24, 30+$cMover, 130, 17) $FlipY = GUICtrlCreateCheckbox("Flip Vertical", 160, 30+$cMover, 130, 17) GUICtrlSetState($CheckKeepAlpha, $GUI_CHECKED) ;JPG Quality Input $qMover = 68 Local $Group1 = GUICtrlCreateGroup("Extraction options (JPG):", 8, 5+$qMover, 284, 86) $ExtractAlpha = GUICtrlCreateCheckbox("Extract alpha channel", 24, 28+$qMover, 130, 17) $ExtractBlue = GUICtrlCreateCheckbox("Extract blue channel", 160, 28+$qMover, 130, 17) $inpVal = GUICtrlCreateInput("90", 20, 56+$qMover, 260, 22) GUICtrlSetState($inpVal, $GUI_DISABLE) ;Buttons and bar $bMover = 92 $Label = GUICtrlCreateLabel("Press Convert to proceed", 20, 94+$bMover, 220, 20, $SS_LEFT) $LabelStatus = GUICtrlCreateLabel("Ready", 20, 153+$bMover, 220, 20, $SS_LEFT) $Progress1 = CreateProgress(20, 115+$bMover, 260, 20) Local $Button1 = GUICtrlCreateButton("Convert", 206, 150+$bMover, 75, 25) GUICtrlSetState ($Button1, $GUI_DEFBUTTON) ;Initializer GUISetState(@SW_SHOW) #EndRegion ### END Koda GUI section ### While 1 Switch GUIGetMsg() Case $GUI_EVENT_CLOSE ExitLoop Exit Case $ExtractAlpha or $ExtractBlue If _IsChecked($ExtractAlpha) or _IsChecked($ExtractBlue) Then GUICtrlSetState($inpVal, $GUI_ENABLE) Else GUICtrlSetState($inpVal, $GUI_DISABLE) EndIf Case $Button1 GUICtrlSetState($inpVal, $GUI_DISABLE) GUICtrlSetState($CheckKeepAlpha, $GUI_DISABLE) GUICtrlSetState($Button1, $GUI_DISABLE) MainLoop() ExitLoop Case Else ContinueLoop EndSwitch WEnd EndFunc ;==>ProcessFiles Func Settings() If _IsChecked($CheckKeepAlpha) Then $v1 = ' ' Else $v1 = ' ' & '-alpha off' & ' ' EndIf If _IsChecked($ExtractAlpha) Then ;Extracting JPG $sSourceFile = '"' & $sSourceFile & '"' $sNewFileNameA = ($sFileName & '_a.' & $ExtOutput) $sDestFileA = '"' & $sDrive & StringTrimRight($sFolder, 1) & '\' & $sNewFileNameA & '"' $sParamsA = '-channel A -separate -quality' & ' ' & GUICtrlRead($inpVal) & ' ' & '-colorspace sRGB' $sRunWaitA = $sIMPath & " " & $sSourceFile & " " & $sParamsA & " " & $sDestFileA EndIf ;Converting PNG $sNewFileName = ($sFileName & '.' & $ExtOutput2) $sDestFile = '"' & $sDrive & StringTrimRight($sFolder, 1) & '\' & $sNewFileName & '"' $sDestFile3 = $sDrive & StringTrimRight($sFolder, 1) & '\' & $sNewFileName $sParams = $v1 & '-colorspace sRGB' $sRunWait = $sIMPath & " " & $sSourceFile & " " & $sParams & " " & $sDestFile EndFunc ;==>Settings Func MainLoop() WriteLogFile() ConsoleWrite("File Log Path: " & $sFileLogPath & @LF) For $i = 1 To $CmdLine[0] $sSourceFile = $CmdLine[$i] _PathSplit($sSourceFile, $sDrive, $sFolder, $sFileName, $sExt) GUICtrlSetData($ProgressBar1, ($i / $CmdLine[0]) * 100) UpdateProgress($Progress1, ($i / $CmdLine[0]) * 100) GUICtrlSetData($Label, $sFileName & $sExt) GUICtrlSetState($LabelStatus, $GUI_ENABLE) GUICtrlSetColor($LabelStatus, $COLOR_BLACK) GUICtrlSetData($LabelStatus, 'Converting') Sleep(20) If StringRegExp($sExt, "\A" & $sPattern & "\z", 0) = 1 Then If FileExists($sSourceFile) Then Settings() ; function of settings ConsoleWrite("Full converting path: " & $sRunWaitA & @LF) If _IsChecked($ExtractAlpha) Then RunWait(@ComSpec & ' /c ' & $sRunWaitA, '', @SW_HIDE) EndIf RunWait(@ComSpec & ' /c ' & $sRunWait, '', @SW_HIDE) Else ConsoleWriteError("File [" & $sSourceFile & "] not found" & @CRLF) EndIf If FileExists($sDestFile3) Then LabelAnim(' .') LabelAnim(' . .') LabelAnim(' . . .') LabelAnim(' . . . OK') Sleep(20) Else LabelAnim(' .') LabelAnim(' . .') LabelAnim(' . . .') GUICtrlSetColor($LabelStatus, $COLOR_RED) LabelAnim(' . . . ERROR') UpdateLogFile() EndIf Else ; MsgBox(0, "Wrong extension", "Extension of file [" & $sFileName & "] is [" & $sExt & "] and not in" & @LF & "[" & $ExtsPreview & "]" & @CRLF) ConsoleWriteError("Extension of file [" & $sSourceFile & "] is [" & $sExt & "] and not in [" & $sPattern & "]" & @CRLF) ; Terminate() LabelAnim(' .') LabelAnim(' . .') LabelAnim(' . . .') GUICtrlSetColor($LabelStatus, $COLOR_RED) LabelAnim(' . . . Wrong Extension') UpdateLogFile() EndIf Next ; Retrieve the file size (in bytes) $iFileSize = FileGetSize($sFileLogPath) ConsoleWrite("FileLog size: " & $iFileSize & @LF) If $iFileSize < $LogDefaultSize Then FileDelete($sFileLogPath) ElseIf $iFileSize > $LogDefaultSize Then FileMove($sFileLogPath, @WorkingDir, $FC_OVERWRITE) EndIf GUICtrlSetData($Label, "Converting complete") Sleep(10) EndFunc ;==>MainLoop Func LabelAnim($Result) GUICtrlSetData($LabelStatus, 'Converting' & $Result) Sleep(12) EndFunc Func RemoveExt($Input) Local $ExtArray = StringSplit($Input, ".") Return StringReplace($Input, "." & $ExtArray[$ExtArray[0]], "", -1) EndFunc Func GetFileName($Input) Local $PathArray = StringSplit($Input, "\/") Return $PathArray[$PathArray[0]] EndFunc ;--------------------------------------------------------------- ;- Creating file in @tempdir ;--------------------------------------------------------------- Func WriteLogFile() ; Create a constant variable in Local scope of the filepath that will be read/written to. $ScriptNameWoExt = RemoveExt(GetFileName(@ScriptName)) $sFileLogPath = (@TempDir & '\' & '_' & $ScriptNameWoExt & '_errorlog_' & @YEAR & '_' & @MON & '_' & @MDAY & '_' & @HOUR & '_' & @MIN & '_' & @SEC & '_.txt') If FileExists($sFileLogPath) Then FileDelete($sFileLogPath) EndIf ; Create a temporary file to write data to. If Not FileWrite($sFileLogPath, "ImageMagick converter (" & $sIMConv & ") can't convert these files:" & @CRLF) Then MsgBox($MB_SYSTEMMODAL, "", "An error occurred whilst writing the temporary file.") Return False EndIf EndFunc ;--------------------------------------------------------------- ;- Update log file in @tempdir ;--------------------------------------------------------------- Func UpdateLogFile() ; Open the file for writing (append to the end of a file) and store the handle to a variable. Local $hFileOpen = FileOpen($sFileLogPath, $FO_APPEND) If $hFileOpen = -1 Then MsgBox($MB_SYSTEMMODAL, "", "An error occurred whilst writing the temporary file.") Return False EndIf ; Write data to the file using the handle returned by FileOpen. FileWriteLine($hFileOpen, ($sFileName & $sExt)) Sleep(20) ; Close the handle returned by FileOpen. FileClose($hFileOpen) EndFunc ;--------------------------------------------------------------- ;- Enhanced Progress widget ;--------------------------------------------------------------- Func CreateProgress($x, $y, $w, $h, $Label="") Dim $Progress[2] $Progress[0] = GuiCtrlCreateProgress($x, $y, $w, $h) ; this is progress bar $Progress[1] = GuiCtrlCreateLabel("---", $x+0, $y-21, '', '', $SS_RIGHT) ; this is percentage label GUICtrlSetFont($Progress[1], 11, 500, 0, "") GUICtrlSetBkColor($Progress[1], $GUI_BKCOLOR_TRANSPARENT) Return $Progress EndFunc Func UpdateProgress($ProgressID, $Percent, $Label="") GUICtrlSetData($ProgressID[0], $Percent) GUICtrlSetData($ProgressID[1], $Label & Round($Percent, 1) & "%") EndFunc Func _IsChecked($idControlID) Return BitAND(GUICtrlRead($idControlID), $GUI_CHECKED) = $GUI_CHECKED EndFunc ;==>_IsChecked Func Terminate() If WinGetHandle('') <> $hGUI Then HotKeySet('{ESC}') Send('{ESC}') HotKeySet('{ESC}', '_Close') Return EndIf GUIDelete() Exit EndFunc ;==>Terminate Exit(0) the problem caused by this area:
      Case $ExtractAlpha or $ExtractBlue If _IsChecked($ExtractAlpha) or _IsChecked($ExtractBlue) Then GUICtrlSetState($inpVal, $GUI_ENABLE) Else GUICtrlSetState($inpVal, $GUI_DISABLE) EndIf if I remove "or $ExtractBlue" and "or _IsChecked($ExtractBlue)" the input field is not flashing.
      p.s.: also my button don't work if I use OR for the "Case" condition.
×
×
  • Create New...