Einzelnen Beitrag anzeigen

Benutzerbild von turboPASCAL
turboPASCAL

Registriert seit: 8. Mai 2005
Ort: Sondershausen
4.274 Beiträge
 
Delphi 6 Personal
 
#33

Re: Code strukturieren! Wie macht man es richtig ..

  Alt 12. Okt 2008, 09:21
Delphi-Quellcode:
unit uCheckButton;

interface

uses
  Windows,
  Messages;

// Classes, // ?

type
  TSkinCheckButton = class
  private
    FButtonHandle: HWND;
    Img: Cardinal;
    Style: DWORD;
    UseState: Integer;
  public
    constructor Create(hOwner: HWND; FullpathImageName: PAnsiChar; stLabel: PAnsiChar;
      x, y, xW, yH, ButID: Integer; ARGBColor: COLORREF; StateMax: Integer);
    destructor Destroy; override;

    function GetCheckButtonStatus(hBut: DWORD): Integer;
    procedure SetCheckButtonStatus(hBut: DWORD; TrueFalse: Bool);
  end;

implementation

uses
  uSkin;

function TSkinCheckButton.Create(hOwner: HWND; FullpathImageName,
  stLabel: PAnsiChar; x, y, xW, yH, ButID: Integer; ARGBColor: COLORREF;
  StateMax: 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;

destructor TSkinCheckButton.Destroy;
begin
  UnRegisterButton(SKBUTIMAGE);
  DeleteResource(Img);
  DestroyWiindow(FButtonHandle);

  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.

Vorschlag, frei Schanauzer.
Matti
Meine Software-Projekte - Homepage - Grüße vom Rüsselmops -Mops Mopser
  Mit Zitat antworten Zitat