Sign in to follow this  
Followers 0

GUIGetBkColor() - Get the background color of the GUI.

8 posts in this topic

Posted (edited)

If you set the GUI background colour with GUISetBkColor() and happen to forget the colour you set it as, then why not try GUIGetBkColor()

Function:

#include-once
#include <WinAPIGdi.au3>

; #FUNCTION# ====================================================================================================================
; Name ..........: GUIGetBkColor
; Description ...: Retrieves the RGB value of the GUI background.
; Syntax ........: GUIGetBkColor($hWnd)
; Parameters ....: $hWnd                - A handle of the GUI.
; Return values .: Success - RGB value
;                  Failure - 0
; Author ........: guinness
; Example .......: Yes
; ===============================================================================================================================
Func GUIGetBkColor($hWnd)
	Local $iColor = 0
	If IsHWnd($hWnd) Then
		Local $hDC = _WinAPI_GetDC($hWnd)
		$iColor = _WinAPI_GetBkColor($hDC)
		_WinAPI_ReleaseDC($hWnd, $hDC)
	EndIf
	Return $iColor
EndFunc   ;==>GUIGetBkColor
Example use of Function:

#include <MsgBoxConstants.au3>

#include 'GUIGetBkColor.au3'

Example()

Func Example()
	Local $hGUI = GUICreate('GUIGetBkColor() Example', 500, 350)
	GUISetState(@SW_SHOW, $hGUI)

	Local $aColor = [0x0000FF, 0x8FFF9F, 0xEC4841, 0xB0E35D, 0x440BFD] ; Random colour array.
	Local $iColor = 0
	For $i = 0 To UBound($aColor) - 1
		GUISetBkColor($aColor[$i])
		Sleep(20)
		$iColor = GUIGetBkColor($hGUI) ; Pass the GUI handle to the function.
		MsgBox($MB_SYSTEMMODAL, '', 'Background Color: ' & _ConvertToHexFormat($aColor[$i]) & @CRLF & _
				'GUIGetBkColor() Hex Format: ' & _ConvertToHexFormat($iColor) & @CRLF & _
				'GUIGetBkColor() Returned: ' & $iColor, 0, $hGUI)
	Next

	GUIDelete($hGUI)
EndFunc   ;==>Example

Func _ConvertToHexFormat($iColor)
	Return Hex($iColor, 6)
EndFunc   ;==>_ConvertToHexFormat
Edited by guinness
Luigi likes this

Share this post


Link to post
Share on other sites



Posted

Updated the Original Post with small changes.

Share this post


Link to post
Share on other sites

Posted

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

Just under two years ago since I last updated this function, so now is a good time to tidy the syntax. I removed the 4096 MsgBox() value and went for the approach of a single exit point.

Share this post


Link to post
Share on other sites

Posted

I removed the 4096 MsgBox() value and went for the approach of a single exit point.

Why you always try to get us to use your scripts in this way?

It would be much easier to have the number 4096 out instead to include a file with definitions.

The same happens with the ternary, noting that many people still using older versions of AutoIt simply by meeting the needs.

But okay, everyone writes the way you want, do not misunderstand me.


Would not it be preferable to have all the topics below in only one? Since all appear to be co-related

fKCUS5S.png

Thanks for the updates,

JS

Share this post


Link to post
Share on other sites

Posted (edited)

The answer is because I enjoy writing clean and easy to understand code, plus I enjoy using the new features of AutoIt.

I am not worried about the users who use an old version of AutoIt, because you seriously believe people actually use the code I post? Come on JScript, be realistic buddy! 0_-

Edit: Post 16,666.

Edited by guinness

Share this post


Link to post
Share on other sites

Posted

The answer is because I enjoy writing clean and easy to understand code, plus I enjoy using the new features of AutoIt.

Yes, thinking at it this way is even better!

I am not worried about the users who use an old version of AutoIt

Ok, but I think you should it matter. It's just a opnion...

because you seriously believe people actually use the code I post? Come on JScript, be realistic buddy! 0_-

Yes, why not? I use your scripts whenever I need, they are all well structured and quite helpful.

JS

Share this post


Link to post
Share on other sites

Posted

I have taken your comments on board.

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