创建一个颜色对话框使用户可以选择颜色
#Include <Misc.au3>
_ChooseColor([$iReturnType = 0 [, $iColorRef = 0 [, $iRefType = 0 [, $hWndOwnder = 0]]]])
$iReturnType | [可选参数] 定义返回类型, 有效值: 0 - COLORREF RGB颜色 1 - BGR 16位值 2 - RGB 16位值 |
$iColorRef | [可选参数] 默认选择的颜色 |
$iRefType | [可选参数] 传递给 $iColorRef 的类型, 有效值为: 0 - COLORREF RGB颜色 1 - BGR 16位值 2 - RGB 16位值 |
$hWndOwnder | [可选参数] 本对话框的父窗口句柄. |
成功: | 返回颜色值 |
失败: | 返回 -1 |
#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>
#include <Misc.au3>
_Color_Example()
Func _Color_Example()
Local $GUI, $Btn_COLORREF, $Btn_BGR, $Btn_RGB, $iMemo
$GUI = GUICreate("_ChooseColor() Example", 400, 300)
$iMemo = GUICtrlCreateEdit("", 2, 55, 396, 200, BitOR($WS_VSCROLL, $WS_HSCROLL))
GUICtrlSetFont($iMemo, 10, 400, 0, "Courier New")
$Btn_COLORREF = GUICtrlCreateButton("COLORREF", 70, 10, 80, 40)
$Btn_BGR = GUICtrlCreateButton("BGR", 160, 10, 80, 40)
$Btn_RGB = GUICtrlCreateButton("RGB", 250, 10, 80, 40)
GUISetState()
While 1
Switch GUIGetMsg()
Case $GUI_EVENT_CLOSE
ExitLoop
Case $Btn_COLORREF
_ShowChoice($GUI, $iMemo, 0, _ChooseColor(0, 255, 0, $GUI), "COLORREF color of your choice: ")
Case $Btn_BGR
_ShowChoice($GUI, $iMemo, 1, _ChooseColor(2, 0x808000, 1, $GUI), "BGR Hex color of your choice: ")
Case $Btn_RGB
_ShowChoice($GUI, $iMemo, 2, _ChooseColor(2, 0x0080C0, 2, $GUI), "RGB Hex color of your choice: ")
EndSwitch
WEnd
EndFunc ;==>_Color_Example
Func _ShowChoice($GUI, $iMemo, $Type, $Choose, $sMessage)
Local $cr
If $Choose <> -1 Then
If $Type = 0 Then ; 为此例把 COLORREF 转换成 RGB
$cr = Hex($Choose, 6)
GUISetBkColor('0x' & StringMid($cr, 5, 2) & StringMid($cr, 3, 2) & StringMid($cr, 1, 2), $GUI)
Else
GUISetBkColor($Choose, $GUI)
EndIf
GUICtrlSetData($iMemo, $sMessage & $Choose & @CRLF, 1)
Else
GUICtrlSetData($iMemo, "User Canceled Selction" & @CRLF, 1)
EndIf
EndFunc ;==>_ShowChoice