由群友:任性,分享修正
由蜜獾哥进行二次改进
CustomColors:=[0x1010E8,0xFFFF17,0x19BFFF,0xE2CC79,0xFF7A00,0xFF9700,0x549E54,0xF0F0F0
,0xB1F7FF,0x6DD71D,0xC073D1,0xE8E8E8,0xe05855,0xB9D497,0x0078D7,0xF8B62D]
Gui,Test:Destroy
Gui,Test:+HWNDhTest
Gui,Test:Add, Text, section, % " BGR: "
Gui,Test:Add, Edit,ys-4
Gui,Test:Add, Text, section xs, % " RGB: "
Gui,Test:Add, Edit,ys-4
Gui,Test:Add, Text, section xs, RRGGBB:
Gui,Test:Add, Edit,ys-4
Gui,Test:Add,Button, gbtn,取色
Gui,Test:Show
Return
btn:
Dlg_Color(SelectColor,"自定义取色窗口",hTest,CustomColors*)
if objCount(SelectColor){
GuiControl,test:,Edit1,% SelectColor.BGR
GuiControl,test:,Edit2,% SelectColor.RGB
GuiControl,test:,Edit3,% SelectColor.RRGGBB
Gui,+OwnDialogs
MsgBox % "BGR:" SelectColor.BGR
. "`nRGB:" SelectColor.RGB
. "`nRRGGBB:" SelectColor.RRGGBB
}
Return
TestGuiClose:
ExitApp
;-----------------------------------------配色----------------------------------------------------------
/*!
函数: Dlg_Color(ByRef r_Color,WinTitle="", hOwner:=0, Palette*)---->显示用于选择颜色的标准窗口对话框。
参数:
r_Color - 初始颜色-->默认设置为黑色.返回结果集{RGB:",BGR:"",RRGGBB:"}
WinTitle - 自定义窗口标题,默认标题为「颜色」
hOwner - 对话框对象的窗口ID, 如果有的话默认为0, i.e. 没有对象. 如果指定的DlgX和DlgY被忽略.
Palette -最多16个BGR颜色值的数组。这些将成为对话框中的初始自定义颜色。
Remarks:
对话框中的自定义颜色在调用时被标记。如果用户选择OK,则将加载调色板阵列(如果存在)使用对话框中的自定义颜色。
Returns:
如果用户选择“确定”,返回True。否则返回False
*/
Dlg_Color(ByRef r_Color, WinTitle:="",hOwner:=0, Palette*){
Static CHOOSECOLOR, A_CustomColors
if !VarSetCapacity(A_CustomColors){
If !objLength(Palette){
Palette:=[0x1C7399,0xEEEEEC,0x014E8B,0x444444,0x009FE8,0xDEF9FA,0xF8B62D,0x90FC0F,0x0078D7,0x0D1B0A,0xB9D497,0x00ADEF,0x1778BF,0xFDF6E3,0x002B36,0xDEDEDE]
}
VarSetCapacity(A_CustomColors,64,0)
for Index, Value in Palette
NumPut(Value, A_CustomColors, 4*(Index - 1), "UInt")
}
l_Color:=r_Color, l_Color:=((l_Color&0xFF)<<16)+(l_Color&0xFF00)+((l_Color>>16)&0xFF)
;-- 创建并填充CHOOSECOLOR结构
lStructSize:=VarSetCapacity(CHOOSECOLOR,(A_PtrSize=8) ? 72:36,0)
NumPut(lStructSize,CHOOSECOLOR,0,"UInt") ;-- lStructSize
NumPut(hOwner,CHOOSECOLOR,(A_PtrSize=8) ? 8:4,"Ptr")
;-- hwndOwner
NumPut(l_Color,CHOOSECOLOR,(A_PtrSize=8) ? 24:12,"UInt")
;-- RGB结果
NumPut(&A_CustomColors,CHOOSECOLOR,(A_PtrSize=8) ? 32:16,"Ptr")
;-- lpCustColors
NumPut(0x00000103,CHOOSECOLOR,(A_PtrSize=8) ? 40:20,"UInt")
;-- Flags
if (WinTitle!="")
SetTimer, AsynchronousWinWait, -1
RC:=DllCall("comdlg32\ChooseColor" . (A_IsUnicode ? "W":"A"),"Ptr",&CHOOSECOLOR)
;-- 按下“取消”按钮或关闭对话框
if (RC=0)
Return False
;-- 收集所选颜色
l_Color:=NumGet(CHOOSECOLOR,(A_PtrSize=8) ? 24:12,"UInt")
;-- 转换为RGB
TempColor:=((l_Color&0xFF)<<16)+(l_Color&0xFF00)+((l_Color>>16)&0xFF)
Red:=((TempColor & 0xff0000) >> 16),Green:=((TempColor & 0x00ff00) >> 8),Blue:=(TempColor & 0xff)
;-- 用选定的颜色更新
r_Color:={RGB:Format("0x{:06X}",TempColor) ;返回16进制RGB
,BGR:Format("0x{1:02X}{2:02X}{3:02X}",[Blue,Green,Red]*) ;返回16进制BGR
,RRGGBB:Red "," Green "," Blue} ;返回10进制RGB
Return True
AsynchronousWinWait:
if WinActive("ahk_class #32770", "颜色") or (n=60)
Goto ChangeTitle
n := n="" ? 1 : ++n
SetTimer AsynchronousWinWait, -10
Return
ChangeTitle:
WinSetTitle, ahk_class #32770, 颜色, %WinTitle%
Return
}
配图更好一些
还有个字体选取框,一并贴上吧
这个太丑了,而且没有透明度