AutoHotkey调用系统调色板当拾色器

调用windows的调色板选择颜色,效果如下图
image

以下是AutoHotkey v2 beta版代码
并增加了 argb 的选项(不过生成的都是完全不透明的颜色,有需求的可自行调整代码)

; https://docs.microsoft.com/en-us/windows/win32/api/commdlg/ns-commdlg-choosecolora-r1
;用系统的调色板选择颜色 ;返回颜色的十进制数
static selectColor(bARGB:=false, bRGB:=true) { ; CC_FULLOPEN := 0x2
    oBuf := buffer(A_PtrSize*9, 0)
    numput("uint", A_PtrSize*9, oBuf)
    numput("uint", hOwner:=0, oBuf, A_PtrSize)
    numput("uint", 0x0000ff, oBuf, A_PtrSize * 3) ;默认颜色
    numput("uint", oBuf.ptr+36, oBuf, A_PtrSize * 4) ;COLORREF *lpCustColors
    numput("uint", flags:=3, oBuf, A_PtrSize * 5)
    SetTimer(()=>WinActivate("颜色 ahk_class #32770"), -100) ;自动激活窗口
    dllcall("comdlg32\ChooseColorA", "Ptr",oBuf)
    if (bRGB) {
        cl := numget(oBuf, A_PtrSize * 3, "UPtr")
    } else {
        nBGR := numget(oBuf, A_PtrSize * 3, "UPtr")
        cl := (nBGR & 0xFF) << 16 | nBGR & 0x0000FF00 | nBGR >> 16
    }
    res := bARGB ? (0xff000000 | cl) : cl ;转成 argb,透明度为ff(完全不透明),可自行修改
    return res
}
posted @ 2020-12-25 22:40  火冷  阅读(678)  评论(0编辑  收藏  举报