Announcement

Collapse
No announcement yet.

Color picker dialog bug

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • Color picker dialog bug

    Curious, think I found my problem with my CGI not displaying the correct color, it was not GIVEN the correct color...

    Now, for MOST colors this works fine.
    But, launch this codea nd select pure black, it does not return anything....
    And, in some colors it returns the wrong color, light blue might be a light pink, and if so, light pink returns light blue....

    Weird....I'm not an RGB kind of guy, hehe, still learning this stuff but the function returns the color code in teh #XXXXXX format for use in web pages..


    Code:
                 Case %ID_FONT_ALINK_BUTTON
                      sTmp = GetColorSelection(CbHndl,LinkFG)
                      If Len(sTmp) Then
                         LinkFG = sTmp
                         Control Set Text CbHndl,%ID_FONT_ALINK_TEXT,LinkFG
                      End If   
    
    '
    '
    '
    ''
    
    
    '------------------------------------------------------------------------------------------
    Function GetColorSelection(hWnd As Long,ByVal CurrentColor As String) As String
    Local ColorValue    As Long
    Local sTmp          As String
    CurrentColor = Remove$(CurrentColor,"#")
    ColorValue = SelectColor(hWnd,Val("&h" & CurrentColor),1)
    If IsTrue ColorValue Then
        sTmp = Hex$(ColorValue)
        'Adds string "0" missing
        Function = "#" & String$(6 - Len(sTmp),"0") & sTmp
    End If
    End Function
    '-----------------------------------------------------------------------------------------
    Function SelectColor(ByVal hParent As Long, ByVal iStartColor As Long, ByVal iUseExt As Long) As Long
      Local cca As ChooseColorApi
      Dim ccTemp(16) As Static Dword
      cca.hinstance    = 0
      cca.lStructSize  = SizeOf(cca)
      cca.lpCustColors = VarPtr(ccTemp(0))  '<-- !!
      cca.Flags        = %CC_RGBINIT Or %CC_FULLOPEN Or %CC_ANYCOLOR
      If iUseExt = 0 Then cca.Flags = cca.Flags Or %CC_PREVENTFULLOPEN
      cca.hwndowner    = hParent
      cca.rgbResult    = iStartColor
    
      If ChooseColor(cca) Then Function = cca.rgbResult
    
    End Function
    '------------------------------------------------------------------------------------------
    ------------------
    Scott
    Scott Turchin
    MCSE, MCP+I
    http://www.tngbbs.com
    ----------------------
    True Karate-do is this: that in daily life, one's mind and body be trained and developed in a spirit of humility; and that in critical times, one be devoted utterly to the cause of justice. -Gichin Funakoshi

  • #2
    By adding 0's to the beginning of the string created by the Hex
    funciton, it messes with the actual byte alignment.
    For instance Red would be &HFF (or FF). You add 4 0's to the
    beginning of it(because it is less then 6 chars long). That
    changes it to blue(&H0000FF).

    You need to try something like this:
    Code:
    Function MakeHex$(SomeColor As Integer)
    	MakeHex$ = Right$("0" & Hex$(SomeColor), 2)
    End Function
    
    rgbColor = cca.rgbResult
    
    RGBRed = rgbColor And &HFF
    RGBGreen = ((rgbColor And &H100FF00) / &H100)
    RGBBlue = (rgbColor And &HFF0000) / &H10000
    
    htmlColor = "#" & MakeHex$(RGBRed) & MakeHex$(RGBGreen) & MakeHex$(RGBBlue)
    Mark

    ------------------




    [This message has been edited by Mark A Owiesny (edited May 11, 2001).]

    Comment


    • #3
      No need to go out of your way to add leading zeroes. HEX$ can do that for you...
      Code:
      result$ = HEX$(number, fieldlen)
      ------------------
      Tom Hanlin
      PowerBASIC Staff

      Comment


      • #4
        You learn something new every day. I didn't know you could do that.

        Originally posted by Tom Hanlin:
        No need to go out of your way to add leading zeroes. HEX$ can do that for you...
        Code:
        result$ = HEX$(number, fieldlen)


        ------------------

        Comment


        • #5
          Interesting results:

          '
          Code:
          Function GetColorSelection(hWnd As Long,ByVal CurrentColor As String) As String
          Local ColorValue    As Long
          Local sTmp          As String
          CurrentColor = Remove$(CurrentColor,"#")
          ColorValue = SelectColor(hWnd,Val("&h" & CurrentColor),1)
          If IsTrue ColorValue Then Function = "#" & Hex$(ColorValue,6)
          End Function
          If I click on Light blue, 5th one from the left on the top row in the color picker, it returns:
          #FFFF80

          But, The TNGMP3 Output shows this for folder background:
          <TD BGCOLOR=#FFFF80>
          So that is correct, except the CGI display is YELLOW:

          '
          '
          Now, it may also be something with the dynamic style sheet that is being used, whereas LINK is defined in teh style as another color, but it's BACKGROUND is not.
          Best way to show you is to have you browse to the CGI:
          http://www.tngbbs.com/mp3/tngmp3.exe

          username: powerbasic
          password: powerbasic
          domain: tngbbs


          According to the source, it's supposed tdo be light blue, but the folderbg is yellow....
          Basically here's what a "View->Source" shows:

          Code:
          <!---------TNG MP3 Listing Begins here------->
          
          <style type="text/css">
          .blue {color: blue;text-decoration:none}
          .red  {color: red;text-decoration:none}
          .warn  {color: black;text-transform:none;font-style:normal;font-weight:bolder;background:yellow;}
          .del {color: black;text-decoration:Line-through;background:#F66;}
          .ins{color: black;text-decoration:None;background:yellow;}
          A:link{text-decoration: None; Color: #080880;}
          A:visited {text-decoration: None; Color: #080880;}
          A:active{text-decoration:None; Color: #40FF00;}
          A:hover{text-decoration: None; Color: #FFFF00;background: #080880;}
          </style>
          <table BORDER="3">
          <TR BGCOLOR="#7191F7"><font color="#FFFF00"><TD><table border="0">
          <TR><TD><a href="http://www.tngbbs.com/ccs"> <img src="/mp3/cclogo.gif" border="0"></a></TD><TD>TNGMP3 v1.6 Copyright (c) 2000  <a href=http://www.tngbbs.com>Computer Creations Software</a><br>
          Brought to you by <a href="http://www.tngbbs.com" class="blue">
          <style type="text/css">
          .lcase {color: blue;text-decoration:none}
          .ucase  {color: red;text-decoration:none}
          </style>
          </span><span class="ucase">T</span><span class="lcase">he </span><span class="ucase">N</span><span class="lcase">ight </span><span class="ucase">G</span><span class="lcase">allery </span><span class="ucase">BBS</span></a><br>
          <br><span class="warn">REGISTERED TO:</span> 
          <style type="text/css">
          .lcase {color: blue;text-decoration:none}
          .ucase  {color: red;text-decoration:none}
          </style>
          </span><span class="ucase">T</span><span class="lcase">he </span><span class="ucase">N</span><span class="lcase">ight </span><span class="ucase">G</span><span class="lcase">allery </span><span class="ucase">BBS</span><br>
          </TD></TR></table>
          <td>14:31:55</td><td>05-11-2001</TD></tr></Font>
          <TR><TD BGCOLOR=#FFFF80><a href="javascript:history.back(1)"><img src=/mp3/folder.gif border=0></a>&nbsp;&nbsp;/virtualmp3/</TD><TD BGCOLOR=#FF00FF>FileSize: </TD><TD BGCOLOR=#FF00FF>File Date/Time:</TD></TR>
          <TD BGCOLOR=#FFFF80><a href=/mp3/tngmp3.exe?subdir=Bonnie%20Tyler><img src=/mp3/folder.gif border=0></A>&nbsp;<a href=/mp3/tngmp3.exe?subdir=Bonnie%20Tyler>Bonnie Tyler</A></TD><TD BGCOLOR=#C0C0FF>    0 kb </TD><TD BGCOLOR=#C0C0FF>05/03/01  03:46 PM</TD></TR>
          ------------------
          Scott
          Scott Turchin
          MCSE, MCP+I
          http://www.tngbbs.com
          ----------------------
          True Karate-do is this: that in daily life, one's mind and body be trained and developed in a spirit of humility; and that in critical times, one be devoted utterly to the cause of justice. -Gichin Funakoshi

          Comment


          • #6
            The duplicate "Style" is because it's in a function called "MakeTNGBBS", I may remove that out and retest...
            SOmething tells me the browser is confused, I understand that TABLE colors take precidence but it appears it is mixing the colors with the STYLE color.
            The table ONLY contains hypertext links, and those are the only one's that are confused.
            The tables that don't contain hypertext links are working correctly...




            ------------------
            Scott
            Scott Turchin
            MCSE, MCP+I
            http://www.tngbbs.com
            ----------------------
            True Karate-do is this: that in daily life, one's mind and body be trained and developed in a spirit of humility; and that in critical times, one be devoted utterly to the cause of justice. -Gichin Funakoshi

            Comment


            • #7
              To do it the way Mr. Hanlin suggested, you would need to do
              Left$(Hex$(ColorValue,8),6). It seems Hex goes from Right to
              Left. If you have &H00FFFF80 or 16777088 you get:
              Hex$(16777088, 6) FFFF80
              Hex$(16777088, 8) 00FFFF80

              As a side note, the earlier routine I posted was from some
              VB code I did a while back. VB's Hex function isn't as
              Smart as PB's. Hence creating the long routine I posted
              earlier.

              Mark


              ------------------

              Comment


              • #8
                I believe you are right, because no matter how I do it blue comes up pink...and vice versa.

                I'll give that a shot, gonna be tied up for a few days so I may post a new one sunday evening...

                Thanks!

                Scott

                ------------------
                Scott
                Scott Turchin
                MCSE, MCP+I
                http://www.tngbbs.com
                ----------------------
                True Karate-do is this: that in daily life, one's mind and body be trained and developed in a spirit of humility; and that in critical times, one be devoted utterly to the cause of justice. -Gichin Funakoshi

                Comment


                • #9
                  What does the RGB built in PB function do exactly?

                  Would it do what I need done here?


                  Scott

                  ------------------
                  Scott
                  Scott Turchin
                  MCSE, MCP+I
                  http://www.tngbbs.com
                  ----------------------
                  True Karate-do is this: that in daily life, one's mind and body be trained and developed in a spirit of humility; and that in critical times, one be devoted utterly to the cause of justice. -Gichin Funakoshi

                  Comment


                  • #10
                    PS, THIS WORKS AWESOME!!!

                    With one exception that when entering the color picker it shows theREVERSE color that it used to show on the web page.

                    How do I convert DARK BLUE for example, so that when I ENTER the Color Picker it knows to go to that color.
                    Current dark Blue is #000080 (Navy blue)

                    It shows up as black or pink...

                    I have the extended colors extended automatically, cca.Flags = %CC_RGBINIT Or %CC_FULLOPEN Or %CC_ANYCOLOR ,


                    So....almost there... I don't quite understand but I do understand that each two digits is a %red,%green,%blue hex form....



                    Scott

                    [This message has been edited by Scott Turchin (edited May 11, 2001).]
                    Scott Turchin
                    MCSE, MCP+I
                    http://www.tngbbs.com
                    ----------------------
                    True Karate-do is this: that in daily life, one's mind and body be trained and developed in a spirit of humility; and that in critical times, one be devoted utterly to the cause of justice. -Gichin Funakoshi

                    Comment


                    • #11
                      Scott, maybe the same problem I had awhile back, Semen helped me out with this one.

                      What the choose color dialog returns is BGR, not RGB. The PB RGB function will convert
                      the 3 parameters to BGR format.

                      In the code fragment below, I store a text based color as RGB, so I have
                      to reverse the order returned from the choose color dialog.

                      Code:
                          'First check for the Choose Color dialog...
                          IF pItem(curSel).nItemType = %PIT_COLOR  THEN
                        
                              currClr = pItem(curSel).curValue
                        
                              IF  currClr > "" THEN
                       
                                  'parse the property's current color value
                                  d$  = ","
                                  currClr = LTRIM$(currClr,"RGB(")
                                  currClr = RTRIM$(currClr,")")
                                  rv%     = VAL(Parse$(currClr,d$,1))
                                  gv%     = VAL(Parse$(currClr,d$,2))
                                  bv%     = VAL(Parse$(currClr,d$,3))
                       
                                  initClr = RGB(rv%,gv%,bv%)
                              ELSE
                                  'use a default instead
                                  initClr = RGB( 255,128,128 )
                              END IF
                       
                              ColorSpec.lStructSize  = LEN(ColorSpec)
                              ColorSpec.hwndOwner    = ghList
                              ColorSpec.lpCustColors = VARPTR(cColor(0))
                              ColorSpec.rgbResult    = initClr
                              ColorSpec.Flags        = ColorSpec.Flags OR %CC_RGBINIT
                       
                              lResult = ChooseColor(ColorSpec)
                       
                              IF lResult = 0 THEN 'check if user cancelled dialog ?
                                 EXIT SUB
                              ELSE
                       
                                  clrStr = HEX$(ColorSpec.rgbResult,6)
                       
                                  'Use Fomrat here, STR$ adds a leading space I don't want
                                  rv$ = FORMAT$(VAL("&H"+MID$(clrStr, 1,2)),",")
                                  gv$ = FORMAT$(VAL("&H"+MID$(clrStr, 3,2)),",") + ","
                                  bv$ = FORMAT$(VAL("&H"+MID$(clrStr, 5,2)),",") + ","
                       
                                  'Note order of RGB, COLORREF 0x00bbggrr
                                  clrStr = "RGB("+bv$+gv$+rv$+")"
                                  pItem(curSel).curValue = clrStr
                      HTH
                      Regards,
                      Jules
                      Best regards
                      Jules
                      www.rpmarchildon.com

                      Comment


                      • #12
                        Hmmm...

                        Scott, You must have been reading my crystal ball while I was typing.

                        Regarding setting the default color before calling Choose Color dialog, see code
                        fragment above, it has that too.

                        Regards,
                        Jules

                        [This message has been edited by Jules Marchildon (edited May 11, 2001).]
                        Best regards
                        Jules
                        www.rpmarchildon.com

                        Comment


                        • #13
                          Thanks, this is becoming more clear (not so muddy)...

                          However, Open any web page and look at a color, ie #000080 and lets say that color is the one I am sending to the function...

                          How do I convert THAT format (String, may or may not have zero's in it) to the RGB long??

                          It's a formatting issue at this point, but I'm confused and it's friday and I want to go home hehe...

                          The Color picker actually SHOWS the value too, so I know that HTML colors are the color pickers colors in those boxes...

                          The blue there is 0,0,128

                          So far so good....

                          Scott

                          ------------------
                          Scott
                          Scott Turchin
                          MCSE, MCP+I
                          http://www.tngbbs.com
                          ----------------------
                          True Karate-do is this: that in daily life, one's mind and body be trained and developed in a spirit of humility; and that in critical times, one be devoted utterly to the cause of justice. -Gichin Funakoshi

                          Comment


                          • #14
                            Got it, Thanks Jules...
                            I modified it shortly, easier way to do it:

                            Code:
                            '------------------------------------------------------------------------------------------
                            Function GetColorSelection(hWnd As Long,ByVal CurrentColor As String) As String
                            Local ColorValue    As Long
                            Local sTmp          As String
                            Local RGBRed        As Long
                            Local RGBGreen      As Long
                            Local RGBBlue       As Long
                            Local RGBColor      As Long
                            Local lLoop         As Long
                            CurrentColor = Remove$(CurrentColor,"#")
                            For lLoop = 6 To 1 Step -1
                                sTmp = sTmp & Mid$(CurrentColor,lLoop,1)
                            Next
                            ColorValue = SelectColor(hWnd,Val("&h" & sTmp))
                            If IsFalse ColorValue Then
                                Function = "#" & CurrentColor
                            Else
                                RGBRed = ColorValue And &HFF
                                RGBGreen = ((ColorValue And &H100FF00) / &H100)
                                RGBBlue = (ColorValue And &HFF0000) / &H10000
                                Function = "#" & Right$("0" & Hex$(RGBRed),2) & Right$("0" & Hex$(RGBGreen),2) & Right$("0" & Hex$(RGBBlue),2)
                            End If
                            End Function
                            '-----------------------------------------------------------------------------------------
                            
                            Function SelectColor(ByVal hParent As Long, ByVal iStartColor As Long) As Long
                              Local cca As ChooseColorApi
                              Dim ccTemp(16) As Static Dword
                              Local sTmp As String
                              Local InitClr As Long
                            
                              cca.hinstance    = 0
                              cca.lStructSize  = SizeOf(cca)
                              cca.lpCustColors = VarPtr(ccTemp(0))  '<-- !!
                              cca.Flags        = %CC_RGBINIT Or %CC_FULLOPEN Or %CC_ANYCOLOR
                              cca.hwndowner    = hParent
                              cca.rgbResult    = iStartColor
                            
                              If ChooseColor(cca) Then Function = cca.rgbResult
                            
                            End Function
                            ------------------
                            Scott
                            Scott Turchin
                            MCSE, MCP+I
                            http://www.tngbbs.com
                            ----------------------
                            True Karate-do is this: that in daily life, one's mind and body be trained and developed in a spirit of humility; and that in critical times, one be devoted utterly to the cause of justice. -Gichin Funakoshi

                            Comment

                            Working...
                            X