Jump to content

Hexadecimal/Decimal Color Converter


Paulie
 Share

Recommended Posts

With this tool, you move the sliders back and forth and it blends the colors and gives you the both Hex and Decimal values

based off this website

http://www.mathsisfun.com/hexadecimal-decimal-colors.html

#include <GuiConstants.au3>

; == GUI generated with Koda == Thank GOD for Koda!!
$Decimal = GUICreate("Decimal and Hexadecimal Colors", 592, 299, 414, 191, -1, $WS_EX_TOOLWINDOW)
GUISetBkColor(0xD4D0C8)
$RedSlider = GUICtrlCreateSlider(75, 35, 255, 35, BitOR($TBS_BOTH,$TBS_NOTICKS), $WS_EX_CLIENTEDGE)
$GreenSlider = GUICtrlCreateSlider(75, 90, 255, 35, BitOR($TBS_BOTH,$TBS_NOTICKS), $WS_EX_CLIENTEDGE)
$BlueSlider = GUICtrlCreateSlider(75, 145, 255, 35, BitOR($TBS_BOTH,$TBS_NOTICKS), $WS_EX_CLIENTEDGE)
GUICtrlSetLimit($RedSlider,255, 0)
GUICtrlSetLimit($GreenSlider,255, 0)
GUICtrlSetLimit($BlueSlider,255, 0)
GUICtrlCreateLabel("Red:", 10, 35, 40, 22)
GUICtrlSetFont(-1, 10, 800, 0, "Arial Black")
GUICtrlSetColor(-1, 0xFF0000)
GUICtrlSetBkColor(-1, 0xD4D0C8)
GUICtrlCreateLabel("Green:", 10, 90, 58, 22)
GUICtrlSetFont(-1, 10, 800, 0, "Arial Black")
GUICtrlSetColor(-1, 0x008000)
GUICtrlSetBkColor(-1, 0xD4D0C8)
GUICtrlCreateLabel("Blue:", 10, 145, 45, 22)
GUICtrlSetFont(-1, 10, 800, 0, "Arial Black")
GUICtrlSetColor(-1, 0x0000FF)
GUICtrlSetBkColor(-1, 0xD4D0C8)
$Display = GUICtrlCreateLabel("", 370, 23, 200, 230, BitOR($SS_SUNKEN,$WS_BORDER), $WS_EX_CLIENTEDGE)
GUICtrlSetBkColor(-1, 0x000000)
$HexInput = GUICtrlCreateInput("000000", 215, 195, 135, 24, $ES_CENTER, $WS_EX_CLIENTEDGE)
GUICtrlSetFont(-1, 10, 800, 0, "MS Sans Serif")
GUICtrlSetColor(-1, 0x000080)
$DecInput = GUICtrlCreateInput("000000", 215, 235, 135, 24, BitOR($ES_CENTER,$ES_NUMBER), $WS_EX_CLIENTEDGE)
GUICtrlSetFont(-1, 10, 800, 0, "MS Sans Serif")
GUICtrlSetColor(-1, 0x000080)
$RedCount = GUICtrlCreateLabel("Red: 0 = 00", 15, 195, 130, 20)
GUICtrlSetFont(-1, 10, 400, 0, "MS Sans Serif")
GUICtrlSetColor(-1, 0xFF0000)
GUICtrlSetBkColor(-1, 0xD4D0C8)
$GreenCount = GUICtrlCreateLabel("Green: 0 = 00", 15, 225, 140, 20)
GUICtrlSetFont(-1, 10, 400, 0, "MS Sans Serif")
GUICtrlSetColor(-1, 0x008000)
GUICtrlSetBkColor(-1, 0xD4D0C8)
$BlueCount = GUICtrlCreateLabel("Blue: 0 = 00", 15, 255, 130, 20)
GUICtrlSetFont(-1, 10, 400, 0, "MS Sans Serif")
GUICtrlSetColor(-1, 0x0000FF)
GUICtrlSetBkColor(-1, 0xD4D0C8)
GUICtrlCreateLabel("HEX:", 155, 195, 50, 27)
GUICtrlSetFont(-1, 12, 800, 0, "Arial Black")
GUICtrlSetBkColor(-1, 0xD4D0C8)
GUICtrlCreateLabel("DEC:", 155, 235, 49, 27)
GUICtrlSetFont(-1, 12, 800, 0, "Arial Black")
GUICtrlSetBkColor(-1, 0xD4D0C8)
GUISetState(@SW_SHOW)

While 1
    $msg = GuiGetMsg()
    Select
    Case $msg = $GUI_EVENT_CLOSE
        ExitLoop
    EndSelect
    $CurrentRed = GUICtrlRead($RedSlider)
    GuiCtrlSetData($RedCount, "Red: "&$CurrentRed&" = "&StringTrimLeft(Hex($CurrentRed),6))
    $CurrentGreen = GUICtrlRead($GreenSlider)
    GuiCtrlSetData($GreenCount, "Green: "&$CurrentGreen&" = "&StringTrimLeft(Hex($CurrentGreen),6))
    $CurrentBlue = GUICtrlRead($BlueSlider)
    GuiCtrlSetData($BlueCount, "Blue: "&$CurrentBlue&" = "&StringTrimLeft(Hex($CurrentBlue),6))
    $OutHex = StringTrimLeft(Hex($CurrentRed),6)&StringTrimLeft(Hex($CurrentGreen),6)&StringTrimLeft(Hex($CurrentBlue),6)
    $OutDec = Dec($OutHex)
    GuiCtrlSetData($HexInput, $OutHex)
    GuiCtrlSetData($DecInput, $OutDec)
    GUICtrlSetBkColor($Display, "0x"&$OutHex)
WEnd
Exit

One problem is that I want the inputs to be able to be edited, so you can enter a hex or dec value ant it will display the color, is this possible since they are constantly being edited? or will i need more inputs?

Edited by Paulie
Link to comment
Share on other sites

One problem is that I want the inputs to be able to be edited, so you can enter a hex or dec value ant it will display the color, is this possible since they are constantly being edited? or will i need more inputs?

You can use GUIRegisterMsg() and react only on change value of sliders/edit boxes

instead of your concept when you constantly update edit inputs from slider values.

Then will be possible also manually edit values in edit boxes.

Try to search on forum for examples about GUIRegisterMsg() ...

Edited by Zedna
Link to comment
Share on other sites

You can use GUIRegisterMsg() and react only on change value of sliders/edit boxes

instead of your concept when you constantly update edit inputs from slider values.

Then will be possible also manually edit values in edit boxes.

Try to search on forum for examples about GUIRegisterMsg() ...

I found it in the helpfile, but it makes NO sense to me at all

how am i supposed to know which 'windows message code'

what if I don't have 4 parameters to make into a function?

i'm confused :P

And the example's not much help as it does more then the code i'm trying to make, my code could be It's example

@gafrost-

just wanted to copy that website more, it was more for learning then functionality

Edited by Paulie
Link to comment
Share on other sites

I found it in the helpfile, but it makes NO sense to me at all

how am i supposed to know which 'windows message code'

what if I don't have 4 parameters to make into a function?

i'm confused :P

That's why I said: search in forum for examples :nuke:

there are lots of nice educational scripts.

And also www.msdn.com will help you.

Link to comment
Share on other sites

somthing for you to play around with

#include <GuiConstants.au3>

Global Const $DebugIt = 1
Global Const $WM_COMMAND = 0x0111
Global Const $EN_CHANGE = 0x300

; == GUI generated with Koda == Thank GOD for Koda!!
$Decimal = GUICreate("Decimal and Hexadecimal Colors", 592, 299, 414, 191, -1, $WS_EX_TOOLWINDOW)
GUISetBkColor(0xD4D0C8)
$RedSlider = GUICtrlCreateSlider(75, 35, 255, 35, BitOR($TBS_BOTH, $TBS_NOTICKS), $WS_EX_CLIENTEDGE)
$GreenSlider = GUICtrlCreateSlider(75, 90, 255, 35, BitOR($TBS_BOTH, $TBS_NOTICKS), $WS_EX_CLIENTEDGE)
$BlueSlider = GUICtrlCreateSlider(75, 145, 255, 35, BitOR($TBS_BOTH, $TBS_NOTICKS), $WS_EX_CLIENTEDGE)
GUICtrlSetLimit($RedSlider, 255, 0)
GUICtrlSetLimit($GreenSlider, 255, 0)
GUICtrlSetLimit($BlueSlider, 255, 0)
GUICtrlCreateLabel("Red:", 10, 35, 40, 22)
GUICtrlSetFont(-1, 10, 800, 0, "Arial Black")
GUICtrlSetColor(-1, 0xFF0000)
GUICtrlSetBkColor(-1, 0xD4D0C8)
GUICtrlCreateLabel("Green:", 10, 90, 58, 22)
GUICtrlSetFont(-1, 10, 800, 0, "Arial Black")
GUICtrlSetColor(-1, 0x008000)
GUICtrlSetBkColor(-1, 0xD4D0C8)
GUICtrlCreateLabel("Blue:", 10, 145, 45, 22)
GUICtrlSetFont(-1, 10, 800, 0, "Arial Black")
GUICtrlSetColor(-1, 0x0000FF)
GUICtrlSetBkColor(-1, 0xD4D0C8)
$Display = GUICtrlCreateLabel("", 370, 23, 200, 230, BitOR($SS_SUNKEN, $WS_BORDER), $WS_EX_CLIENTEDGE)
GUICtrlSetBkColor(-1, 0x000000)
$HexInput = GUICtrlCreateInput("000000", 215, 195, 135, 24, $ES_CENTER, $WS_EX_CLIENTEDGE)
GUICtrlSetFont(-1, 10, 800, 0, "MS Sans Serif")
GUICtrlSetColor(-1, 0x000080)
$DecInput = GUICtrlCreateInput("000000", 215, 235, 135, 24, BitOR($ES_CENTER, $ES_NUMBER), $WS_EX_CLIENTEDGE)
GUICtrlSetFont(-1, 10, 800, 0, "MS Sans Serif")
GUICtrlSetColor(-1, 0x000080)
$RedCount = GUICtrlCreateLabel("Red: 0 = 00", 15, 195, 130, 20)
GUICtrlSetFont(-1, 10, 400, 0, "MS Sans Serif")
GUICtrlSetColor(-1, 0xFF0000)
GUICtrlSetBkColor(-1, 0xD4D0C8)
$GreenCount = GUICtrlCreateLabel("Green: 0 = 00", 15, 225, 140, 20)
GUICtrlSetFont(-1, 10, 400, 0, "MS Sans Serif")
GUICtrlSetColor(-1, 0x008000)
GUICtrlSetBkColor(-1, 0xD4D0C8)
$BlueCount = GUICtrlCreateLabel("Blue: 0 = 00", 15, 255, 130, 20)
GUICtrlSetFont(-1, 10, 400, 0, "MS Sans Serif")
GUICtrlSetColor(-1, 0x0000FF)
GUICtrlSetBkColor(-1, 0xD4D0C8)
GUICtrlCreateLabel("HEX:", 155, 195, 50, 27)
GUICtrlSetFont(-1, 12, 800, 0, "Arial Black")
GUICtrlSetBkColor(-1, 0xD4D0C8)
GUICtrlCreateLabel("DEC:", 155, 235, 49, 27)
GUICtrlSetFont(-1, 12, 800, 0, "Arial Black")
GUICtrlSetBkColor(-1, 0xD4D0C8)
GUISetState(@SW_SHOW)
GUIRegisterMsg($WM_COMMAND, "MY_WM_COMMAND")
$CurrentRed = GUICtrlRead($RedSlider)
$CurrentGreen = GUICtrlRead($GreenSlider)
$CurrentBlue = GUICtrlRead($BlueSlider)
While 1
    $msg = GUIGetMsg()
    Select
        Case $msg = $GUI_EVENT_CLOSE
            ExitLoop
        Case Else
            If $CurrentRed <> GUICtrlRead($RedSlider) Or _
                    $CurrentGreen <> GUICtrlRead($GreenSlider) Or _
                    $CurrentBlue <> GUICtrlRead($BlueSlider) Then
                $CurrentRed = GUICtrlRead($RedSlider)
                GUICtrlSetData($RedCount, "Red: " & $CurrentRed & " = " & StringTrimLeft(Hex($CurrentRed), 6))
                $CurrentGreen = GUICtrlRead($GreenSlider)
                GUICtrlSetData($GreenCount, "Green: " & $CurrentGreen & " = " & StringTrimLeft(Hex($CurrentGreen), 6))
                $CurrentBlue = GUICtrlRead($BlueSlider)
                GUICtrlSetData($BlueCount, "Blue: " & $CurrentBlue & " = " & StringTrimLeft(Hex($CurrentBlue), 6))
                $OutHex = StringTrimLeft(Hex($CurrentRed), 6) & StringTrimLeft(Hex($CurrentGreen), 6) & StringTrimLeft(Hex($CurrentBlue), 6)
                $OutDec = Dec($OutHex)
                GUICtrlSetData($HexInput, $OutHex)
                GUICtrlSetData($DecInput, $OutDec)
                GUICtrlSetBkColor($Display, "0x" & $OutHex)
            EndIf
    EndSelect

WEnd
Exit

Func _Hex_Changed()
    ;----------------------------------------------------------------------------------------------
    If $DebugIt Then _DebugPrint("_Hex_Changed:" & GUICtrlRead($HexInput))
    ;----------------------------------------------------------------------------------------------
    Local $Hex = GUICtrlRead($HexInput)
    If StringLen($Hex) = 6 Then
        If GUICtrlRead($RedSlider) <> Dec(StringMid($Hex, 1, 2)) Then
            GUICtrlSetData($RedSlider, Dec(StringMid($Hex, 1, 2)))
        EndIf
        If GUICtrlRead($GreenSlider) <> Dec(StringMid($Hex, 3, 2)) Then
            GUICtrlSetData($GreenSlider, Dec(StringMid($Hex, 3, 2)))
        EndIf
        If GUICtrlRead($BlueSlider) <> Dec(StringMid($Hex, 5, 2)) Then
            GUICtrlSetData($BlueSlider, Dec(StringMid($Hex, 5, 2)))
        EndIf
    EndIf
EndFunc   ;==>_Hex_Changed

Func _Dec_Changed()
    ;----------------------------------------------------------------------------------------------
    If $DebugIt Then _DebugPrint("_Dec_Changed:" & GUICtrlRead($DecInput))
    ;----------------------------------------------------------------------------------------------
    Local $Hex = Hex(GUICtrlRead($DecInput), 6)
    If StringLen($Hex) = 6 Then
        If GUICtrlRead($RedSlider) <> Dec(StringMid($Hex, 1, 2)) Then
            GUICtrlSetData($RedSlider, Dec(StringMid($Hex, 1, 2)))
        EndIf
        If GUICtrlRead($GreenSlider) <> Dec(StringMid($Hex, 3, 2)) Then
            GUICtrlSetData($GreenSlider, Dec(StringMid($Hex, 3, 2)))
        EndIf
        If GUICtrlRead($BlueSlider) <> Dec(StringMid($Hex, 5, 2)) Then
            GUICtrlSetData($BlueSlider, Dec(StringMid($Hex, 5, 2)))
        EndIf
    EndIf
EndFunc   ;==>_Dec_Changed

Func MY_WM_COMMAND($hWnd, $msg, $wParam, $lParam)
    Local $nNotifyCode = _HiWord($wParam)
    Local $nID = _LoWord($wParam)
    Local $hCtrl = $lParam

    Switch $nID
        Case $HexInput
            Switch $nNotifyCode
                Case $EN_CHANGE
                    _Hex_Changed()
            EndSwitch
        Case $DecInput
            Switch $nNotifyCode
                Case $EN_CHANGE
                    _Dec_Changed()
            EndSwitch
    EndSwitch
    ; Proceed the default Autoit3 internal message commands.
    ; You also can complete let the line out.
    ; !!! But only 'Return' (without any value) will not proceed
    ; the default Autoit3-message in the future !!!
    Return $GUI_RUNDEFMSG
EndFunc   ;==>MY_WM_COMMAND

Func _DebugPrint($s_text)
    $s_text = StringReplace($s_text, @LF, @LF & "-->")
    ConsoleWrite("!===========================================================" & @LF & _
            "+===========================================================" & @LF & _
            "-->" & $s_text & @LF & _
            "+===========================================================" & @LF)
EndFunc   ;==>_DebugPrint

Func _HiWord($x)
    Return BitShift($x, 16)
EndFunc   ;==>_HiWord

Func _LoWord($x)
    Return BitAND($x, 0xFFFF)
EndFunc   ;==>_LoWord

SciTE for AutoItDirections for Submitting Standard UDFs

 

Don't argue with an idiot; people watching may not be able to tell the difference.

 

Link to comment
Share on other sites

  • 2 years later...

Thank you Paulie, Zedna and GaryFrost for this excellent script. :mellow:

I modified this script and put it in my tool : GCS Search

Posted Image

Edited by Jikoo
My projects : GCS Search 1.07 (GUI Control Styles Search)* Multilingual tool to help about the old scripts, with a dynamic menu.* Easy way to find missing Include files in old scripts downloaded from forums !* Famous Monoceres script added and improved (visual, drag and drop, automatic)* There is an interactive color converter with palettes too, for fun !The best way to start Autoit3 development (for newbies).
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...