Jump to content

Recommended Posts

Posted

I have:

For $i = $ctrl1 To $ctrl100
guictrl
  GUICtrlSetState($i, $GUI_DISABLE)
Next

how check in loop if $i is a button?

  • Moderators
Posted

Ontosy,

_WinAPI_GetClassName will do that for you. ;)

M23

Public_Domain.png.2d871819fcb9957cf44f4514551a2935.png Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind

Open spoiler to see my UDFs:

  Reveal hidden contents

 

Posted

Hi Ontosy,

I'm sure there's a way to tell the difference, but if you write your script clean you can tell by yourself whether it's a Button or sth. else.

If you have lot's of controls, using arrays comes in very handy.

You could group your controls in arrays, e.g. one array for buttons one for labels, ...

Regards,Hannes[spoiler]If you can't convince them, confuse them![/spoiler]
Posted (edited)

Was in the progress of creating this >>

#include <ButtonConstants.au3>
#include <Constants.au3>
#include <WinAPI.au3>

Example()

Func Example()
    Local $hGUI = GUICreate('')
    Local $iLabel = GUICtrlCreateButton('', 0, 0, 50, 50)
    Local $iCheckbox = GUICtrlCreateCheckbox('', 0, 0, 100, 20) ; This is considered a 'Button' by _WinAPI_GetClassName too.
    GUISetState(@SW_SHOW, $hGUI)

    MsgBox(4096, '', 'AutoIt Button ID: ' & _IsButton($iLabel) & @CRLF & _
            'AutoIt Button Handle: ' & _IsButton(GUICtrlGetHandle($iLabel)) & @CRLF & _
            'AutoIt Checkbox ID: ' & _IsButton($iCheckbox) & @CRLF & _
            'AutoIt Checkbox Handle: ' & _IsButton(GUICtrlGetHandle($iCheckbox)) & @CRLF)

    Return GUIDelete($hGUI)
EndFunc   ;==>Example

; Check if a variable is referencing a Button control.
Func _IsButton($hWnd)
    If IsHWnd($hWnd) = 0 Then
        $hWnd = GUICtrlGetHandle($hWnd)
    EndIf
    Local $sClassName = _WinAPI_GetClassName($hWnd)
    If $sClassName = 'Button' Then
        Local $aStyle[5] = [4, $BS_CHECKBOX, $BS_AUTOCHECKBOX, $BS_RADIOBUTTON, $BS_AUTORADIOBUTTON]
        Local $iLong = _WinAPI_GetWindowLong($hWnd, $GWL_STYLE)
        For $i = 1 To $aStyle[0]
            If BitAND($iLong, $aStyle[$i]) = $aStyle[$i] Then
                Return False
            EndIf
        Next
        Return True
    EndIf
    Return False
EndFunc   ;==>_IsButton
Edited by guinness

UDF List:

  Reveal hidden contents

Updated: 22/04/2018

Posted (edited)

You're welcome.

Be sure to check out the AutoIt Snippets section for more

Edited by guinness

UDF List:

  Reveal hidden contents

Updated: 22/04/2018

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.
×
×
  • Create New...