Link to home
Start Free TrialLog in
Avatar of chencc77
chencc77

asked on

commonDialog Show color

i use Visual Interdev to create a CommonDialog box to display color box for me to choose color.
but i found that the color i choosed is not same as the color display. (Not all color, but some)
So i hope anyone can help me. Thanks alot.

Below is the source code.

<%@ Language=VBScript %>
<HTML>
<HEAD>
<META name=VI60_defaultClientScript content=VBScript>
<META NAME="GENERATOR" Content="Microsoft Visual Studio 6.0">
<SCRIPT ID=clientEventHandlersVBS LANGUAGE=vbscript>
<!--

Sub button1_onclick

     CommonDialog1.ShowColor
     text1.style.backgroundColor= CommonDialog1.Color
     
     
End Sub

-->
</SCRIPT>
</HEAD>
<BODY>

<P>
<OBJECT id=CommonDialog1 classid=clsid:F9043C85-F6F2-101A-A3C9-08002B2F49FB><PARAM NAME="_ExtentX" VALUE="847"><PARAM NAME="_ExtentY" VALUE="847"><PARAM NAME="_Version" VALUE="393216"><PARAM NAME="CancelError" VALUE="0"><PARAM NAME="Color" VALUE="0"><PARAM NAME="Copies" VALUE="1"><PARAM NAME="DefaultExt" VALUE=""><PARAM NAME="DialogTitle" VALUE=""><PARAM NAME="FileName" VALUE=""><PARAM NAME="Filter" VALUE=""><PARAM NAME="FilterIndex" VALUE="0"><PARAM NAME="Flags" VALUE="0"><PARAM NAME="FontBold" VALUE="0"><PARAM NAME="FontItalic" VALUE="0"><PARAM NAME="FontName" VALUE=""><PARAM NAME="FontSize" VALUE="8"><PARAM NAME="FontStrikeThru" VALUE="0"><PARAM NAME="FontUnderLine" VALUE="0"><PARAM NAME="FromPage" VALUE="0"><PARAM NAME="HelpCommand" VALUE="0"><PARAM NAME="HelpContext" VALUE="0"><PARAM NAME="HelpFile" VALUE=""><PARAM NAME="HelpKey" VALUE=""><PARAM NAME="InitDir" VALUE=""><PARAM NAME="Max" VALUE="0"><PARAM NAME="Min" VALUE="0"><PARAM NAME="MaxFileSize" VALUE="260"><PARAM NAME="PrinterDefault" VALUE="1"><PARAM NAME="ToPage" VALUE="0"><PARAM NAME="Orientation" VALUE="1"></OBJECT>
<INPUT id=text1 name=text1></P>
<P><INPUT id=button1 type=button value=Button name=button1></P>

</BODY>
</HTML>
Avatar of Michel Sakr
Michel Sakr
Flag of Canada image

In cases I encounered that IE browsers don't show the selected colors but a close match... I thought it might be that I have a pattern of 24bit colors (FFFFFF) and my display settings are set to 16 bit or less.. this might occure..
Avatar of chencc77
chencc77

ASKER

i found that the color box use 'long' numeric to identify the color. So how am i going to solve this problem??
yes.. 24 bit value.. 16777215 = FFFFFF hex

what are your entered values?
I found the red and blue color has been change position

try this


Function RGBX(red, green, blue)
     
    On Error Resume Next
     RGBX = RGB(blue, green, red)
end Function


function GetRed(color)
     
    On Error Resume Next
     GetRed = color And &HFF
end Function

function GetGreen(color)
     
    On Error Resume Next
     GetGreen = ((color And &HFF00) / &H100) And &HFF
end Function

function GetBlue(color)
     
    On Error Resume Next
     GetBlue = ((color And &HFF0000) / &H10000) And &HFF
end Function


text1.style.backgroundColor = RGBX(getblue(color), getgreen(color), getred(color))
OOhs where color is

Dim color
color = CommonDialog1.Color


hi EDDYKT,
i have edit the code, but i found it show all black color.


<%@ Language=VBScript %>
<HTML>
<HEAD>
<META name=VI60_defaultClientScript content=VBScript>
<META NAME="GENERATOR" Content="Microsoft Visual Studio 6.0">
<SCRIPT ID=clientEventHandlersVBS LANGUAGE=vbscript>
<!--
Dim color

Sub button1_onclick

CommonDialog1.ShowColor
color = CommonDialog1.Color
msgbox color
msgbox RGBX(getblue(color), getgreen(color), getred(color))
text1.style.backgroundColor = RGBX(getblue(color), getgreen(color), getred(color))

End Sub



Function RGBX(red, green, blue)
    msgbox "rGBX"
   On Error Resume Next
    RGBX = RGB(blue, green, red)
end Function


function GetRed(color)
   
   On Error Resume Next
    GetRed = color And &HFF
end Function

function GetGreen(color)
   
   On Error Resume Next
    GetGreen = ((color And &HFF00) / &H100) And &HFF
end Function

function GetBlue(color)
   
   On Error Resume Next
    GetBlue = ((color And &HFF0000) / &H10000) And &HFF
end Function



-->
</SCRIPT>
</HEAD>

<BODY>

<P>&nbsp;</P>
<INPUT id=text1 name=text1>
<INPUT id=button1 type=button value=Button name=button1>
<OBJECT id=CommonDialog1 classid=clsid:F9043C85-F6F2-101A-A3C9-08002B2F49FB><PARAM NAME="_ExtentX" VALUE="847"><PARAM NAME="_ExtentY" VALUE="847"><PARAM NAME="_Version" VALUE="393216"><PARAM NAME="CancelError" VALUE="0"><PARAM NAME="Color" VALUE="0"><PARAM NAME="Copies" VALUE="1"><PARAM NAME="DefaultExt" VALUE=""><PARAM NAME="DialogTitle" VALUE=""><PARAM NAME="FileName" VALUE=""><PARAM NAME="Filter" VALUE=""><PARAM NAME="FilterIndex" VALUE="0"><PARAM NAME="Flags" VALUE="0"><PARAM NAME="FontBold" VALUE="0"><PARAM NAME="FontItalic" VALUE="0"><PARAM NAME="FontName" VALUE=""><PARAM NAME="FontSize" VALUE="8"><PARAM NAME="FontStrikeThru" VALUE="0"><PARAM NAME="FontUnderLine" VALUE="0"><PARAM NAME="FromPage" VALUE="0"><PARAM NAME="HelpCommand" VALUE="0"><PARAM NAME="HelpContext" VALUE="0"><PARAM NAME="HelpFile" VALUE=""><PARAM NAME="HelpKey" VALUE=""><PARAM NAME="InitDir" VALUE=""><PARAM NAME="Max" VALUE="0"><PARAM NAME="Min" VALUE="0"><PARAM NAME="MaxFileSize" VALUE="260"><PARAM NAME="PrinterDefault" VALUE="1"><PARAM NAME="ToPage" VALUE="0"><PARAM NAME="Orientation" VALUE="1"></OBJECT>

</BODY>
</HTML>
EDDYKT : i found the Getxxx function doesn't work.

Silvers5 : my display setting is 24bit - TRue Color, izit the display setting will effect it?? i found the IE browser use the same color box, but it showed the exact color as i choosed. So wht was the reason there?? Thanks
Nahh.. this has nothing with the display then.. 1 min..
why such a turn.. simply remove all the other functions and leave this:

Sub button1_onclick

CommonDialog1.ShowColor
color = hex(CommonDialog1.Color)
text1.style.backgroundColor = "#" & color

End Sub



;o)
hmm same issue.. I'll do it another way.. 1 min..
silver5 : can u try my code?? really there are some color that display different color from wht i choose.
silver5 : can u try my code?? really there are some color that display different color from wht i choose.
silver5 : they are a error if use ur suggestion.

hex(0) = 0

no this color

:>
the dialogue box is returning the colors info blue green red instead of red green blue ..I'll fix you a code in 1 min..
Shake it baby ;o)


Sub button1_onclick

CommonDialog1.ShowColor
color = hex(CommonDialog1.Color)
color =  Right(color,2) & Mid(color,3,2) & left(color,2)
text1.style.backgroundColor = "#" & color
End Sub

silver5 : they are a error if use ur suggestion.

hex(0) = 0

no this color

:>
This issue was tricky! the dialogue box seemed to have a bug.. 100 extra points are nice :o)  jokin..
silver5 : they are a error if use ur suggestion.

hex(0) = 0

no this color

:>
no problems...  :>
need ur help.
I'll need to polish the code for bugs.. like if the color number is less than 6 digits.. or is 0
But the main issue is resolved.. colors are shown exactly as they are.. give me a minute for polishing..
silver5 : not all color are fix. still got error.

 :(
ASKER CERTIFIED SOLUTION
Avatar of Michel Sakr
Michel Sakr
Flag of Canada image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
>silver5 : not all color are fix. still got error.

what color?
silver5 : not all color are fix. still got error.

 :(
remove the msb boxes from the sub..
msg boxes
the last code I gave will take all colors.. the error you had is because of the colors that are less than 6 in hex length.. try it and report back
silver5 : not all color are fix. still got error.

 :(
Chen.. what is the error? or your post is duplicated (you are on a slow connection?)
silver5 : thank you very much, really appreciate ur help.

^_^  .  really nice to meet u here!!


from,
cc chen
silver5 : yes, the msg is duplicated. u have solve all the problems...

here's ur points
You're welcome ;o)  I was glad to solve.. a bug! :o)

I posted comment to your other question that you can't use getred getgreen and getblue function.. your best way is to convert them to Hex and get the part you need using mid function..

rgrds