unit uCheckButton;
interface
uses Windows, Classes, Messages;
type
TSkinCheckButton =
class
private
FButtonHandle: HWND;
Img : Cardinal;
Style : DWORD;
UseState : Integer;
public
constructor Create;
destructor Destroy;
override;
function CheckButton(hOwner: HWND; FullpathImageName:PAnsiChar; stLabel: PAnsiChar;
x, y, xW ,yH ,ButID: Integer; ARGBColor: COLORREF; StateMax: Integer): Integer;
function GetCheckButtonStatus(hBut: DWORD): Integer;
procedure SetCheckButtonStatus(hBut: DWORD; TrueFalse: Bool);
end;
implementation
uses uSkin;
function TSkinCheckButton.CheckButton(hOwner: HWND; FullpathImageName,
stLabel: PAnsiChar; x, y, xW, yH, ButID: Integer; ARGBColor: COLORREF;
StateMax: Integer): Integer;
begin
with SkinEngine
do
begin
if RegisterButton(SKBUTIMAGE) <> 0
then
begin
// Erstelle ein GDIPLUS Image von Datei
Img := AddResource((FullpathImageName));
if Img <> 0
then
Style := WS_CHILD
or WS_VISIBLE
or WS_TABSTOP
or BS_AUTOCHECKBOX;
FButtonHandle := CreateWindowEx(WS_EX_TRANSPARENT, SKBUTIMAGE, stLabel,
Style, x, y, xW, yH, hOwner, ButID, sInstance,
nil);
if FButtonHandle <> 0
then
begin
if StateMax < 1
then StateMax := 2;
// Speichere das Image Handle in die Property
SetImageProperty(FButtonHandle, PROP_IMAGE, Img);
SetImageProperty(FButtonHandle, PROP_STYLE, BS_AUTOCHECKBOX);
SetImageProperty(FButtonHandle, PROP_TEXT_COLOR, ARGBColor);
SetImageProperty(FButtonHandle, PROP_STATEMAX, StateMax);
Result := FButtonHandle;
end else
begin
// Lösche das Image
DeleteResource(Img);
end;
end;
end;
end;
constructor TSkinCheckButton.Create;
begin
//
end;
destructor TSkinCheckButton.Destroy;
begin
//
inherited Destroy;
end;
// Hole den Checkbutton status
function TSkinCheckButton.GetCheckButtonStatus(hBut: DWORD): Integer;
begin
Result := 0;
if SendMessage(hBut, BM_GETCHECK, 0, 0) = BST_CHECKED
then
Result := -1;
end;
// Setze den Checkbutton status
procedure TSkinCheckButton.SetCheckButtonStatus(hBut: DWORD; TrueFalse: Bool);
begin
if TrueFalse
then
UseState := BST_CHECKED
else UseState := BST_UNCHECKED;
SendMessage(hBut, BM_SETCHECK, UseState, 0);
end;
end.