whats new ¦  programming tips ¦  indy articles ¦  intraweb articles ¦  informations ¦  links ¦  interviews
 misc ¦  tutorials ¦  Add&Win Game

Tips (1541)

Database (90)
Files (137)
Forms (107)
Graphic (114)
IDE (21)
Indy (5)
Internet / LAN (130)
IntraWeb (0)
Math (76)
Misc (126)
Multimedia (45)
Objects/
ActiveX (51)

OpenTools API (3)
Printing (35)
Strings (83)
System (266)
VCL (242)

Top15

Tips sort by
component


Search Tip

Add new Tip

Add&Win Game

Advertising

44 Visitors Online


 
...get a Bitmap of a TCheckBox?
Autor: Michael
Homepage: http://www.frifra.de
[ Print tip ]  

Tip Rating (3):  
     


{
  Diese Funktion liefert ein Bitmap einer CheckBox.
  Parameter:
  Checked = CheckBox ausgewählt
  Hot = CheckBox aktiv (funktioniert nur unter XP und bewirkt z.B. unter Luna einen hellroten Rand)
  BgColor = Hintergrundfarbe der CheckBox

  Wichtig:
  Die Bitmap sollte nach Ausführung der Funktion wieder freigegeben werden!
  XP-Styles werden erst ab Delphi7 unterstützt.
}


{$IFDEF VER150}

uses
  
Themes;
{$ENDIF}

function GetCheckBoxBitmap(Checked, Hot : boolean; BgColor : TColor): TBitmap;
const
  
CtrlState : array[boolean] of integer = (DFCS_BUTTONCHECK,
    DFCS_BUTTONCHECK or DFCS_CHECKED);
var
  
CBRect : TRect;
  {$IFDEF VER150}
  
Details : TThemedElementDetails;
  {$ENDIF}
  
BgOld : TColor;
  ChkBmp : TBitmap;
  ThemeOK : boolean;
  x, x2, y : integer;
begin
  
Result := nil;
  try
    
Result := TBitmap.Create;
    ChkBmp := TBitmap.Create;
    ThemeOK := False;
    with Result do
    begin
      
Width := 16;
      Height := 16;
      with Canvas do
      begin
        
Brush.Color := BgColor;
        FillRect(ClipRect);
        ChkBmp.Assign(Result);
        CBRect := ClipRect;
        CBRect.Top := 1;
        CBRect.Left := 1;
        {$IFDEF VER150}
        
if ThemeServices.ThemesAvailable then
        begin
          
// ab WinXP
          
if Checked = True then
          begin
            if 
Hot = True then
              
Details := ThemeServices.GetElementDetails(tbCheckBoxCheckedHot)
            else
              
Details :=
                ThemeServices.GetElementDetails(tbCheckBoxCheckedNormal);
          end
          else
          begin
            if 
Hot = True then
              
Details :=
                ThemeServices.GetElementDetails(tbCheckBoxUncheckedHot)
            else
              
Details :=
                ThemeServices.GetElementDetails(tbCheckBoxUncheckedNormal);
          end;
          ThemeServices.DrawElement(Handle, Details, CBRect);
          // Prüfen, ob es tatsächlich geklappt hat (Win2003 liefert leere Images!)
          
for x := 15 downto do
            for 
y := 15 downto do
              if 
ChkBmp.Canvas.Pixels[x, y] <> Pixels[x, y] then
              begin
                
ThemeOK := True;
                break;
              end;
        end;
        {$ENDIF}
        
if ThemeOK = False then
        begin
          
//alles vor WinXP
          
CBRect.Left := ClipRect.Left + 2;
          CBRect.Right := ClipRect.Right - 1;
          CBRect.Top := ClipRect.Top + 2;
          CBRect.Bottom := ClipRect.Bottom - 1;
          DrawFrameControl(Handle, CBRect, DFC_BUTTON, CtrlState[Checked]);
        end;
      end;
    end;
  finally
  end
;
end;

 

Rate this tip:

poor
very good


Copyright © by SwissDelphiCenter.ch
All trademarks are the sole property of their respective owners