Can't find the information you are looking for here? Then leave a message over on our WinBatch Tech Support Forum.
Keywords: udfAskColor AskColor Format
;------------------------------------------------------------------------------------------------------------------------------------------ #DefineFunction udfAskColor (strAC_DefaultColor, strAC_Reg, intAC_Format) strAC_DefaultColor = StrTrim (strAC_DefaultColor) intFormatIn = 0 intError = 1 Switch @TRUE Case strAC_DefaultColor == "" ; Empty string opens dialog with status "128|128|128" and returns hex formatted value. Case StrIndex (strAC_DefaultColor, "#", 1, @FWDSCAN) == 1 ; e. g. "#FF8040", further error checking in AskColor function. intError = 0 Break Case ItemCount (strAC_DefaultColor, ",") == 3 ; e. g. "255,255,64" intFormatIn = 2 Continue Case ItemCount (strAC_DefaultColor, "|") == 3 ; e. g. "255|255|64" intFormatIn = 1 Continue Case @TRUE strAC_DefaultColor = StrReplace (strAC_DefaultColor, ",", "|") ; e. g. from "255,255,64" to "255|255|64" If ItemCount (strAC_DefaultColor, "|") != 3 Then Break strR = ItemExtract (1, strAC_DefaultColor, "|") If !IsNumber (strR) Then Break strG = ItemExtract (2, strAC_DefaultColor, "|") If !IsNumber (strG) Then Break strB = ItemExtract (3, strAC_DefaultColor, "|") If !IsNumber (strB) Then Break intR = Int (strR) If intR < 0 Then Break If intR > 255 Then Break intG = Int (strG) If intG < 0 Then Break If intG > 255 Then Break intB = Int (strB) If intB < 0 Then Break If intB > 255 Then Break ; strAC_DefaultColor RGB string list is accepted. hdlBB = BinaryAlloc (3) ; Convert integer values to hex values. BinaryPoke (hdlBB, 0, intR) ; R BinaryPoke (hdlBB, 1, intG) ; G BinaryPoke (hdlBB, 2, intB) ; B strAC_DefaultColor = "#" : BinaryPeekHex (hdlBB, 0, 3); Format hex string for use with AskColor. hdlBB = BinaryFree (hdlBB) intError = 0 EndSwitch If intError == 1 Then ErrorEvent (-1, 7694, "AskColor: Invalid default color when using RGB format.") ; Throw minor error. Switch @TRUE Case intAC_Format == 3 intAC_Format = intFormatIn Continue Case intAC_Format == 2 strColor = AskColor (strAC_DefaultColor, strAC_Reg, 1) strColor = StrReplace (strColor, "|", ",") Break Case @TRUE strColor = AskColor (strAC_DefaultColor, strAC_Reg, intAC_Format) EndSwitch Return strColor :CANCEL Return strAC_DefaultColor ;.......................................................................................................................................... ; This UDF extends the WinBatch function "AskColor (default-color, reg-key, format)" to accept also a ; RGB value as the default color value beside the standard notation of a hex value "#RRGGBB". ; The RGB value can be formatted as a pipe delimited string list "R|G|B" ; or a comma delimited string list "R,G,B". ; ; In addition the format parameter accepts two new integer values for modifying the output format: ; - Value 2 forces the function to return a RGB comma delimited string list "R,G,B". ; - Value 3 let the function return the choosen color value in the same format as the default color value ; format was given when invoked. ; ; Note: The original function AskColor allows to specify the name of a user-defined registry key by it's ; second parameter. This functionality can be used unchanged by this UDF. ; ; Example: ; Using second parameter strAC_Reg as "MyUserDefinedColors" then there will be created a registry key ; named as "[HKEY_CURRENT_USER\Software\Wilson WindowWare\MyUserDefinedColors\AskColor]". ; This registry entry holds a binary value named "CustomColors" which is a table of 16 elements of 4-byte values, ; each value assigned to a color field in the dialog area "User Defined Colors" within the AskColor dialog. ;.......................................................................................................................................... ; Syntax ; ; udfAskColor (strAC_DefaultColor, strAC_Reg, intAC_Format) ; ; strAC_DefaultColor ; String of format "#RRGGBB" or "R|G|B" or "R,G,B". ; ; strAC_Reg ; String, name of a registry sub key under "HKEY_CURRENT_USER\Software\Wilson WindowWare" where persistent ; state information will be stored. The sub key will be created if it does not already exist. ; If an empty string is specified, then persistent state information will not be stored. ; The sub key stores the table of 16 user defined colors from the AskColor dialog. ; ; intAC_Format ; 0: Return RGB color value as hex string with format "#RRGGBB", ; where "R", "G", and "B" are the respective red, green, and blue components, in hexadecimal values. ; 1: Return RGB color value as pipe delimited list with format "R|G|B", ; where "R", "G", and "B" are the respective red, green, and blue components, in decimal values. ; 2: Return RGB color value as comma delimited list with format "R,G,B", ; where "R", "G", and "B" are the respective red, green, and blue components, in decimal values. ; 3: Return same format as default color format. ;.......................................................................................................................................... ; Detlev Dalitz.20090418.20100127. ;.......................................................................................................................................... #EndFunction ;------------------------------------------------------------------------------------------------------------------------------------------ ; Test-1. Step through each case manually. strAC_Reg = "" intAC_Format = 0 ; Return RGB color value as hex string with format "#RRGGBB" strAC_DefaultColor = "" ; No error, opens dialog with value "128|128|128", returns hex formatted value when intAC_Format != 1. ;strColorValue11 = udfAskColor (strAC_DefaultColor, strAC_Reg, intAC_Format) ;Exit strAC_DefaultColor = "255|128" ; Throw minor error 7694: AskColor: Invalid default color when using RGB format. ;strColorValue12 = udfAskColor (strAC_DefaultColor, strAC_Reg, intAC_Format) ;Exit strAC_DefaultColor = "255|255|256" ; Throw minor error 7694: AskColor: Invalid default color when using RGB format. ;strColorValue13 = udfAskColor (strAC_DefaultColor, strAC_Reg, intAC_Format) ;Exit strAC_DefaultColor = "0|-1|0" ; Throw minor error 7694: AskColor: Invalid default color when using RGB format. ;strColorValue14 = udfAskColor (strAC_DefaultColor, strAC_Reg, intAC_Format) ;Exit strAC_DefaultColor = "0||0" ; Throw minor error 7694: AskColor: Invalid default color when using RGB format. ;strColorValue15 = udfAskColor (strAC_DefaultColor, strAC_Reg, intAC_Format) ;Exit strAC_DefaultColor = "-1|0|0" ; Throw minor error 7694: AskColor: Invalid default color when using RGB format. ;strColorValue16 = udfAskColor (strAC_DefaultColor, strAC_Reg, intAC_Format) ;Exit strAC_DefaultColor = "221:221:221" ; Throw minor error 7694: AskColor: Invalid default color when using RGB format. ;strColorValue17 = udfAskColor (strAC_DefaultColor, strAC_Reg, intAC_Format) ;Exit ; Test-2 strAC_DefaultColor = "255|128|64" intAC_Format = 0 ; Return RGB color value as hex string with format "#RRGGBB" strColorValue21 = udfAskColor (strAC_DefaultColor, strAC_Reg, intAC_Format) ; "#FF8040" Display (2, "intAC_Format=" : intAC_Format, "Default=" : strAC_DefaultColor : @LF : @LF : "RGB=" : strColorValue21) intAC_Format = 1 ; Return RGB color value as pipe delimited list with format "R|G|B" strColorValue22 = udfAskColor (strAC_DefaultColor, strAC_Reg, intAC_Format) ; "255|128|64" Display (2, "intAC_Format=" : intAC_Format, "Default=" : strAC_DefaultColor : @LF : @LF : "RGB=" : strColorValue22) intAC_Format = 2 ; Return RGB color value as comma delimited list with format "R,G,B" strColorValue23 = udfAskColor (strAC_DefaultColor, strAC_Reg, intAC_Format) ; "255,128,64" Display (2, "intAC_Format=" : intAC_Format, "Default=" : strAC_DefaultColor : @LF : @LF : "RGB=" : strColorValue23) intAC_Format = 3 ; Return same format as default color format. strColorValue24 = udfAskColor (strAC_DefaultColor, strAC_Reg, intAC_Format) ; "255|128|64" Display (2, "intAC_Format=" : intAC_Format, "Default=" : strAC_DefaultColor : @LF : @LF : "RGB=" : strColorValue24) ; Test-3 strAC_DefaultColor = "255,128,64" intAC_Format = 0 ; Return RGB color value as hex string with format "#RRGGBB" strColorValue31 = udfAskColor (strAC_DefaultColor, strAC_Reg, intAC_Format) ; "#FF8040" Display (2, "intAC_Format=" : intAC_Format, "Default=" : strAC_DefaultColor : @LF : @LF : "RGB=" : strColorValue31) intAC_Format = 1 ; Return RGB color value as pipe delimited list with format "R|G|B" strColorValue32 = udfAskColor (strAC_DefaultColor, strAC_Reg, intAC_Format) ; "255|128|64" Display (2, "intAC_Format=" : intAC_Format, "Default=" : strAC_DefaultColor : @LF : @LF : "RGB=" : strColorValue32) intAC_Format = 2 ; Return RGB color value as comma delimited list with format "R,G,B" strColorValue33 = udfAskColor (strAC_DefaultColor, strAC_Reg, intAC_Format) ; "255,128,64" Display (2, "intAC_Format=" : intAC_Format, "Default=" : strAC_DefaultColor : @LF : @LF : "RGB=" : strColorValue33) intAC_Format = 3 ; Return same format as default color format. strColorValue34 = udfAskColor (strAC_DefaultColor, strAC_Reg, intAC_Format) ; "255,128,64" Display (2, "intAC_Format=" : intAC_Format, "Default=" : strAC_DefaultColor : @LF : @LF : "RGB=" : strColorValue34) ; Test-4 strAC_DefaultColor = "#FF8040" intAC_Format = 0 ; Return RGB color value as hex string with format "#RRGGBB" strColorValue41 = udfAskColor (strAC_DefaultColor, strAC_Reg, intAC_Format) ; "#FF8040" Display (2, "intAC_Format=" : intAC_Format, "Default=" : strAC_DefaultColor : @LF : @LF : "RGB=" : strColorValue41) intAC_Format = 1 ; Return RGB color value as pipe delimited list with format "R|G|B" strColorValue42 = udfAskColor (strAC_DefaultColor, strAC_Reg, intAC_Format) ; "255|128|64" Display (2, "intAC_Format=" : intAC_Format, "Default=" : strAC_DefaultColor : @LF : @LF : "RGB=" : strColorValue42) intAC_Format = 2 ; Return RGB color value as comma delimited list with format "R,G,B" strColorValue43 = udfAskColor (strAC_DefaultColor, strAC_Reg, intAC_Format) ; "255,128,64" Display (2, "intAC_Format=" : intAC_Format, "Default=" : strAC_DefaultColor : @LF : @LF : "RGB=" : strColorValue43) intAC_Format = 3 ; Return same format as default color format. strColorValue44 = udfAskColor (strAC_DefaultColor, strAC_Reg, intAC_Format) ; "#FF8040" Display (2, "intAC_Format=" : intAC_Format, "Default=" : strAC_DefaultColor : @LF : @LF : "RGB=" : strColorValue44) ; Test-5 strAC_Reg = "MyUserDefinedColors" ; Registry key to hold my user defined colors. intAC_Format = 3 ; The return value should be the same as default color format. Display (4, "udfAskColor", "Choose your personal color value." : @LF : @LF : "The value will be stored in registry key for later revoking.") strAC_DefaultColor = "255,128,64" strColorValue = udfAskColor (strAC_DefaultColor, strAC_Reg, intAC_Format) ; Returned value has format "R,G,B". Display (2, "intAC_Format=" : intAC_Format, "Default=" : strAC_DefaultColor : @LF : @LF : "RGB=" : strColorValue) Display (4, "udfAskColor", "Following color dialog is set to default color value from registry key.") strAC_DefaultColor = strColorValue strColorValue = udfAskColor (strAC_DefaultColor, strAC_Reg, intAC_Format) ; Returned value has format "R,G,B". Display (2, "intAC_Format=" : intAC_Format, "Default=" : strAC_DefaultColor : @LF : @LF : "RGB=" : strColorValue) Exit
Article ID: W18372
Filename: udfAskColor .txt
File Created: 2010:02:16:10:36:58
Last Updated: 2010:02:16:10:36:58