Announcement

Collapse
No announcement yet.

Transparent Background for Radio Button?

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

  • Transparent Background for Radio Button?

    Does anyone know how to make the background of a radio button transparent? I need to put a radio button on a textured background but I don't want the rectangle to show up around the actual button. Thanks in advance!

    Scott
    Scott Wolfington
    [url="http://www.boogietools.com"]http://www.boogietools.com[/url]

  • #2
    Scott;

    You need to use the %WS_EX_TRANSPARENT extended style for the radio buttons.

    You need to use CreateWindowEX (API) rather than just CreateWindow, to use an extended style.

    DDT supports extended styles as well.

    Since you are an XXXXX (Dreaded E word to some) user, you can use EZ_ControlEX just like CreateWindowEx to do the same.

    As far as I know, the %WS_EX_TRANSPARENT extended style can be used with most controls. If I am wrong about this, maybe someone who does know can comment on this.


    ------------------
    Chris Boss
    Computer Workshop
    Developer of "EZGUI"
    http://cwsof.com
    http://twitter.com/EZGUIProGuy

    Comment


    • #3
      %WS_EX_TRANSPARENT is not listed in the PB/DLL Help File as a valid style for CONTROL ADD OPTION, so you'll probably have to use CONTROL ADD "classname" to create it "manually".

      ------------------
      Perfect Sync: Perfect Sync Development Tools
      Email: mailto:[email protected][email protected]</A>

      "Not my circus, not my monkeys."

      Comment


      • #4
        Eric --
        I tried
        Control Add "Button", hDlg, %ID_Button, "Testbutton", 10, 70, 80, 15, _
        %WS_VISIBLE Or %WS_CHILD Or %BS_AUTORADIOBUTTON, %WS_EX_TRANSPARENT

        No success. So, let's wait Chris' definition of styles.

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

        Comment


        • #5
          Actually I spoke too soon. Add this case to your sample program...

          Code:
                          Case 1
                              SetBkColor CbWparam, &H80C0FF
                              Function = BrushLtBr
          ...after the Case %ID_Label1 block, and you'll get the desired results. But it does not depend on WS_EX_TRANSPARENT. You can eliminate that.

          -- Eric

          ------------------
          Perfect Sync: Perfect Sync Development Tools
          Email: mailto:[email protected][email protected]</A>



          [This message has been edited by Eric Pearson (edited March 09, 2000).]
          "Not my circus, not my monkeys."

          Comment


          • #6
            What about a null brush?

            WM_SETCOLOR or the 'WM_colorstatic's' etc..

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

            Comment


            • #7
              Eric --
              Nice, very simple solution
              So, I post final variant

              Code:
              #Compile Exe
              #Register None
              
              #Include "Win32Api.Inc"
              
              %ID_Label1 =  101
              %ID_Label2 =  102
              %ID_Text1 = 201
              %ID_Button = 301
              
              Global hDlg&
              
              CallBack Function hDlg_CB()
                 Dim BrushLtBr As Static Long, BrushWhite As Static Long, BrushBlue As Static Long
              
                 Select Case CbMsg
                    Case %WM_INITDIALOG
                       Local Lb As LOGBRUSH
                       Lb.lbStyle = %BS_SOLID
                       Lb.lbColor = &H80C0FF: BrushLtBr = CreateBrushIndirect(Lb)
                       Lb.lbColor = %White  : BrushWhite = CreateBrushIndirect(Lb)
                       Lb.lbColor = %Blue   : BrushBlue = CreateBrushIndirect(Lb)
                       Function = %TRUE
              
                    Case %WM_DESTROY
                       DeleteObject BrushLtBr
                       DeleteObject BrushWhite
                       DeleteObject BrushBlue
              
                    Case %WM_CTLCOLORDLG ' Return the handle of the dialog background brush.
                       Function = BrushLtBr
              
                    Case %WM_CTLCOLORSTATIC, %WM_CTLCOLOREDIT
                       Select Case GetDlgCtrlId(CbLparam)
                          Case %ID_Text1
                             SetTextColor CbWparam, %Blue
                             SetBkColor CbWparam, %White
                             Function = BrushWhite
              
                          Case %ID_Label1
                             SetBkMode CbWparam, %TRANSPARENT
                             SetTextColor CbWparam, &H80
                             Function = BrushLtBr
                          Case %ID_Label2
                             SetTextColor CbWparam, %White
                             SetBkColor CbWparam, %Blue
                             Function = BrushBlue
                          Case %ID_BUTTON
                             SetBkColor CbWparam, &H80C0FF
                             SetTextColor CbWparam, %Blue
                             Function = BrushLtBr
                          End Select
                 End Select
              End Function
              
              Function PbMain ()
                Dialog New 0 ,"Test",0,0, 105, 90, %DS_CENTER Or %WS_OVERLAPPEDWINDOW To hDlg
                Control Add Label, hDlg, %ID_Label1, "Very important", 10, 5, 80, 10, %SS_RIGHT
                Control Add TextBox, hDlg, %ID_Text1,"1. Not nice" + $CRLF + "2. Colors, fonts" + $CRLF + "3. Pardon", 9, 35, 82, 30, %ES_WANTRETURN Or %ES_MULTILINE Or %ES_READONLY, %WS_EX_CLIENTEDGE
                Control Add Option, hDlg, %ID_Button, "Testbutton", 10, 70, 80, 15
                Dialog Show Modal hDlg, Call hDlg_CB
              
              End Function
              [This message has been edited by Semen Matusovski (edited March 10, 2000).]

              Comment


              • #8
                I looked up several examples and they all use a hollow brush, same as null brush for any control on a dialog to allow any type
                of back ground to bleed thru.(in the case you have a bitmap for a background you need to do it this way for some controls otherwise controls like lables and radio buttons would look silly on a bitmap background)


                Regards, Jules

                [This message has been edited by Jules Marchildon (edited March 09, 2000).]

                Comment


                • #9
                  A problem with using a hollow/null brush with static (LABEL) controls occurs if you want to change the text at runtime - the control does not repaint correctly - the solution in this instance is to kill the control and recreate it with the new text. DDT makes this little chore very easy however.


                  ------------------
                  Lance
                  PowerBASIC Support
                  mailto:[email protected][email protected]</A>
                  Lance
                  mailto:[email protected]

                  Comment


                  • #10
                    If you want to achieve the ultimate transparency effect that
                    will work on any background, you should handle all the paint
                    process yourself, building a black and white XOR mask on the fly.
                    It is how things are done within the "WinLIFT Skin Engine".

                    For small surface you can also achieve nice translucency effect
                    "a la Win2K" mixing pixels together, using this:

                    Code:
                    FUNCTION GetBValue?(BYVAL nColor&) EXPORT
                      DIM F AS INTEGER
                      ! mov AL, Byte Ptr nColor&[2]
                      ! xor AH, AH
                      ! mov F, AX
                      FUNCTION = CBYT(F)
                    END FUNCTION
                    
                    FUNCTION GetGValue?(BYVAL nColor&) EXPORT
                      DIM F AS INTEGER
                      ! mov AL, Byte Ptr nColor&[1]
                      ! xor AH, AH
                      ! mov F, AX
                      FUNCTION = CBYT(F)
                    END FUNCTION
                    
                    FUNCTION GetRValue?(BYVAL nColor&) EXPORT
                      DIM F AS INTEGER
                      ! mov AL, Byte Ptr nColor&[0]
                      ! xor AH, AH
                      ! mov F, AX
                      FUNCTION = CBYT(F)
                    END FUNCTION
                    
                    ' Compute the resulting RGB for the translucid pixel
                    FUNCTION skTransRGB&(BYVAL hDC1&, BYVAL x1&, BYVAL y1&, BYVAL hDC2&, BYVAL x2&, BYVAL y2&, BYVAL Percent&) EXPORT
                        
                      ' Get the color of the first picture and extract the r&,g&,b& values
                        Colr1& = GetPixel(hDC1&, x1&, y1&)
                        r1& = GetRValue(Colr1&)
                        b1& = GetBValue(Colr1&)
                        g1& = GetGValue(Colr1&)
                           
                      ' Get the color of the second picture and extract the r&,g&,b& values
                        Colr2& = GetPixel(hDC2&, x2&, y2&)
                        r2& = GetRValue(Colr2&)
                        b2& = GetBValue(Colr2&)
                        g2& = GetGValue(Colr2&)
                    
                      ' Mix the colors based on the specified percent& to create a new color
                      ' that's a perfect combination of the previous two
                        r& = (((100 - percent&) * r1&) + (percent& * r2&)) \ 100
                        g& = (((100 - percent&) * g1&) + (percent& * g2&)) \ 100
                        b& = (((100 - percent&) * b1&) + (percent& * b2&)) \ 100
                        
                        FUNCTION = RGB(r&, g&, b&)
                            
                    END FUNCTION
                    ------------------
                    Patrice Terrier
                    mailto[email protected][email protected]</A>

                    [This message has been edited by Patrice Terrier (edited March 10, 2000).]
                    Patrice Terrier
                    www.zapsolution.com
                    www.objreader.com
                    Addons: GDImage.DLL 32/64-bit (Graphic library), WinLIFT.DLL 32/64-bit (Skin Engine).

                    Comment


                    • #11
                      Scott;

                      I did some research with the MSDN CD and it turns out that the %WS_EX_TRANSPARENT style isn't strongly recommended. I did some testing and it seems the standard windows controls "don't" process this style (except for the Groupbox (Frame) control).

                      The generic Window created with your own class using CreateWindowEx does though !

                      The MS docs seem to imply the transparent style was added for such things as "creating hotspots" and for transparent windows to be used over controls (in a Dialog Editor) so you can display "other" things (like those corner blocks (sizing grips) on a selected control in a Dialog editor).

                      The MS docs basically say that the transparent window style feature is "not fully" implimented in Windows, for example don't try to move a transparent window around, since it will not "repaint" correctly. I found this out in XXXXX (Dreaded E word) when I used the style with the groupbox control and they were moved around in my Visual Designer. I had to do some special processing to get it to repaint correctly.



                      ------------------
                      Chris Boss
                      Computer Workshop
                      Developer of "EZGUI"
                      http://cwsof.com
                      http://twitter.com/EZGUIProGuy

                      Comment


                      • #12
                        Jules --

                        > in the case you have a bitmap for a background

                        It isn't necessary to use a hollow brush for that, because Windows handles that automatically in most cases. If you supply the handle to the "bitmap brush" (instead of a solid brush) Windows will automatically use the appropriate section of the bitmap, depending on where it is being displayed, instead of always using the top-left corner section of the bitmap as you might expect.

                        -- Eric


                        ------------------
                        Perfect Sync: Perfect Sync Development Tools
                        Email: mailto:[email protected][email protected]</A>

                        "Not my circus, not my monkeys."

                        Comment


                        • #13
                          Eric, thank you for taking the time to explain these details. I have read most of your replies
                          in all the forums and I just want to say I appreciate all the help (and your humor) you have given to all of us.

                          Have a great weekend!
                          Regards, Jules

                          Comment

                          Working...
                          X