jdelaney

Get style of a control

7 posts in this topic

I'm trying to setup a function that will return the text or checked state of a button...when the button is a checkbox or a radio, return the "ischecked", else return the button's text...I'm not seeing anything that would return the style.


IEbyXPATH-Grab IE DOM objects by XPATH IEscriptRecord-Makings of an IE script recorder ExcelFromXML-Create Excel docs without excel installed GetAllWindowControls-Output all control data on a given window.

Share this post


Link to post
Share on other sites



#2 ·  Posted (edited)

https://www.autoitscript.com/autoit3/docs/functions/GUIGetStyle.htm

What do you think?

EDIT: wait, you mean the style of the button?

Edited by careca

Spoiler

Paster - Main function is to paste text, but has more functions.

OpenW - Open With... alternative, Open any file with any application, set it's icon, set application as default.

Renamer - Rename files and folders, remove portions of text from the filename etc.

BeatsPlayer - Music player.

Params Tool - Right click an exe to see it's parameters or execute them.

Regedit Control - Registry browsing history, quickly jump into any saved key.

Time4Shutdown - Write the time for shutdown in minutes.

Power Profiles Tool - Set a profile as active, delete, duplicate, export and import.

Firefox Profile Backup - Backup/restore previously saved profile.

Finished Task Shutdown - Shuts down pc when specified window/Wndl/process closes.

NetworkSpeedShutdown - Shuts down pc if download speed goes under "X" Kb/s.

 

Share this post


Link to post
Share on other sites

#3 ·  Posted (edited)

Yes, the style of the button...I attempted to pass the handle of the control to that function, and no good...returns 0:

Here is a slightly modified help file function...:

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

_Main()

Func _Main()
    Local $btn, $btn2
    $h = GUICreate("Buttons", 400, 400)
    GUISetState()
    $btn = GUICtrlCreateButton("Button1", 10, 10, 90, 50)
    $btn2 = GUICtrlCreateButton("Button2", 10, 70, 90, 50)
    $btn3 = GUICtrlCreateButton("Button3", 10, 130, 90, 50)
    MsgBox(4096, "Information", "Setting Button Style")
    _GUICtrlButton_SetStyle($btn, $BS_AUTORADIOBUTTON)
    _GUICtrlButton_SetStyle($btn2, $BS_AUTOCHECKBOX)

    $hB1 = ControlGetHandle($h,"",$btn)
    $hB2 = ControlGetHandle($h,"",$btn2)
    $hB3 = ControlGetHandle($h,"",$btn3)
    $sStyleB1 = GUIGetStyle($hB1)
    $sStyleB2 = GUIGetStyle($hB2)
    $sStyleB3 = GUIGetStyle($hB3)
    ConsoleWrite($hB1 & " " & $sStyleB1 & @CRLF)
    ConsoleWrite($hB2 & " " & $sStyleB2 & @CRLF)
    ConsoleWrite($hB3 & " " & $sStyleB3 & @CRLF)

EndFunc   ;==>_Main
While True
    Switch GUIGetMsg()
        Case $GUI_EVENT_CLOSE
            ExitLoop

    EndSwitch
WEnd

 

Edited by jdelaney

IEbyXPATH-Grab IE DOM objects by XPATH IEscriptRecord-Makings of an IE script recorder ExcelFromXML-Create Excel docs without excel installed GetAllWindowControls-Output all control data on a given window.

Share this post


Link to post
Share on other sites

jdelaney,

when the button is a checkbox or a radio, return the "ischecked", else return the button's text

This script will do that:

#include <GUIConstantsEx.au3>
#include <MsgBoxConstants.au3>

$hGUI = GUICreate("Test", 500, 500)

$cRadio_1 = GUICtrlCreateRadio(" Radio control 1", 10, 10, 200, 20)

$cRadio_2 = GUICtrlCreateRadio(" Radio control 2", 10, 40, 200, 20)

GUISetState()

While 1

    Switch GUIGetMsg()
        Case $GUI_EVENT_CLOSE
            Exit
        Case $cRadio_1, $cRadio_2
            $sMsg = ""
            If GUICtrlRead($cRadio_1) = $GUI_CHECKED Then
                $sMsg &= "State: Radio 1 checked"
            Else
                $sMsg &= "Text: " & GUICtrlRead($cRadio_1, 1)
            EndIf

            $sMsg &= @CRLF
            If GUICtrlRead($cRadio_2) = $GUI_CHECKED Then
                $sMsg &= "State: Radio 2 checked"
            Else
                $sMsg &= "Text: " & GUICtrlRead($cRadio_2, 1)
            EndIf

            MsgBox($MB_SYSTEMMODAL, "Result", $sMsg)

    EndSwitch



WEnd

If you actually want the style, then you need to call the API as explained in the Setting Styles tutorial in the Wiki:

#include <Constants.au3> ; Do not forget these include files!
#include <WinAPI.au3>
 
$iStyle   = _WinAPI_GetWindowLong(GUICtrlGetHandle($cControlID), $GWL_STYLE)
$iExStyle = _WinAPI_GetWindowLong(GUICtrlGetHandle($cControlID), $GWL_EXSTYLE)

M23

1 person likes this

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

Thanks Melba, I posted that just as an example, I'm working with a 3rd party application so the Gui* funcs won't do it for me...I'll look into _WinAPI_GetWindowLong.


IEbyXPATH-Grab IE DOM objects by XPATH IEscriptRecord-Makings of an IE script recorder ExcelFromXML-Create Excel docs without excel installed GetAllWindowControls-Output all control data on a given window.

Share this post


Link to post
Share on other sites

#6 ·  Posted (edited)

Got it...thanks again Melba...just need to add a check if there is a BitAND of either $BS_RADIOBUTTON or $BS_AUTORADIOBUTTON...if not, it's a button.:

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

_Main()

Func _Main()
    Local $btn, $btn2
    $h = GUICreate("Buttons", 400, 400)
    GUISetState()
    $btn = GUICtrlCreateButton("Button1", 10, 10, 90, 50)
    $btn2 = GUICtrlCreateButton("Button2", 10, 70, 90, 50)
    $btn3 = GUICtrlCreateButton("Button3", 10, 130, 90, 50)

    _GUICtrlButton_SetStyle($btn, $BS_AUTORADIOBUTTON)
    _GUICtrlButton_SetStyle($btn2, $BS_AUTOCHECKBOX)

    $hB1 = ControlGetHandle($h,"",$btn)
    $hB2 = ControlGetHandle($h,"",$btn2)
    $hB3 = ControlGetHandle($h,"",$btn3)

    $sStyleB1 = _WinAPI_GetWindowLong(GUICtrlGetHandle($btn), $GWL_STYLE)
    $sStyleB2 = _WinAPI_GetWindowLong(GUICtrlGetHandle($btn2), $GWL_STYLE)
    $sStyleB3 = _WinAPI_GetWindowLong(GUICtrlGetHandle($btn3), $GWL_STYLE)

    If BitAND($sStyleB1,$BS_CHECKBOX)=$BS_CHECKBOX Or BitAND($sStyleB1,$BS_AUTOCHECKBOX)=$BS_AUTOCHECKBOX Then
        ConsoleWrite("Button 1 is a checkbox" & @CRLF)
    ElseIf BitAND($sStyleB1,$BS_RADIOBUTTON)=$BS_RADIOBUTTON Or BitAND($sStyleB1,$BS_AUTORADIOBUTTON)=$BS_AUTORADIOBUTTON Then
        ConsoleWrite("Button 1 is a radio" & @CRLF)
    Else
        ConsoleWrite("Button 1 is only a button" & @CRLF)
    EndIf



    If BitAND($sStyleB2,$BS_CHECKBOX)=$BS_CHECKBOX Or BitAND($sStyleB2,$BS_AUTOCHECKBOX)=$BS_AUTOCHECKBOX Then
        ConsoleWrite("Button 2 is a checkbox" & @CRLF)
    ElseIf BitAND($sStyleB2,$BS_RADIOBUTTON)=$BS_RADIOBUTTON Or BitAND($sStyleB2,$BS_AUTORADIOBUTTON)=$BS_AUTORADIOBUTTON Then
        ConsoleWrite("Button 2 is a radio" & @CRLF)
    Else
        ConsoleWrite("Button 2 is only a button" & @CRLF)
    EndIf



    If BitAND($sStyleB3,$BS_CHECKBOX)=$BS_CHECKBOX Or BitAND($sStyleB3,$BS_AUTOCHECKBOX)=$BS_AUTOCHECKBOX Then
        ConsoleWrite("Button 3 is a checkbox" & @CRLF)
    ElseIf BitAND($sStyleB3,$BS_RADIOBUTTON)=$BS_RADIOBUTTON Or BitAND($sStyleB3,$BS_AUTORADIOBUTTON)=$BS_AUTORADIOBUTTON Then
        ConsoleWrite("Button 3 is a radio" & @CRLF)
    Else
        ConsoleWrite("Button 3 is only a button" & @CRLF)
    EndIf

EndFunc   ;==>_Main
While True
    Switch GUIGetMsg()
        Case $GUI_EVENT_CLOSE
            ExitLoop

    EndSwitch
WEnd

 

Edited by jdelaney

IEbyXPATH-Grab IE DOM objects by XPATH IEscriptRecord-Makings of an IE script recorder ExcelFromXML-Create Excel docs without excel installed GetAllWindowControls-Output all control data on a given window.

Share this post


Link to post
Share on other sites

Well, the above works on the simple controls created by autoit, but not for my 3rd party app.

Is there a way to get the actual size of the button within the controlgetpos area?


IEbyXPATH-Grab IE DOM objects by XPATH IEscriptRecord-Makings of an IE script recorder ExcelFromXML-Create Excel docs without excel installed GetAllWindowControls-Output all control data on a given window.

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