100% AutoHotkey, no dllcalls or gdi+
This time, it's a colour dialog!
Revision 1
Code: Select all
;
; AutoHotkey Version: 1.1.12.00
; Language: English
; Dev Platform: Windows 7 Home Premium x64
; Author: Joe DF | http://joedf.co.nr | [email protected]
; Date: August 20th, 2013
;
; Script Function:
; Color Dialog Example script.
;
#NoEnv ; Recommended for performance and compatibility with future AutoHotkey releases.
#Warn ; Recommended for catching common errors.
SendMode Input ; Recommended for new scripts due to its superior speed and reliability.
SetWorkingDir %A_ScriptDir% ; Ensures a consistent starting directory.
;<<<<<<<< HEADER END >>>>>>>>>
;Set starting default value to RGB(44,197,89), Just a random colour
RGBval:=RGB(Rval:=44,Gval:=197,Bval:=89)
;Create Color Dialog GUI
Gui, Add, Text, x0 y10 w40 h20 +Right, Red
Gui, Add, Text, x0 y30 w40 h20 +Right, Green
Gui, Add, Text, x0 y50 w40 h20 +Right, Blue
Gui, Add, Slider, x40 y10 w190 h20 AltSubmit +NoTicks +Range0-255 vsR gSliderSub, %Rval%
Gui, Add, Slider, x40 y30 w190 h20 AltSubmit +NoTicks +Range0-255 vsG gSliderSub, %Gval%
Gui, Add, Slider, x40 y50 w190 h20 AltSubmit +NoTicks +Range0-255 vsB gSliderSub, %Bval%
Gui, Add, Edit, x230 y10 w45 h20 gEditSub veR +Limit3 +Number, %Rval%
Gui, Add, UpDown, Range0-255 vuR gUpDownSub, %Rval%
Gui, Add, Edit, x230 y30 w45 h20 gEditSub veG +Limit3 +Number, %Gval%
Gui, Add, UpDown, Range0-255 vuG gUpDownSub, %Gval%
Gui, Add, Edit, x230 y50 w45 h20 gEditSub veB +Limit3 +Number, %Bval%
Gui, Add, UpDown, Range0-255 vuB gUpDownSub, %Bval%
Gui, Add, Progress, x285 y10 w60 h60 +Border Background%RGBval% vpC
Gui, Add, Text, x285 y10 w60 h60 +Border vtP cWhite +BackgroundTrans, Preview
Gui, Add, Button, x120 y80 w110 h20 vbS gButtonSub, Copy to Clipboard
Gui, Show, w351 h105, Simple Color Dialog
return
EditSub:
;Get Values
GuiControlGet,Rval,,eR
GuiControlGet,Gval,,eG
GuiControlGet,Bval,,eB
;Set preview
gosub set
;Make Everything else aware
GuiControl,,uR,%Rval%
GuiControl,,uG,%Gval%
GuiControl,,uB,%Bval%
GuiControl,,sR,%Rval%
GuiControl,,sG,%Gval%
GuiControl,,sB,%Bval%
return
UpDownSub:
;Get Values
GuiControlGet,Rval,,uR
GuiControlGet,Gval,,uG
GuiControlGet,Bval,,uB
;Set preview
gosub set
;Make Everything else aware
GuiControl,,eR,%Rval%
GuiControl,,eG,%Gval%
GuiControl,,eB,%Bval%
GuiControl,,sR,%Rval%
GuiControl,,sG,%Gval%
GuiControl,,sB,%Bval%
return
SliderSub:
;Get Values
GuiControlGet,Rval,,sR
GuiControlGet,Gval,,sG
GuiControlGet,Bval,,sB
;Set preview
gosub set
;Make Everything else aware
GuiControl,,eR,%Rval%
GuiControl,,eG,%Gval%
GuiControl,,eB,%Bval%
GuiControl,,uR,%Rval%
GuiControl,,uG,%Gval%
GuiControl,,uB,%Bval%
return
set:
;Convert values to Hex
RGBval:=RGB(Rval,Gval,Bval)
;Display Tooltip
ToolTip Red: %Rval%`nGreen: %Gval%`nBlue: %Bval%`nHex: %RGBval%
;Make tooltip disappear after 375 ms (3/8th of a second)
SetTimer, RemoveToolTip, 375
;Apply colour to preview
GuiControl,+Background%RGBval%,pC
return
RemoveToolTip:
SetTimer, RemoveToolTip, Off ;Turn timer off
ToolTip ;Turn off tooltip
return
ButtonSub:
;Remove '0x' prefix to hex color code, saving it directly to the clipboard
StringReplace,Clipboard,RGBval,0x
;Display Last selected values... (these values can later be used), and Notify the user
MsgBox,64,Simple Color Dialog,RGB: (%Rval%, %Gval%, %Bval%)`nHex: %RGBval%`nCopied to Clipboard!
;Skip Directly GuiClose
GuiClose:
;Exit This Example script
ExitApp
;Function to convert Decimal RGB to Hexadecimal RBG, Note: '0' (zero) padding is unnecessary
RGB(r, g, b) {
;Shift Numbers
var:=(r << 16) + (g << 8) + b
;Save current A_FormatInteger
OldFormat := A_FormatInteger
;Set Hex A_FormatInteger mode
SetFormat, Integer, Hex
;Force decimal number to Hex number
var += 0
;set original A_FormatInteger mode
SetFormat, Integer, %OldFormat%
return var
}
Cheers!