Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Is there anyway to make a checkbox transparent?

444 views
Skip to first unread message

Paul Sneddon

unread,
Nov 12, 2001, 10:53:09 PM11/12/01
to
I have completed GroupBox and Pagecontrol components which work properly
under XP and are theme aware. The Checkbox and Radiobuttons are theme aware
already but also still draw the clBtnface background, why??? and how do I
override it.

I've tried all the usual methods.

Reagrds,
Paul


serge gubenko

unread,
Nov 13, 2001, 1:43:59 AM11/13/01
to

"Paul Sneddon" <psne...@blueyonder.co.uk> wrote in message
news:3bf0993d_1@dnews...

Hi, Paul

In order to make a check box transparent, you should include
WS_EX_Transparent constant to the extended window style
and try to draw caption on your own. Example of how you can
do it, is listed below.

Best regards, Serge Gubenko
__________________________________________________
type
TMyCheckBox = class(TCheckBox)
protected
procedure CNDrawItem(var Message: TWMDrawItem); message CN_DRAWITEM;
procedure CreateParams(var Params: TCreateParams); override;
procedure CreateWnd; override;
procedure SetButtonStyle;
end;

{=====================================================}

procedure TMyCheckBox.CNDrawItem(var Message: TWMDrawItem);
var
XCanvas: TCanvas;
XCaptionRect, XGlyphRect: TRect;

procedure xxDrawBitMap(ACanvas: TCanvas);
const
xx_h =13; xx_w = 13;
var
xxGlyph: TBitmap;
xxX, xxY, xxStepY, xxStepX: integer;
begin
xxGlyph:=TBitmap.Create;
try
xxGlyph.Handle:=LoadBitmap(0, PChar(OBM_CHECKBOXES));
xxY:=XGlyphRect.Top + (XGlyphRect.Bottom - XGlyphRect.Top - xx_h)
div 2;
xxX:=2;
xxStepX:=0; xxStepY:=0;
case State of
cbChecked: xxStepX:=xxStepX + xx_w;
cbGrayed: xxStepX:=xxStepX + xx_w*3;
end;
ACanvas.CopyRect(Rect(xxX, xxY, xxX+xx_w, xxY+xx_h),
xxGlyph.Canvas,
Rect(xxStepX, xxStepY, xx_w+xxStepX, xx_h+xxStepY));
finally
xxGlyph.Free;
end;
end;

procedure xxDrawCaption;
var
xXFormat: longint;
begin
xXFormat:=DT_VCENTER + DT_SINGLELINE + DT_LEFT;
xXFormat:=DrawTextBiDiModeFlags(xXFormat);
DrawText(Message.DrawItemStruct.hDC, PChar(Caption),
length(Caption), XCaptionRect, xXFormat);
end;
begin
XGlyphRect:=Message.DrawItemStruct.rcItem;
XGlyphRect.Right:=20;
XCaptionRect:=Message.DrawItemStruct.rcItem;
XCaptionRect.Left:=XGlyphRect.Right;

XCanvas:=TCanvas.Create;
try
XCanvas.Handle:=Message.DrawItemStruct.hDC;
XCanvas.Brush.Style:=bsClear;
xxDrawBitMap(XCanvas);
xxDrawCaption;
finally
XCanvas.Free;
end;
end;

procedure TMyCheckBox.CreateParams(var Params: TCreateParams);
begin
inherited CreateParams(Params);
Params.ExStyle:=Params.ExStyle or WS_EX_Transparent;
end;

procedure TMyCheckBox.CreateWnd;
begin
inherited CreateWnd;
SetButtonStyle;
end;

procedure TMyCheckBox.SetButtonStyle;
const
BS_MASK = $000F;
var
Style: Word;
begin
if HandleAllocated then begin
Style:=BS_CHECKBOX or BS_OWNERDRAW;
if GetWindowLong(Handle, GWL_STYLE) and BS_MASK <> Style
then SendMessage(Handle, BM_SETSTYLE, Style, 1);
end;
end;


Paul Sneddon

unread,
Nov 13, 2001, 4:23:45 PM11/13/01
to
Thanks again, you have been extremely helpful. All I need to do now is add
support for all the new checkbox states, add support for Windows XP, remove
the unneeded code and hopefully I will have a transparent Windows XP
compatible checkbox to put on my Windows XP compatible groupbox and
pagecontrol.

Thanks again

Regards,
Paul

"serge gubenko" <serge_...@yahoo.com> wrote in message
news:3bf0c167_2@dnews...

Paul Sneddon

unread,
Nov 13, 2001, 4:57:59 PM11/13/01
to
How can I speed up how reactive the checkbox is to my mouse clicks, i have
to wait over half a second before I can click again, as it doesn't register
my clicks.

Regards,
Paul


serge gubenko

unread,
Nov 14, 2001, 1:15:45 AM11/14/01
to

"Paul Sneddon" <psne...@blueyonder.co.uk> wrote in message
news:3bf19762_1@dnews...

Hi, Paul

Add

ControlStyle:=ControlStyle - [csDoubleClicks];

line to the constructor:

constructor TMyCheckBox.Create(AOwner: TComponent);
begin
inherited Create(AOwner);
ControlStyle:=ControlStyle - [csDoubleClicks];
end;

regards

Paul Sneddon

unread,
Nov 14, 2001, 3:48:56 PM11/14/01
to
Hi, Serge, I've got one more question for you,

I have my control working fine, exactly like the Windows XP common
control....apart from one thing.

My OnMouseEnter message handler does not trigger if I enter the control with
a mouse button pressed, how do I fix this. Is it another flag I have to
set.

Also can anyone tell me what the MIXED property is for, I know what it does
but then would I have to use it and do I need to add support for it into my
control on will it be inherited.

Thanks once more

Regards,
Paul
"serge gubenko" <serge_...@yahoo.com> wrote in message

news:3bf20c4d_1@dnews...

serge gubenko

unread,
Nov 15, 2001, 5:17:42 AM11/15/01
to
Hi, Paul

>
> My OnMouseEnter message handler does not trigger if I enter the control
with
> a mouse button pressed, how do I fix this. Is it another flag I have to
> set.
>

One reason I know is that the mouse is captured. Try to remove
csCaptureMouse constant from the ControlStyle of the form (or
from control on which mouse was pressed).

Best regards, Serge Gubenko


0 new messages