AHK调用系统颜色对话框函数
贴一个 AHK 调用系统颜色对话框的函数 Dlg_Color:
Dlg_Color(ByRef Color, hGui=0) ;调用系统颜色对话框 { clr := ((Color & 0xFF) << 16) + (Color & 0xFF00) + ((Color >> 16) & 0xFF) VarSetCapacity(CHOOSECOLOR, 0x24, 0), VarSetCapacity(CUSTOM, 64, 0) ,NumPut(0x24, CHOOSECOLOR, 0) ; DWORD lStructSize ,NumPut(hGui, CHOOSECOLOR, 4) ; HWND hwndOwner (makes dialog "modal"). ,NumPut(clr, CHOOSECOLOR, 12) ; clr.rgbResult ,NumPut(&CUSTOM, CHOOSECOLOR, 16) ; COLORREF *lpCustColors ,NumPut(0x00000103,CHOOSECOLOR, 20) ; Flag: CC_ANYCOLOR || CC_RGBINIT nRC := DllCall("comdlg32\ChooseColorA", str, CHOOSECOLOR) ; Display the dialog. if (errorlevel <> 0) || (nRC = 0) return false clr := NumGet(CHOOSECOLOR, 12) oldFormat := A_FormatInteger SetFormat, integer, hex ; Show RGB color extracted below in hex format. Color := (clr & 0xff00) + ((clr & 0xff0000) >> 16) + ((clr & 0xff) << 16) ;convert to rgb StringTrimLeft, Color, Color, 2 loop, % 6-strlen(Color) Color=0%Color% Color=%Color% SetFormat, integer, %oldFormat% return true }
注意:
- 该函数的参数 Color 为 ByRef 类型。否则,可以用 Return 返回选定的颜色。
- 参数 hGui 为调用该函数的窗口ID。