Sign in to follow this  
Followers 0
E1M1

How to enable clicking on buttons?

6 posts in this topic

How to enable clicking on buttons? at the moment nothing happens when I click on close button.I want script to keep updating gui buttons and allow user to clickon these buttons.ATmM i tested buttons by clicking on close button ( X ) and nothing happen.It would be great if someone could help me fix this

#include <ButtonConstants.au3>
#include <GUIConstantsEx.au3>
#include <EditConstants.au3>
#include <WindowsConstants.au3>
#Include <GuiButton.au3>


Dim $buttons[1]
$Form1 = GUICreate("Form1", 926, 908, 193, 115)
GUISetState(@SW_SHOW)


$left = 10
$height = 0
$n = 0

Func lol()
    $var = WinList()
For $i = 1 to $var[0][0]
  If $var[$i][0] <> "" AND IsVisible($var[$i][1]) Then
;~     MsgBox(0, $var[0][0],  $var[$i][0])
$n = $n + 1
        ReDim $buttons[1 + $n]
;~       MsgBox(0, $var[0][0],  $left)
        If $left > 900 Then
            $height = $height + 25
            $left = 10
        EndIf   
    $buttons[$n] = GUICtrlCreateButton($var[$i][0],$left,$height)
    $data = _GUICtrlButton_GetIdealSize(-1)
    $left = $left + $data[0]
;~   MsgBox(0, $var[0][0],$data[0])
  EndIf
Next    
EndFunc
;~ $i = 0



While 1
    $nMsg = GUIGetMsg()
$left = 10
$height = 0
$n = 0
lol()
Sleep(2000)
For $i = 1 To $n
    GUICtrlDelete($buttons[$i])
Next
    Switch $nMsg
        Case $GUI_EVENT_CLOSE
        Exit
    EndSwitch
WEnd




Func IsVisible($handle)
  If BitAnd( WinGetState($handle), 2 ) Then 
    Return 1
  Else
    Return 0
  EndIf
EndFunc

edited

Share this post


Link to post
Share on other sites



E1M1,

Get rid of the Sleep(2000) in your While...WEnd loop - the forced 2 second pause is making the whole script unresponsive. GUIGetMsg "automatically idles the CPU when required so that it can be safely used in tight loops without hogging all the CPU" (from the Help file).

M23


Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind._______My UDFs:

Spoiler

ArrayMultiColSort ---- Sort arrays on multiple columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

Share this post


Link to post
Share on other sites

but now it refreshes buttons extremely fast, and it is very hard to see buttons, how to fix this?


edited

Share this post


Link to post
Share on other sites

E1M1,

Run the "lol" function under Adlib. Then it is called every few seconds, giving you time to see the buttons, and your main loop stays nice and responsive:

#include <ButtonConstants.au3>
#include <GUIConstantsEx.au3>
#include <EditConstants.au3>
#include <WindowsConstants.au3>
#include <GuiButton.au3>
#include <Array.au3>

Global $buttons[1]
Global $top_button = 0

AdlibEnable("lol", 5000) ; call lol() every 5 secs

$Form1 = GUICreate("Form1", 926, 908, 193, 115)
GUISetState(@SW_SHOW)

While 1

    $nMsg = GUIGetMsg()
    Switch $nMsg
        Case $GUI_EVENT_CLOSE
            Exit
    EndSwitch
WEnd

Func lol()  
    For $i = 1 To $top_button
        GUICtrlDelete($buttons[$i])
    Next
    
    $left = 10
    $height = 0
    
    $var = WinList()
    For $i = 1 To $var[0][0]
        If $var[$i][0] <> "" And IsVisible($var[$i][1]) Then
            If $left > 900 Then
                $height = $height + 25
                $left = 10
            EndIf
            _ArrayAdd( $buttons, GUICtrlCreateButton($var[$i][0], $left, $height))
            $data = _GUICtrlButton_GetIdealSize(-1)
            $left = $left + $data[0]
        EndIf
    Next
    $top_button = UBound($buttons) - 1
EndFunc  ;==>lol

Func IsVisible($handle)
    If BitAND(WinGetState($handle), 2) Then
        Return 1
    Else
        Return 0
    EndIf
EndFunc  ;==>IsVisible

M23


Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind._______My UDFs:

Spoiler

ArrayMultiColSort ---- Sort arrays on multiple columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

Share this post


Link to post
Share on other sites

#5 ·  Posted (edited)

Thanks your script works fine.I show what I have invented ... I wanted to get rid of blinking, and I want it to refresh pretty fast and I wanted to reduce cpu usage and then I made up script but crashes when I close window.

@Melba23 how I can have button click actions for other buttons?

I tried

Case $buttons

WinSetState(GUICtrlRead($buttons),"",@SW_MINIMIZE)

and

Case $buttons[$i]

WinSetState(GUICtrlRead($buttons[$i]),"",@SW_MINIMIZE)

but nothing happened

#include <ButtonConstants.au3>
#include <GUIConstantsEx.au3>
#include <EditConstants.au3>
#include <WindowsConstants.au3>
#Include <GuiButton.au3>


Dim $buttons[1]
Global $var
$Form1 = GUICreate("Form1", 926, 908, 193, 115)
GUISetState(@SW_SHOW)


$left = 10
$height = 0
$n = 0
lol()

Func lol()
    Dim $buttons[1]
    $left = 10
$height = 0
$n = 0
$var = ""
$data = ""
    ReDim $buttons[1]
    For $i = 1 To $n
    GUICtrlDelete($buttons[$i])
Next
    $var = WinList()
For $i = 1 to $var[0][0]
  If $var[$i][0] <> "" AND IsVisible($var[$i][1]) Then
$n = $n + 1
        ReDim $buttons[1 + $n]
        If $left > 800 Then
            $height = $height + 25
            $left = 10
        EndIf   
    $buttons[$n] = GUICtrlCreateButton($var[$i][0],$left,$height)
    $data = _GUICtrlButton_GetIdealSize(-1)
    $left = $left + $data[0]
  EndIf
Next
EndFunc

Func winclosewait($whandle)
    $exist = WinExists($whandle)
    if $exist = 0 Then
;~  MsgBox(1,1,WinExists($whandle))
    lol()
    EndIf
EndFunc 

Func winwaitcreate()
    EndFunc
;~ $i = 0

Func rem ()
    ;~ Sleep(500)
For $i = 1 To $n
    GUICtrlDelete($buttons[$i])
Next
EndFunc

While 1
;~  Sleep(250)
    For $i = 1 to $n
        $text = GUICtrlRead($buttons[$i])
    winclosewait($text)
    Next
    $nMsg = GUIGetMsg()
    Switch $nMsg
        Case $GUI_EVENT_CLOSE
        Exit
    EndSwitch
WEnd




Func IsVisible($handle)
  If BitAnd( WinGetState($handle), 2 ) Then
    Return 1
  Else
    Return 0
  EndIf
EndFunc
Edited by E1M1

edited

Share this post


Link to post
Share on other sites

How to enable clicking on buttons? at the moment nothing happens when I click on close button.I want script to keep updating gui buttons and allow user to clickon these buttons.ATmM i tested buttons by clicking on close button ( X ) and nothing happen.It would be great if someone could help me fix this

Here is an example based off of your original script. It should give you insight as to how you can use the "OnEvent" functions to make something happen when you click on your buttons. To reduce the flickering you were experiencing, this script only deletes and recreates the buttons when it notice a change in how many windows are open.

#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>
#include <Array.au3>

AutoItSetOption("GUIOnEventMode", 1)

Global $WindowCountThen, $buttons[1] = [0]

$gui = GUICreate("Visible Windows", 520, 500)
GUISetOnEvent($GUI_EVENT_CLOSE, "_Exit")

_Setbuttons()

GUISetState()

$WindowCountThen = WinList()

While 1 
    $WindowCountNow = WinList()
    
    If $WindowCountNow[0][0] <> $WindowCountThen[0][0] Then 
        _Setbuttons()
        $WindowCountThen = WinList()
    EndIf
    
    Sleep(20)
WEnd

Func _Setbuttons()
    Local $VisibleWindows = _GetVisibleWindows()
    
    If $buttons[0] <> 0 Then
        For $i = $buttons[0] to 1 Step -1
            GUICtrlDelete($buttons[$i])
            _ArrayPop($buttons)
        Next
        $buttons[0] = 0
    EndIf
    
    For $i = 1 to $VisibleWindows[0][0]
        _ArrayAdd($buttons, GUICtrlCreateButton($VisibleWindows[$i][0], 10, $i * 25, 500))
        GUICtrlSetOnEvent($buttons[$i], "_BringToFront")
        $buttons[0] = $i
    Next
EndFunc

Func _GetVisibleWindows()
    Local $aWins = WinList(), $aVisibleWins[1][1], $count = 0
    
    For $i = 1 to $aWins[0][0]
        If $aWins[$i][0] <> "" AND _IsVisible($aWins[$i][1]) Then
            $count += 1
            ReDim $aVisibleWins[$count + 1][$count + 1]
            
            $aVisibleWins[$count][0] = $aWins[$i][0]
            $aVisibleWins[$count][1] = $aWins[$i][1]
        EndIf
    Next
    $aVisibleWins[0][0] = $count
    
    Return $aVisibleWins
EndFunc
    
Func _IsVisible($handle)
    If BitAnd( WinGetState($handle), 2 ) Then 
        Return 1
    Else
        Return 0
    EndIf
EndFunc

Func _BringToFront()
    WinActivate(GUICtrlRead(@GUI_CtrlId))
EndFunc

Func _Exit()
    Exit
EndFunc

I hope this helps some.

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