Jump to content

Recommended Posts

Posted (edited)

If you set the styles of a control with GUICtrlSetStyle() and happen to forget the styles you set, then why not try GUICtrlGetStyle()

To get the Hex value e.g. 00100000 then use this little conversion >>

Local $aArray = GUICtrlGetStyle($iLabel)
_GUICtrlGetStyle_Convert($aArray)
_ArrayDisplay($aArray, 'The Style = 0101 & the ExStyle = 00100000'))
Function:

#include-once
#include <WinAPI.au3>

; #FUNCTION# ====================================================================================================================
; Name ..........: GUICtrlGetStyle
; Description ...: Retrieves the Styles/ExStyles value(s) of a control.
; Syntax ........: GUICtrlGetStyle($hWnd)
; Parameters ....: $hWnd                - Control ID/Handle to the control
; Return values .: $aArray[2] = [Style, ExStyle]
; Author ........: guinness
; Example .......: Yes
; ===============================================================================================================================
Func GUICtrlGetStyle($hWnd)
    If Not IsHWnd($hWnd) Then
        $hWnd = GUICtrlGetHandle($hWnd)
    EndIf
    Local $aReturn = [_WinAPI_GetWindowLong($hWnd, $GWL_STYLE), _WinAPI_GetWindowLong($hWnd, $GWL_EXSTYLE)]
    Return $aReturn
EndFunc   ;==>GUICtrlGetStyle
Example use of Function:

#include <Array.au3> ; Required only for _ArrayDisplay(), but not the UDF!
#include <GUIConstantsEx.au3>

#include 'GUICtrlGetStyle.au3'

Example()

Func Example()
    Local $hGUI = GUICreate('GUICtrlGetStyle() Example', 280, 90)

    ; This label is using 'magic numbers' instead of the constant variables. It's advisable to use $SS_CENTER & $GUI_WS_EX_PARENTDRAG
    ; instead of 0x0101 & 0x00100000, but this has been done for proof of concept only. See the second _Array display for more details.
    Local $iLabel = GUICtrlCreateLabel('This is a Label with $SS_CENTER & $GUI_WS_EX_PARENTDRAG set as the Styles.', 10, 10, 270, 45, 0x0101, 0x00100000) ; $SS_CENTER, $GUI_WS_EX_PARENTDRAG
    Local $iButton = GUICtrlCreateButton('GetStyle Array', 95, 55, 85, 25)
    GUISetState(@SW_SHOW, $hGUI)

    Local $aArray = 0
    While 1
        Switch GUIGetMsg()
            Case $GUI_EVENT_CLOSE
                ExitLoop

            Case $iButton
                $aArray = GUICtrlGetStyle($iLabel)
                _ArrayDisplay($aArray)
                GUICtrlDelete($iLabel)
                GUICtrlCreateLabel('This is a NEW Label with $SS_CENTER & $GUI_WS_EX_PARENTDRAG set as the Styles/ExStyles.', 10, 10, 270, 50, $aArray[0], $aArray[1])

                ; This is the reason why 'magic numbers' were used, so as to see they match the same values in GUICtrlCreateLabel.
                $aArray = GUICtrlGetStyle($iLabel)
                _GUICtrlGetStyle_Convert($aArray)
                _ArrayDisplay($aArray, 'The Style = 0x0101 & the ExStyle = 0x00100000')

        EndSwitch
    WEnd

    GUIDelete($hGUI)
EndFunc   ;==>Example

Func _GUICtrlGetStyle_Convert(ByRef $aArray)
    If UBound($aArray) = 2 Then
        $aArray[0] = '0x' & Hex($aArray[0], 4)
        $aArray[1] = '0x' & Hex($aArray[1], 8)
    EndIf
EndFunc   ;==>_GUICtrlGetStyle_Convert
Edited by guinness

UDF List:

  Reveal hidden contents

Updated: 22/04/2018

  • 3 months later...
  • 10 months later...
Posted

  On 4/6/2012 at 10:54 PM, 'Aktonius said:

nice, good job

Thanks. It's just a wrapper function for _WinAPI_GetWindowLong.

UDF List:

  Reveal hidden contents

Updated: 22/04/2018

  • 6 months later...
Posted

I've updated the example and function syntax. See above for more details. Thanks.

UDF List:

  Reveal hidden contents

Updated: 22/04/2018

  • 1 year later...
Posted

Again, just under a year and thought why not give this a little dusting off. Funnily enough I tried to use GUIGetStyle() but converting the controlid to a handle and then passing to that function, but alas it didn't work. I should have stuck to using this function methinks!

UDF List:

  Reveal hidden contents

Updated: 22/04/2018

  • 4 years later...
Posted
#include 'GUICtrlGetBkColor.au3'


$mainwindow = GUICreate("# WINDOW #", 200, 200)                                             
$test = GUICtrlCreateButton("TEST", 40, 34, 90, 90)
GUICtrlSetBkColor($test, 0xf2f2f2)
GUISetState(@SW_SHOW)

$iColor = GUICtrlGetBkColor($test)
MsgBox(0,"",$iColor)

@guinness $iColor returns 0 to me, what im doing wrong? Im looking for the value in GuiCtrlSetBkColor "0xf2f2f2"

Posted

You're posting to the wrong thread:

and that function works fine for me:

#include <WinAPIGdi.au3>

$mainwindow = GUICreate("# WINDOW #", 200, 200)
$test = GUICtrlCreateButton("TEST", 40, 34, 90, 90)
GUICtrlSetBkColor($test, 0xf2f2f2)
GUISetState(@SW_SHOW)

$iColor = GUICtrlGetBkColor($test)
MsgBox(0,"",$iColor & @crlf & "0x" & Hex($iColor, 6))

; #FUNCTION# ====================================================================================================================
; Name ..........: GUICtrlGetBkColor
; Description ...: Retrieves the RGB value of the control background.
; Syntax ........: GUICtrlGetBkColor($hWnd)
; Parameters ....: $hWnd                - Control ID/Handle to the control
; Return values .: Success - RGB value
;                  Failure - 0
; Author ........: guinness
; Example .......: Yes
; ===============================================================================================================================

Func GUICtrlGetBkColor($hWnd)
    If Not IsHWnd($hWnd) Then
        $hWnd = GUICtrlGetHandle($hWnd)
    EndIf
    Local $hDC = _WinAPI_GetDC($hWnd)
    Local $iColor = _WinAPI_GetPixel($hDC, 0, 0)
    _WinAPI_ReleaseDC($hWnd, $hDC)
    Return $iColor
EndFunc   ;==>GUICtrlGetBkColor

 

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...