Jump to content

Button Text Color


Recommended Posts

Hi,

How comes my button changes when I set the text color?

See the difference:

$GUI = GUICreate("", 100, 100)
$Button = GUICtrlCreateButton("Test", 25, 20, 50, 25)
$Button2 = GUICtrlCreateButton("Test", 25, 50, 50, 25)

GUICtrlSetColor($Button, 0xFF00FF)

GUISetState()
While 1
    Switch GUIGetMsg()
        Case -3
            Exit
    EndSwitch
WEnd

Minesweeper

A minesweeper game created in autoit, source available.

_Mouse_UDF

An UDF for registering functions to mouse events, made in pure autoit.

2D Hitbox Editor

A 2D hitbox editor for quick creation of 2D sphere and rectangle hitboxes.

Link to comment
Share on other sites

The button text color changes, because you changed the button text color.

What did you expect? How does your button change?

:idea:

Valuater's AutoIt 1-2-3, Class... Is now in Session!For those who want somebody to write the script for them: RentACoder"Any technology distinguishable from magic is insufficiently advanced." -- Geek's corollary to Clarke's law
Link to comment
Share on other sites

And if you comment out the GUICtrlSetColor() it looks exactly the same, but with black text.

So what did you expect? What am I missing?

:idea:

Valuater's AutoIt 1-2-3, Class... Is now in Session!For those who want somebody to write the script for them: RentACoder"Any technology distinguishable from magic is insufficiently advanced." -- Geek's corollary to Clarke's law
Link to comment
Share on other sites

And if you comment out the GUICtrlSetColor() it looks exactly the same, but with black text.

So what did you expect? What am I missing?

:idea:

It makes the button look flat (2D).

Can you see the difference now?

Posted Image

Edited by AlmarM

Minesweeper

A minesweeper game created in autoit, source available.

_Mouse_UDF

An UDF for registering functions to mouse events, made in pure autoit.

2D Hitbox Editor

A 2D hitbox editor for quick creation of 2D sphere and rectangle hitboxes.

Link to comment
Share on other sites

Yeah, I see that now, but I don't know if/how you can fix it. I seem to recall that once you change something about the button, the style becomes BS_OWNERDRAW and none of the default Windows styles, like the 3D background image are applied any more.

You could create a 3D gradient and apply it yourself with GuiCtrlSetImage(), I guess.

There are smarter people here who might know a better way. (Edit: Like Yashied; see below!)

:idea:

Edited by PsaltyDS
Valuater's AutoIt 1-2-3, Class... Is now in Session!For those who want somebody to write the script for them: RentACoder"Any technology distinguishable from magic is insufficiently advanced." -- Geek's corollary to Clarke's law
Link to comment
Share on other sites

You could use transparent labels for the text.

Edit: Sorry, then there is no hover effect for the button. Posted Image

Edited by funkey

Programming today is a race between software engineers striving to
build bigger and better idiot-proof programs, and the Universe
trying to produce bigger and better idiots.
So far, the Universe is winning.

Link to comment
Share on other sites

Isnt their any wat to get those default buttons styles?

http://www.google.nl/#hl=nl&q=windows+vista+default+button+styles&meta=&aq=f&aqi=&aql=&oq=&gs_rfai=&fp=69c3d546787043f8

EDIT:

Default Style (I guess): 0x50010000 (Makes it 3D after GUICtrlSetColor() again, loses color though)

Flat Button Style: 0x5001000B

Anyway to combine Default style with color? :idea:

Edited by AlmarM

Minesweeper

A minesweeper game created in autoit, source available.

_Mouse_UDF

An UDF for registering functions to mouse events, made in pure autoit.

2D Hitbox Editor

A 2D hitbox editor for quick creation of 2D sphere and rectangle hitboxes.

Link to comment
Share on other sites

One way.

#Include <Constants.au3>
#Include <GUIConstantsEx.au3>
#Include <StaticConstants.au3>
#Include <WindowsConstants.au3>
#Include <WinAPI.au3>

Dim $Button[4]

$hForm = GUICreate('MyGUI', 350, 63)

$Button[0] = GUICtrlCreateButton('', 20, 20, 70, 23)
GUICtrlCreateLabel('Button1', 20, 20, 70, 23, BitOR($SS_CENTER, $SS_CENTERIMAGE))
GUICtrlSetBkColor(-1, $GUI_BKCOLOR_TRANSPARENT)
GUICtrlSetFont(-1, 11, -1, -1, 'Times')
GUICtrlSetColor(-1, 0xFF00FF)

$Button[1] = GUICtrlCreateButton('', 100, 20, 70, 23)
GUICtrlCreateLabel('Button2', 100, 20, 70, 23, BitOR($SS_CENTER, $SS_CENTERIMAGE))
GUICtrlSetBkColor(-1, $GUI_BKCOLOR_TRANSPARENT)
GUICtrlSetFont(-1, 11, -1, -1, 'Comic Sans MS')
GUICtrlSetColor(-1, 0xFF0000)

$Button[2] = GUICtrlCreateButton('', 180, 20, 70, 23)
GUICtrlCreateLabel('Button1', 180, 20, 70, 23, BitOR($SS_CENTER, $SS_CENTERIMAGE))
GUICtrlSetBkColor(-1, $GUI_BKCOLOR_TRANSPARENT)
GUICtrlSetFont(-1, 10, -1, 2)
GUICtrlSetColor(-1, 0x00FF00)

$Button[3] = GUICtrlCreateButton('', 260, 20, 70, 23)
GUICtrlCreateLabel('Button1', 260, 20, 70, 23, BitOR($SS_CENTER, $SS_CENTERIMAGE))
GUICtrlSetBkColor(-1, $GUI_BKCOLOR_TRANSPARENT)
GUICtrlSetFont(-1, -1, -1, 4)
GUICtrlSetColor(-1, 0x0000FF)

$hDll = DllCallbackRegister('_WinProc', 'ptr', 'hwnd;uint;wparam;lparam')
$pDll = DllCallbackGetPtr($hDll)
For $i = 0 To UBound($Button) - 1
    $hProc = _WinAPI_SetWindowLong(GUICtrlGetHandle($Button[$i]), $GWL_WNDPROC, $pDll)
Next

GUISetState()

While 1
    $Msg = GUIGetMsg()
    Switch $Msg
        Case -3
            ExitLoop
        Case $Button[0], $Button[1], $Button[2], $Button[3]
            MsgBox(0, 'Message', 'Button is pressed.', 0, $hForm)
    EndSwitch
WEnd

For $i = 0 To UBound($Button) - 1
    _WinAPI_SetWindowLong(GUICtrlGetHandle($Button[$i]), $GWL_WNDPROC, $hProc)
Next
DllCallbackFree($hDll)

Func _WinProc($hWnd, $iMsg, $wParam, $lParam)
    Switch $iMsg
        Case $WM_PAINT

            Local $tRECT = DllStructCreate($tagRECT)
            Local $Ret = DllCall('user32.dll', 'int', 'GetUpdateRect', 'hwnd', $hWnd, 'ptr', DllStructGetPtr($tRECT), 'int', 1)

            If $Ret[0] Then
                _WinAPI_InvalidateRect(GUICtrlGetHandle(_WinAPI_GetDlgCtrlID($hWnd) + 1), $tRECT)
            EndIf
    EndSwitch
    Return _WinAPI_CallWindowProc($hProc, $hWnd, $iMsg, $wParam, $lParam)
EndFunc   ;==>_WinProc
Link to comment
Share on other sites

One way.

#Include <Constants.au3>
#Include <GUIConstantsEx.au3>
#Include <StaticConstants.au3>
#Include <WindowsConstants.au3>
#Include <WinAPI.au3>

Dim $Button[4]

$hForm = GUICreate('MyGUI', 350, 63)

$Button[0] = GUICtrlCreateButton('', 20, 20, 70, 23)
GUICtrlCreateLabel('Button1', 20, 20, 70, 23, BitOR($SS_CENTER, $SS_CENTERIMAGE))
GUICtrlSetBkColor(-1, $GUI_BKCOLOR_TRANSPARENT)
GUICtrlSetFont(-1, 11, -1, -1, 'Times')
GUICtrlSetColor(-1, 0xFF00FF)

$Button[1] = GUICtrlCreateButton('', 100, 20, 70, 23)
GUICtrlCreateLabel('Button2', 100, 20, 70, 23, BitOR($SS_CENTER, $SS_CENTERIMAGE))
GUICtrlSetBkColor(-1, $GUI_BKCOLOR_TRANSPARENT)
GUICtrlSetFont(-1, 11, -1, -1, 'Comic Sans MS')
GUICtrlSetColor(-1, 0xFF0000)

$Button[2] = GUICtrlCreateButton('', 180, 20, 70, 23)
GUICtrlCreateLabel('Button1', 180, 20, 70, 23, BitOR($SS_CENTER, $SS_CENTERIMAGE))
GUICtrlSetBkColor(-1, $GUI_BKCOLOR_TRANSPARENT)
GUICtrlSetFont(-1, 10, -1, 2)
GUICtrlSetColor(-1, 0x00FF00)

$Button[3] = GUICtrlCreateButton('', 260, 20, 70, 23)
GUICtrlCreateLabel('Button1', 260, 20, 70, 23, BitOR($SS_CENTER, $SS_CENTERIMAGE))
GUICtrlSetBkColor(-1, $GUI_BKCOLOR_TRANSPARENT)
GUICtrlSetFont(-1, -1, -1, 4)
GUICtrlSetColor(-1, 0x0000FF)

$hDll = DllCallbackRegister('_WinProc', 'ptr', 'hwnd;uint;wparam;lparam')
$pDll = DllCallbackGetPtr($hDll)
For $i = 0 To UBound($Button) - 1
    $hProc = _WinAPI_SetWindowLong(GUICtrlGetHandle($Button[$i]), $GWL_WNDPROC, $pDll)
Next

GUISetState()

While 1
    $Msg = GUIGetMsg()
    Switch $Msg
        Case -3
            ExitLoop
        Case $Button[0], $Button[1], $Button[2], $Button[3]
            MsgBox(0, 'Message', 'Button is pressed.', 0, $hForm)
    EndSwitch
WEnd

For $i = 0 To UBound($Button) - 1
    _WinAPI_SetWindowLong(GUICtrlGetHandle($Button[$i]), $GWL_WNDPROC, $hProc)
Next
DllCallbackFree($hDll)

Func _WinProc($hWnd, $iMsg, $wParam, $lParam)
    Switch $iMsg
        Case $WM_PAINT

            Local $tRECT = DllStructCreate($tagRECT)
            Local $Ret = DllCall('user32.dll', 'int', 'GetUpdateRect', 'hwnd', $hWnd, 'ptr', DllStructGetPtr($tRECT), 'int', 1)

            If $Ret[0] Then
                _WinAPI_InvalidateRect(GUICtrlGetHandle(_WinAPI_GetDlgCtrlID($hWnd) + 1), $tRECT)
            EndIf
    EndSwitch
    Return _WinAPI_CallWindowProc($hProc, $hWnd, $iMsg, $wParam, $lParam)
EndFunc   ;==>_WinProc

Oh, thank you. :)

Still a pain in the ass to create this for all my buttons. :idea:

Edited by AlmarM

Minesweeper

A minesweeper game created in autoit, source available.

_Mouse_UDF

An UDF for registering functions to mouse events, made in pure autoit.

2D Hitbox Editor

A 2D hitbox editor for quick creation of 2D sphere and rectangle hitboxes.

Link to comment
Share on other sites

Another way.

#Include <GUIConstantsEx.au3>
#Include <GUIButton.au3>
#Include <GUIImageList.au3>
#Include <WinAPI.au3>
#Include <WindowsConstants.au3>

GUICreate('MyGUI', 200, 200)
GUICtrlCreateButton('', 65, 170, 70, 23)
_GUIButtonSetTextColor(-1, 'OK', 0xFF0000)
GUISetState()

Do
Until GUIGetMsg() = -3

Func _GUIButtonSetTextColor($iCtrlID, $sText, $iTextColor)

    Local $hWnd, $hTheme, $hImageList, $hBitmap, $hObj, $hDC, $hMemDC, $tRect, $pRect, $Data, $Width, $Height, $Prev = -1

    $hWnd = GUICtrlGetHandle($iCtrlID)
    If Not $hWnd Then
        Return 0
    EndIf
    $hTheme = DllCall('uxtheme.dll', 'ptr', 'OpenThemeData', 'hwnd', $hWnd, 'wstr', 'Button')
    If (@error) Or (Not $hTheme[0]) Then
        GUICtrlSetColor($iCtrlID, $iTextColor)
        GUICtrlSetData($iCtrlID, $sText)
        Return 1
    EndIf
    $hTheme = $hTheme[0]
    $Width = _WinAPI_GetClientWidth($hWnd)
    $Height = _WinAPI_GetClientHeight($hWnd)
    $hImageList = _GUIImageList_Create($Width - 8, $Height - 8, 4, 4)
    $hBitmap = _WinAPI_CreateBitmap($Width - 8, $Height - 8, 1, 32)
    $tRect = DllStructCreate('int[4]')
    DllStructSetData($tRect, 1, -4, 1)
    DllStructSetData($tRect, 1, -4, 2)
    DllStructSetData($tRect, 1, $Width - 4, 3)
    DllStructSetData($tRect, 1, $Height - 4, 4)
    $pRect = DllStructGetPtr($tRect)
    $hDC = _WinAPI_GetDC(0)
    $hMemDC = _WinAPI_CreateCompatibleDC($hDC)
    _WinAPI_ReleaseDC(0, $hDC)
    _WinAPI_SelectObject($hMemDC, _SendMessage($hWnd, $WM_GETFONT))
    _WinAPI_SetTextColor($hMemDC, BitOR(BitAND($iTextColor, 0x00FF00), BitShift(BitAND($iTextColor, 0x0000FF), -16), BitShift(BitAND($iTextColor, 0xFF0000), 16)))
    _WinAPI_SetBkMode($hMemDC, $TRANSPARENT)
    ; PBS_NORMAL
    $hObj = _WinAPI_SelectObject($hMemDC, $hBitmap)
    DllCall('uxtheme.dll', 'int', 'DrawThemeBackground', 'ptr', $hTheme, 'hwnd', $hMemDC, 'int', 1, 'int', 1, 'ptr', $pRect, 'ptr', 0)
    _WinAPI_DrawText($hMemDC, $sText, $tRect, BitOR($DT_CENTER, $DT_SINGLELINE, $DT_VCENTER))
    _WinAPI_SelectObject($hMemDC, $hObj)
    _GUIImageList_Add($hImageList, $hBitmap)
    ; PBS_HOT
    $hObj = _WinAPI_SelectObject($hMemDC, $hBitmap)
    DllCall('uxtheme.dll', 'int', 'DrawThemeBackground', 'ptr', $hTheme, 'hwnd', $hMemDC, 'int', 1, 'int', 2, 'ptr', $pRect, 'ptr', 0)
    _WinAPI_DrawText($hMemDC, $sText, $tRect, BitOR($DT_CENTER, $DT_SINGLELINE, $DT_VCENTER))
    _WinAPI_SelectObject($hMemDC, $hObj)
    _GUIImageList_Add($hImageList, $hBitmap)
    ; PBS_PRESSED
    $hObj = _WinAPI_SelectObject($hMemDC, $hBitmap)
    DllCall('uxtheme.dll', 'int', 'DrawThemeBackground', 'ptr', $hTheme, 'hwnd', $hMemDC, 'int', 1, 'int', 3, 'ptr', $pRect, 'ptr', 0)
    _WinAPI_DrawText($hMemDC, $sText, $tRect, BitOR($DT_CENTER, $DT_SINGLELINE, $DT_VCENTER))
    _WinAPI_SelectObject($hMemDC, $hObj)
    _GUIImageList_Add($hImageList, $hBitmap)
    ; PBS_DISABLED
    $hObj = _WinAPI_SelectObject($hMemDC, $hBitmap)
    DllCall('uxtheme.dll', 'int', 'DrawThemeBackground', 'ptr', $hTheme, 'hwnd', $hMemDC, 'int', 1, 'int', 4, 'ptr', $pRect, 'ptr', 0)
    $Data = DllCall('uxtheme.dll', 'int', 'GetThemeColor', 'ptr', $hTheme, 'int', 1, 'int', 4, 'int', 3803, 'dword*', 0)
    If (Not @error) And (Not $Data[0]) Then
        $Prev = _WinAPI_SetTextColor($hMemDC, $Data[5])
    EndIf
    _WinAPI_DrawText($hMemDC, $sText, $tRect, BitOR($DT_CENTER, $DT_SINGLELINE, $DT_VCENTER))
    If $Prev > -1 Then
        _WinAPI_SetTextColor($hMemDC, $Prev)
    EndIf
    _WinAPI_SelectObject($hMemDC, $hObj)
    _GUIImageList_Add($hImageList, $hBitmap)
    ; PBS_DEFAULTED
    $hObj = _WinAPI_SelectObject($hMemDC, $hBitmap)
    DllCall('uxtheme.dll', 'int', 'DrawThemeBackground', 'ptr', $hTheme, 'hwnd', $hMemDC, 'int', 1, 'int', 5, 'ptr', $pRect, 'ptr', 0)
    _WinAPI_DrawText($hMemDC, $sText, $tRect, BitOR($DT_CENTER, $DT_SINGLELINE, $DT_VCENTER))
    _WinAPI_SelectObject($hMemDC, $hObj)
    _GUIImageList_Add($hImageList, $hBitmap)
    _WinAPI_DeleteDC($hMemDC)
    _WinAPI_DeleteObject($hBitmap)
    DllCall('uxtheme.dll', 'int', 'CloseThemeData', 'ptr', $hTheme)
    $Data = _GUICtrlButton_GetImageList($hWnd)
    If $Data[0] Then
        _GUIImageList_Destroy($Data[0])
    EndIf
    GUICtrlSetData($iCtrlID, '')
    If Not _GUICtrlButton_SetImageList($hWnd, $hImageList, 4) Then
        _GUIImageList_Destroy($hImageList)
        Return 0
    EndIf
    Return 1
EndFunc   ;==>_GUIButtonSetTextColor
Edited by Yashied
Link to comment
Share on other sites

Another way.

#Include <GUIConstantsEx.au3>
#Include <GUIButton.au3>
#Include <GUIImageList.au3>
#Include <WinAPI.au3>
#Include <WindowsConstants.au3>

GUICreate('MyGUI', 200, 200)
GUICtrlCreateButton('', 65, 170, 70, 23)
_GUIButtonSetTextColor(-1, 'OK', 0xFF0000)
GUISetState()

Do
Until GUIGetMsg() = -3

Func _GUIButtonSetTextColor($iCtrlID, $sText, $iTextColor)

    Local $hWnd, $hTheme, $hImageList, $hBitmap, $hObj, $hDC, $hMemDC, $tRect, $pRect, $Data, $Width, $Height, $Prev = -1

    $hWnd = GUICtrlGetHandle($iCtrlID)
    If Not $hWnd Then
        Return 0
    EndIf
    $hTheme = DllCall('uxtheme.dll', 'ptr', 'OpenThemeData', 'hwnd', $hWnd, 'wstr', 'Button')
    If (@error) Or (Not $hTheme[0]) Then
        GUICtrlSetColor($iCtrlID, $iTextColor)
        GUICtrlSetData($iCtrlID, $sText)
        Return 1
    EndIf
    $hTheme = $hTheme[0]
    $Width = _WinAPI_GetClientWidth($hWnd)
    $Height = _WinAPI_GetClientHeight($hWnd)
    $hImageList = _GUIImageList_Create($Width - 8, $Height - 8, 4, 4)
    $hBitmap = _WinAPI_CreateBitmap($Width - 8, $Height - 8, 1, 32)
    $tRect = DllStructCreate('int[4]')
    DllStructSetData($tRect, 1, -4, 1)
    DllStructSetData($tRect, 1, -4, 2)
    DllStructSetData($tRect, 1, $Width - 4, 3)
    DllStructSetData($tRect, 1, $Height - 4, 4)
    $pRect = DllStructGetPtr($tRect)
    $hDC = _WinAPI_GetDC(0)
    $hMemDC = _WinAPI_CreateCompatibleDC($hDC)
    _WinAPI_ReleaseDC(0, $hDC)
    _WinAPI_SelectObject($hMemDC, _SendMessage($hWnd, $WM_GETFONT))
    _WinAPI_SetTextColor($hMemDC, BitOR(BitAND($iTextColor, 0x00FF00), BitShift(BitAND($iTextColor, 0x0000FF), -16), BitShift(BitAND($iTextColor, 0xFF0000), 16)))
    _WinAPI_SetBkMode($hMemDC, $TRANSPARENT)
    ; PBS_NORMAL
    $hObj = _WinAPI_SelectObject($hMemDC, $hBitmap)
    DllCall('uxtheme.dll', 'int', 'DrawThemeBackground', 'ptr', $hTheme, 'hwnd', $hMemDC, 'int', 1, 'int', 1, 'ptr', $pRect, 'ptr', 0)
    _WinAPI_DrawText($hMemDC, $sText, $tRect, BitOR($DT_CENTER, $DT_SINGLELINE, $DT_VCENTER))
    _WinAPI_SelectObject($hMemDC, $hObj)
    _GUIImageList_Add($hImageList, $hBitmap)
    ; PBS_HOT
    $hObj = _WinAPI_SelectObject($hMemDC, $hBitmap)
    DllCall('uxtheme.dll', 'int', 'DrawThemeBackground', 'ptr', $hTheme, 'hwnd', $hMemDC, 'int', 1, 'int', 2, 'ptr', $pRect, 'ptr', 0)
    _WinAPI_DrawText($hMemDC, $sText, $tRect, BitOR($DT_CENTER, $DT_SINGLELINE, $DT_VCENTER))
    _WinAPI_SelectObject($hMemDC, $hObj)
    _GUIImageList_Add($hImageList, $hBitmap)
    ; PBS_PRESSED
    $hObj = _WinAPI_SelectObject($hMemDC, $hBitmap)
    DllCall('uxtheme.dll', 'int', 'DrawThemeBackground', 'ptr', $hTheme, 'hwnd', $hMemDC, 'int', 1, 'int', 3, 'ptr', $pRect, 'ptr', 0)
    _WinAPI_DrawText($hMemDC, $sText, $tRect, BitOR($DT_CENTER, $DT_SINGLELINE, $DT_VCENTER))
    _WinAPI_SelectObject($hMemDC, $hObj)
    _GUIImageList_Add($hImageList, $hBitmap)
    ; PBS_DISABLED
    $hObj = _WinAPI_SelectObject($hMemDC, $hBitmap)
    DllCall('uxtheme.dll', 'int', 'DrawThemeBackground', 'ptr', $hTheme, 'hwnd', $hMemDC, 'int', 1, 'int', 4, 'ptr', $pRect, 'ptr', 0)
    $Data = DllCall('uxtheme.dll', 'int', 'GetThemeColor', 'ptr', $hTheme, 'int', 1, 'int', 4, 'int', 3803, 'dword*', 0)
    If (Not @error) And (Not $Data[0]) Then
        $Prev = _WinAPI_SetTextColor($hMemDC, $Data[5])
    EndIf
    _WinAPI_DrawText($hMemDC, $sText, $tRect, BitOR($DT_CENTER, $DT_SINGLELINE, $DT_VCENTER))
    If $Prev > -1 Then
        _WinAPI_SetTextColor($hMemDC, $Prev)
    EndIf
    _WinAPI_SelectObject($hMemDC, $hObj)
    _GUIImageList_Add($hImageList, $hBitmap)
    ; PBS_DEFAULTED
    $hObj = _WinAPI_SelectObject($hMemDC, $hBitmap)
    DllCall('uxtheme.dll', 'int', 'DrawThemeBackground', 'ptr', $hTheme, 'hwnd', $hMemDC, 'int', 1, 'int', 5, 'ptr', $pRect, 'ptr', 0)
    _WinAPI_DrawText($hMemDC, $sText, $tRect, BitOR($DT_CENTER, $DT_SINGLELINE, $DT_VCENTER))
    _WinAPI_SelectObject($hMemDC, $hObj)
    _GUIImageList_Add($hImageList, $hBitmap)
    _WinAPI_DeleteDC($hMemDC)
    _WinAPI_DeleteObject($hBitmap)
    DllCall('uxtheme.dll', 'int', 'CloseThemeData', 'ptr', $hTheme)
    $Data = _GUICtrlButton_GetImageList($hWnd)
    If $Data[0] Then
        _GUIImageList_Destroy($Data[0])
    EndIf
    GUICtrlSetData($iCtrlID, '')
    If Not _GUICtrlButton_SetImageList($hWnd, $hImageList, 4) Then
        _GUIImageList_Destroy($hImageList)
        Return 0
    EndIf
    Return 1
EndFunc   ;==>_GUIButtonSetTextColor

Nice, only my button color will always be white :idea:

Minesweeper

A minesweeper game created in autoit, source available.

_Mouse_UDF

An UDF for registering functions to mouse events, made in pure autoit.

2D Hitbox Editor

A 2D hitbox editor for quick creation of 2D sphere and rectangle hitboxes.

Link to comment
Share on other sites

Nice, only my button color will always be white :idea:

Fixed.

#Include <GUIButton.au3>
#Include <GUIImageList.au3>
#Include <WinAPI.au3>
#Include <WindowsConstants.au3>

GUICreate('MyGUI', 200, 200)
GUICtrlCreateButton('', 65, 170, 70, 23)
_GUICtrlButton_SetTextColor(-1, 'OK', 0xFF0000)
GUISetState()

Do
Until GUIGetMsg() = -3

Func _GUICtrlButton_SetTextColor($iCtrlID, $sText, $iTextColor)

    Local $hWnd, $hTheme, $hImageList, $hBitmap, $hBack, $hDC, $hMemDC, $hSrcDC, $tRect, $pRect, $Width, $Height, $Prev, $Flags = BitOR($DT_CENTER, $DT_SINGLELINE, $DT_VCENTER)

    $hWnd = GUICtrlGetHandle($iCtrlID)
    If Not $hWnd Then
        Return 0
    EndIf
    $hTheme = DllCall('uxtheme.dll', 'ptr', 'OpenThemeData', 'hwnd', $hWnd, 'wstr', 'BUTTON')
    If (@error) Or (Not $hTheme[0]) Then
        GUICtrlSetColor($iCtrlID, $iTextColor)
        GUICtrlSetData($iCtrlID, $sText)
        Return 1
    EndIf
    $Width = _WinAPI_GetClientWidth($hWnd)
    $Height = _WinAPI_GetClientHeight($hWnd)
    $hImageList = _GUIImageList_Create($Width - 8, $Height - 8, 4, 4)
    $tRect = DllStructCreate('int[4]')
    DllStructSetData($tRect, 1, -4, 1)
    DllStructSetData($tRect, 1, -4, 2)
    DllStructSetData($tRect, 1, $Width - 4, 3)
    DllStructSetData($tRect, 1, $Height - 4, 4)
    $pRect = DllStructGetPtr($tRect)
    $hDC = _WinAPI_GetDC(0)
    $hMemDC = _WinAPI_CreateCompatibleDC($hDC)
    $hSrcDC = _WinAPI_CreateCompatibleDC($hDC)
    $hBitmap = _WinAPI_CreateCompatibleBitmap($hDC, $Width - 8, $Height - 8)
    $hBack = _WinAPI_CreateCompatibleBitmap($hDC, $Width - 8, $Height - 8)
    _WinAPI_ReleaseDC(0, $hDC)
    _WinAPI_SelectObject($hSrcDC, $hBack)
    _WinAPI_SelectObject($hMemDC, _SendMessage($hWnd, $WM_GETFONT))
    _WinAPI_SetTextColor($hMemDC, BitOR(BitAND($iTextColor, 0x00FF00), BitShift(BitAND($iTextColor, 0x0000FF), -16), BitShift(BitAND($iTextColor, 0xFF0000), 16)))
    _WinAPI_SetBkMode($hMemDC, $TRANSPARENT)
    ; PBS_NORMAL, PBS_HOT, PBS_PRESSED, PBS_DISABLED, PBS_DEFAULTED
    For $i = 1 To 5
        $Prev = _WinAPI_SelectObject($hMemDC, $hBitmap)
        DllCall('uxtheme.dll', 'int', 'DrawThemeBackground', 'ptr', $hTheme[0], 'hwnd', $hSrcDC, 'int', 1, 'int', $i, 'ptr', $pRect, 'ptr', 0)
        _WinAPI_BitBlt($hMemDC, 0, 0, $Width - 8, $Height - 8, $hSrcDC, 0, 0, $MERGECOPY)
        If $i = 4 Then
            DllCall('uxtheme.dll', 'int', 'DrawThemeText', 'ptr', $hTheme[0], 'hwnd', $hMemDC, 'int', 1, 'int', 4, 'wstr', $sText, 'int', -1, 'dword', $Flags, 'dword', 0, 'ptr', $pRECT)
        Else
            _WinAPI_DrawText($hMemDC, $sText, $tRect, $Flags)
        EndIf
        _WinAPI_SelectObject($hMemDC, $Prev)
        _GUIImageList_Add($hImageList, $hBitmap)
    Next
    ; PBS_HOT (Stylus Hot)
    _GUIImageList_SetImageCount($hImageList, 6)
    _GUIImageList_Copy($hImageList, 1, 5)
    _WinAPI_DeleteDC($hMemDC)
    _WinAPI_DeleteDC($hSrcDC)
    _WinAPI_DeleteObject($hBitmap)
    _WinAPI_DeleteObject($hBack)
    DllCall('uxtheme.dll', 'int', 'CloseThemeData', 'ptr', $hTheme[0])
    $Prev = _GUICtrlButton_GetImageList($hWnd)
    If $Prev[0] Then
        _GUIImageList_Destroy($Prev[0])
    EndIf
    GUICtrlSetData($iCtrlID, '')
    If Not _GUICtrlButton_SetImageList($hWnd, $hImageList, 4) Then
        _GUIImageList_Destroy($hImageList)
        Return 0
    EndIf
    Return 1
EndFunc   ;==>_GUICtrlButton_SetTextColor
Edited by Yashied
Link to comment
Share on other sites

Wow, that's a lot of code for such a basic (seeming) function! I'm amazed there isn't a simpler API available for that.

:idea:

Valuater's AutoIt 1-2-3, Class... Is now in Session!For those who want somebody to write the script for them: RentACoder"Any technology distinguishable from magic is insufficiently advanced." -- Geek's corollary to Clarke's law
Link to comment
Share on other sites

Fixed.

#Include <GUIButton.au3>
#Include <GUIImageList.au3>
#Include <WinAPI.au3>
#Include <WindowsConstants.au3>

GUICreate('MyGUI', 200, 200)
GUICtrlCreateButton('', 65, 170, 70, 23)
_GUICtrlButton_SetTextColor(-1, 'OK', 0xFF0000)
GUISetState()

Do
Until GUIGetMsg() = -3

Func _GUICtrlButton_SetTextColor($iCtrlID, $sText, $iTextColor)

    Local $hWnd, $hTheme, $hImageList, $hBitmap, $hBack, $hObj, $hDC, $hMemDC, $hSrcDC, $tRect, $pRect, $Data, $Width, $Height, $Prev = -1

    $hWnd = GUICtrlGetHandle($iCtrlID)
    If Not $hWnd Then
        Return 0
    EndIf
    $hTheme = DllCall('uxtheme.dll', 'ptr', 'OpenThemeData', 'hwnd', $hWnd, 'wstr', 'Button')
    If (@error) Or (Not $hTheme[0]) Then
        GUICtrlSetColor($iCtrlID, $iTextColor)
        GUICtrlSetData($iCtrlID, $sText)
        Return 1
    EndIf
    $hTheme = $hTheme[0]
    $Width = _WinAPI_GetClientWidth($hWnd)
    $Height = _WinAPI_GetClientHeight($hWnd)
    $hImageList = _GUIImageList_Create($Width - 8, $Height - 8, 4, 4)
    $tRect = DllStructCreate('int[4]')
    DllStructSetData($tRect, 1, -4, 1)
    DllStructSetData($tRect, 1, -4, 2)
    DllStructSetData($tRect, 1, $Width - 4, 3)
    DllStructSetData($tRect, 1, $Height - 4, 4)
    $pRect = DllStructGetPtr($tRect)
    $hDC = _WinAPI_GetDC(0)
    $hMemDC = _WinAPI_CreateCompatibleDC($hDC)
    $hSrcDC = _WinAPI_CreateCompatibleDC($hDC)
    $hBitmap = _WinAPI_CreateCompatibleBitmap($hDC, $Width - 8, $Height - 8)
    $hBack = _WinAPI_CreateCompatibleBitmap($hDC, $Width - 8, $Height - 8)
    _WinAPI_ReleaseDC(0, $hDC)
    _WinAPI_SelectObject($hSrcDC, $hBack)
    _WinAPI_SelectObject($hMemDC, _SendMessage($hWnd, $WM_GETFONT))
    _WinAPI_SetTextColor($hMemDC, BitOR(BitAND($iTextColor, 0x00FF00), BitShift(BitAND($iTextColor, 0x0000FF), -16), BitShift(BitAND($iTextColor, 0xFF0000), 16)))
    _WinAPI_SetBkMode($hMemDC, $TRANSPARENT)
    ; PBS_NORMAL
    DllCall('uxtheme.dll', 'int', 'DrawThemeBackground', 'ptr', $hTheme, 'hwnd', $hSrcDC, 'int', 1, 'int', 1, 'ptr', $pRect, 'ptr', 0)
    $hObj = _WinAPI_SelectObject($hMemDC, $hBitmap)
    _WinAPI_BitBlt($hMemDC, 0, 0, $Width - 8, $Height - 8, $hSrcDC, 0, 0, $MERGECOPY)
    _WinAPI_DrawText($hMemDC, $sText, $tRect, BitOR($DT_CENTER, $DT_SINGLELINE, $DT_VCENTER))
    _WinAPI_SelectObject($hMemDC, $hObj)
    _GUIImageList_Add($hImageList, $hBitmap)
    ; PBS_HOT
    DllCall('uxtheme.dll', 'int', 'DrawThemeBackground', 'ptr', $hTheme, 'hwnd', $hSrcDC, 'int', 1, 'int', 2, 'ptr', $pRect, 'ptr', 0)
    $hObj = _WinAPI_SelectObject($hMemDC, $hBitmap)
    _WinAPI_BitBlt($hMemDC, 0, 0, $Width - 8, $Height - 8, $hSrcDC, 0, 0, $MERGECOPY)
    _WinAPI_DrawText($hMemDC, $sText, $tRect, BitOR($DT_CENTER, $DT_SINGLELINE, $DT_VCENTER))
    _WinAPI_SelectObject($hMemDC, $hObj)
    _GUIImageList_Add($hImageList, $hBitmap)
    ; PBS_PRESSED
    DllCall('uxtheme.dll', 'int', 'DrawThemeBackground', 'ptr', $hTheme, 'hwnd', $hSrcDC, 'int', 1, 'int', 3, 'ptr', $pRect, 'ptr', 0)
    $hObj = _WinAPI_SelectObject($hMemDC, $hBitmap)
    _WinAPI_BitBlt($hMemDC, 0, 0, $Width - 8, $Height - 8, $hSrcDC, 0, 0, $MERGECOPY)
    _WinAPI_DrawText($hMemDC, $sText, $tRect, BitOR($DT_CENTER, $DT_SINGLELINE, $DT_VCENTER))
    _WinAPI_SelectObject($hMemDC, $hObj)
    _GUIImageList_Add($hImageList, $hBitmap)
    ; PBS_DISABLED
    DllCall('uxtheme.dll', 'int', 'DrawThemeBackground', 'ptr', $hTheme, 'hwnd', $hSrcDC, 'int', 1, 'int', 4, 'ptr', $pRect, 'ptr', 0)
    $hObj = _WinAPI_SelectObject($hMemDC, $hBitmap)
    _WinAPI_BitBlt($hMemDC, 0, 0, $Width - 8, $Height - 8, $hSrcDC, 0, 0, $MERGECOPY)
    $Data = DllCall('uxtheme.dll', 'int', 'GetThemeColor', 'ptr', $hTheme, 'int', 1, 'int', 4, 'int', 3803, 'dword*', 0)
    If (Not @error) And (Not $Data[0]) Then
        $Prev = _WinAPI_SetTextColor($hMemDC, $Data[5])
    EndIf
    _WinAPI_DrawText($hMemDC, $sText, $tRect, BitOR($DT_CENTER, $DT_SINGLELINE, $DT_VCENTER))
    If $Prev > -1 Then
        _WinAPI_SetTextColor($hMemDC, $Prev)
    EndIf
    _WinAPI_SelectObject($hMemDC, $hObj)
    _GUIImageList_Add($hImageList, $hBitmap)
    ; PBS_DEFAULTED
    DllCall('uxtheme.dll', 'int', 'DrawThemeBackground', 'ptr', $hTheme, 'hwnd', $hSrcDC, 'int', 1, 'int', 5, 'ptr', $pRect, 'ptr', 0)
    $hObj = _WinAPI_SelectObject($hMemDC, $hBitmap)
    _WinAPI_BitBlt($hMemDC, 0, 0, $Width - 8, $Height - 8, $hSrcDC, 0, 0, $MERGECOPY)
    _WinAPI_DrawText($hMemDC, $sText, $tRect, BitOR($DT_CENTER, $DT_SINGLELINE, $DT_VCENTER))
    _WinAPI_SelectObject($hMemDC, $hObj)
    _GUIImageList_Add($hImageList, $hBitmap)
    ; PBS_HOT (Stylus Hot)
    _GUIImageList_SetImageCount($hImageList, 6)
    _GUIImageList_Copy($hImageList, 1, 5)
    _WinAPI_DeleteDC($hMemDC)
    _WinAPI_DeleteDC($hSrcDC)
    _WinAPI_DeleteObject($hBitmap)
    _WinAPI_DeleteObject($hBack)
    DllCall('uxtheme.dll', 'int', 'CloseThemeData', 'ptr', $hTheme)
    $Data = _GUICtrlButton_GetImageList($hWnd)
    If $Data[0] Then
        _GUIImageList_Destroy($Data[0])
    EndIf
    GUICtrlSetData($iCtrlID, '')
    If Not _GUICtrlButton_SetImageList($hWnd, $hImageList, 4) Then
        _GUIImageList_Destroy($hImageList)
        Return 0
    EndIf
    Return 1
EndFunc   ;==>_GUICtrlButton_SetTextColor

Thank you. :idea:

Minesweeper

A minesweeper game created in autoit, source available.

_Mouse_UDF

An UDF for registering functions to mouse events, made in pure autoit.

2D Hitbox Editor

A 2D hitbox editor for quick creation of 2D sphere and rectangle hitboxes.

Link to comment
Share on other sites

  • 7 years later...

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