This is another proof of concept script. Color Dialog found on forum.
Have fun.
Code:
SetBatchLines -1
SetWinDelay -1
#NoEnv
Gui, +LastFound ; +AlwaysOnTop +ToolWindow
Gui, Add, GroupBox, x6 y40 w320 h310 , My Picture
Gui, Add, ComboBox, x46 y10 w90 h20 vPen_Size gPenSize r5, 1|2|3|4||5|6|7|8|9|10
Gui, Add, Text, x16 y10 w30 h20 , Size:
Gui, Add, Button, x146 y10 w60 h20 gPickColor, Pick Color
;Gui, Add, Button, x216 y10 w60 h20 , Save File
Gui, Add, Text, x16 y60 w300 h280 +Border hwndhCanvas +0x2000000 +0x6 +0x1000 ;+0x12
Gui, Show, , AHK Paint
Size := 200
WinSet, Trans, 255
hGui := WinExist()
hDc := DllCall("GetDC", "uint", hCanvas)
Selected_Color := 0x0
CoordMode, Mouse, Relative
SysGet, SM_CXBORDER, 5
SysGet, SM_CYBORDER, 6
SysGet, SM_CYCAPTION, 4
WindowProcNew := RegisterCallback("WindowProc", "" ; "" to avoid fast-mode for subclassing.
, 4, hGui) ; Must specify exact ParamCount when EventInfo parameter is present.
WindowProcOld := DllCall("SetWindowLong", UInt, hGui, Int, -4 ; -4 is GWL_WNDPROC
, Int, WindowProcNew, UInt) ; Return value must be set to UInt vs. Int.
ControlGetPos, Canvas_x, Canvas_y, , , ,ahk_id %hCanvas%
;Return
PenSize:
Gui, Submit, NoHide
return
#z::
PickColor:
Selected_Color:=ColorPicker(hGui)
return
WindowProc(hwnd, uMsg, wParam, lParam)
{
Global
Critical
If LButton {
MouseGetPos, x1, y1, , hControl, 2
If !(hControl = hCanvas) or ( (Oldx1 = x1) and (Oldy1 = y1) )
return DllCall("CallWindowProcA", UInt, WindowProcOld, UInt, hwnd, UInt, uMsg, UInt, wParam, UInt, lParam)
Count++
hPen := DllCall("CreatePen", "UInt", 0, "UInt", Pen_Size, "UInt", Selected_Color)
hOldObject := DllCall("SelectObject", "UInt", hDc, "UInt", hPen)
DllCall("Ellipse", "uint", hDc, "int", x1-Canvas_x-1, "int", y1-Canvas_y+1, "int", x1-Canvas_x, "int", y1-Canvas_y)
;Select the old oject back into the DC.
DllCall("SelectObject", "UInt", hDc, "UInt", hOldObject)
;Delete the pen that is no longer needed
DllCall("DeleteObject", "UInt", hPen)
Oldx1 := x1
Oldy1 := y1
}
return DllCall("CallWindowProcA", UInt, WindowProcOld, UInt, hwnd, UInt, uMsg, UInt, wParam, UInt, lParam)
}
BGRtoRGB(oldValue)
{
Value := (oldValue & 0x00ff00)
Value += ((oldValue & 0xff0000) >> 16)
Value += ((oldValue & 0x0000ff) << 16)
return Value
}
ColorPicker(OwnerGui,CurrentHexColor="")
{
SizeOfStructForChooseColor = 0x24
VarSetCapacity(StructForChooseColor, SizeOfStructForChooseColor, 0)
VarSetCapacity(StructArrayForChooseColor, 64, 0)
NumPut(SizeOfStructForChooseColor, StructForChooseColor, 0) ; DWORD lStructSize
NumPut(OwnerGui, StructForChooseColor, 4) ; HWND hwndOwner (makes dialog "modal").
NumPut(0x0 , StructForChooseColor, 8) ; HINSTANCE hInstance
NumPut(0x0 , StructForChooseColor, 12) ; clr.rgbResult = 0;
NumPut(&StructArrayForChooseColor , StructForChooseColor, 16) ; COLORREF *lpCustColors
NumPut(0x00000100 , StructForChooseColor, 20) ; Flag: Anycolor
NumPut(0x0 , StructForChooseColor, 24) ; LPARAM lCustData
NumPut(0x0 , StructForChooseColor, 28) ; LPCCHOOKPROC lpfnHook
NumPut(0x0, StructForChooseColor, 32) ; LPCTSTR lpTemplateName
nRC := DllCall("comdlg32\ChooseColorA", str, StructForChooseColor) ; Display the dialog.
if (errorlevel <> 0)
{
MsgBox error while calling ChooseColor Errorlevel: %errorlevel% - RC: %nRC%
return
}
If (nRC = 0)
return -1
; Otherwise, the user pressed OK in the dialog, so determine what was selected.
;GuiControl,, Color, % BGRtoRGB(ExtractInteger(StructForChooseColor, 12))
SetFormat, integer, hex ; Show RGB color extracted below in hex format.
return NumGet(StructForChooseColor, 12)
}
~Lbutton::
MouseGetPos, , , , hButtonDownControl, 2
If (hButtonDownControl = hCanvas) {
LButton++
Break=
}
Return
~Lbutton Up::LButton:="", Break := 1
esc::exitapp