You are not logged in. You can browse in the PowerBASIC Community, but you must click Login (top right) before you can post. If this is your first visit, check out the FAQ or Sign Up.
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]
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.
%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".
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.
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).]
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).]
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.
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
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.
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, 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.
We process personal data about users of our site, through the use of cookies and other technologies, to deliver our services, and to analyze site activity. For additional details, refer to our Privacy Policy.
By clicking "I AGREE" below, you agree to our Privacy Policy and our personal data processing and cookie practices as described therein. You also acknowledge that this forum may be hosted outside your country and you consent to the collection, storage, and processing of your data in the country where this forum is hosted.
Comment