• Announcements

Sign in to follow this  
Followers 0

GUICtrlGetStyle() - Get the Styles of a control.

7 posts in this topic

Posted (edited) · Report post

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

Share this post


Link to post
Share on other sites



Posted · Report post

This is very apreciated. Thank you for sharing.


Regards
Tip

Share this post


Link to post
Share on other sites

Posted · Report post

nice, good job

Share this post


Link to post
Share on other sites

Posted · Report post

nice, good job

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

Share this post


Link to post
Share on other sites

Posted · Report post

but unlike getwindowlong helps when you google ;)

Share this post


Link to post
Share on other sites

Posted · Report post

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

Share this post


Link to post
Share on other sites

Posted · Report post

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!

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