Jump to content

Win10 - Default Button background color


KaFu
 Share

Recommended Posts

Hiho Forum :),

for Win7 and Win8 _WinAPI_GetSysColor(15) seems to return the correct result for the default background color of a button. It seems this is not true for Win10 :(... can somebody with Win10 run the following sample code and post the console output? Much appreciated!

Regards

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

Global $__Var[9] = [0, 0, 0, 0, 16385, 8388608, 1, 0, 0]

For $i = 1 To 30
    ConsoleWrite($i & @TAB & _WinAPI_GetSysColor($i) & @CRLF)
Next

GUICreate("My GUI")
$c_Button = GUICtrlCreateButton("Test", 10, 10, 100, 30)
GUISetState(@SW_SHOW)

ConsoleWrite(@CRLF & GUICtrlGetBkColor(GUICtrlGetHandle($c_Button)) & @CRLF)

While 1
    $msg = GUIGetMsg()
    If $msg = $GUI_EVENT_CLOSE Then ExitLoop
WEnd
GUIDelete()


; #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_Ex($hDC, 0, 0)
    _WinAPI_ReleaseDC($hWnd, $hDC)
    Return $iColor
EndFunc   ;==>GUICtrlGetBkColor

Func _WinAPI_GetPixel_Ex($hDC, $iX, $iY)

    Local $Ret = DllCall('gdi32.dll', 'dword', 'GetPixel', 'hwnd', $hDC, 'int', $iX, 'int', $iY)

    If (@error) Or ($Ret[0] = 4294967295) Then
        Return SetError(1, 0, -1)
    EndIf
    Return __RGB_Ex($Ret[0])
EndFunc   ;==>_WinAPI_GetPixel_Ex

Func __RGB_Ex($iColor)
    If $__Var[6] Then
        $iColor = _WinAPI_SwitchColor_Ex($iColor)
    EndIf
    Return $iColor
EndFunc   ;==>__RGB_Ex

Func _WinAPI_SwitchColor_Ex($iColor)
    Return BitOR(BitAND($iColor, 0x00FF00), BitShift(BitAND($iColor, 0x0000FF), -16), BitShift(BitAND($iColor, 0xFF0000), 16))
EndFunc   ;==>_WinAPI_SwitchColor_Ex

 

Link to comment
Share on other sites

  • Moderators

Here you go @KaFu

--> Press Ctrl+Alt+Break to Restart or Ctrl+Break to Stop
1   0
2   13743257
3   14405055
4   15790320
5   16777215
6   6579300
7   0
8   0
9   0
10  11842740
11  16578548
12  11250603
13  16750899
14  16777215
15  15790320
16  10526880
17  7171437
18  0
19  0
20  16777215
21  6908265
22  14935011
23  0
24  14811135
25  0
26  13395456
27  15389113
28  15918295
29  16750899
30  15790320

15790320
+>10:32:28 AutoIt3.exe ended.rc:0

 

"Profanity is the last vestige of the feeble mind. For the man who cannot express himself forcibly through intellect must do so through shock and awe" - Spencer W. Kimball

How to get your question answered on this forum!

Link to comment
Share on other sites

Link to comment
Share on other sites

Could anybody with Win10 re-run this and post the console output?

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

Global $__Var[9] = [0, 0, 0, 0, 16385, 8388608, 1, 0, 0]

For $i = 1 To 30
    ConsoleWrite($i & @TAB & _WinAPI_GetSysColor($i) & @CRLF)
Next

GUICreate("My GUI")
$c_Button = GUICtrlCreateButton("Test", 10, 10, 100, 30)
GUISetState(@SW_SHOW)

ConsoleWrite(@CRLF)

for $i = 0 to 10
    ConsoleWrite($i & @tab & GUICtrlGetBkColorEx(GUICtrlGetHandle($c_Button),$i,$i) & @CRLF)
Next

While 1
    $msg = GUIGetMsg()
    If $msg = $GUI_EVENT_CLOSE Then ExitLoop
WEnd
GUIDelete()


; #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 GUICtrlGetBkColorEx($hWnd,$x,$y)
    If Not IsHWnd($hWnd) Then
        $hWnd = GUICtrlGetHandle($hWnd)
    EndIf
    Local $hDC = _WinAPI_GetDC($hWnd)
    Local $iColor = _WinAPI_GetPixel_Ex($hDC, $x, $y)
    _WinAPI_ReleaseDC($hWnd, $hDC)
    Return $iColor
EndFunc   ;==>GUICtrlGetBkColor

Func _WinAPI_GetPixel_Ex($hDC, $iX, $iY)

    Local $Ret = DllCall('gdi32.dll', 'dword', 'GetPixel', 'hwnd', $hDC, 'int', $iX, 'int', $iY)

    If (@error) Or ($Ret[0] = 4294967295) Then
        Return SetError(1, 0, -1)
    EndIf
    Return __RGB_Ex($Ret[0])
EndFunc   ;==>_WinAPI_GetPixel_Ex

Func __RGB_Ex($iColor)
    If $__Var[6] Then
        $iColor = _WinAPI_SwitchColor_Ex($iColor)
    EndIf
    Return $iColor
EndFunc   ;==>__RGB_Ex

Func _WinAPI_SwitchColor_Ex($iColor)
    Return BitOR(BitAND($iColor, 0x00FF00), BitShift(BitAND($iColor, 0x0000FF), -16), BitShift(BitAND($iColor, 0xFF0000), 16))
EndFunc   ;==>_WinAPI_SwitchColor_Ex

 

Link to comment
Share on other sites

Windows 10 x86 Pro
1    0
2    13743257
3    14405055
4    15790320
5    16777215
6    6579300
7    0
8    0
9    0
10    11842740
11    16578548
12    11250603
13    16750899
14    16777215
15    15790320
16    10526880
17    7171437
18    0
19    0
20    16777215
21    6908265
22    14935011
23    0
24    14811135
25    0
26    13395456
27    15389113
28    15918295
29    16750899
30    15790320

0    15790320
1    11382189
2    14803425
3    14803425
4    14803425
5    14803425
6    14803425
7    14803425
8    14803425
9    14803425
10    14803425
>Exit code: 0    Time: 12.48

Regards,
 

Link to comment
Share on other sites

Hello. Here is my output. W10 x86

1   0
2   13743257
3   14405055
4   15790320
5   16777215
6   6579300
7   0
8   0
9   0
10  11842740
11  16578548
12  11250603
13  16750899
14  16777215
15  15790320
16  10526880
17  7171437
18  0
19  0
20  16777215
21  6908265
22  14935011
23  0
24  14811135
25  0
26  13395456
27  15389113
28  15918295
29  16750899
30  15790320

0   15790320
1   11382189
2   14803425
3   14803425
4   14803425
5   14803425
6   14803425
7   14803425
8   14803425
9   14803425
10  14803425

Saludos

 

Link to comment
Share on other sites

So the border is still = _WinAPI_GetSysColor(15) = 15790320 ($i = 0), but the center is 14803425, damned themed buttons, have to think how to "reproduce" this...

Thanks a lot for testing!

Link to comment
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
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...