Einzelnen Beitrag anzeigen

EWeiss
(Gast)

n/a Beiträge
 
#12

AW: TInterfacedObject Subclass

  Alt 12. Mär 2011, 04:39
Ich habe aber bemerkt das die ListBox kurz nach dem erstellen wieder zerstört wird
Dann zeig doch mal den Code, der die ListBox erzeugt und wie die Variable deklariert ist, der die erzeugte ListBox zugewiesen wird.
Kein Problem..

Delphi-Quellcode:
type
  ISkinListBox = interface
    ['{38EF3B4F-86A1-45D0-A7F3-4E45E125979D}']
    function GetHandle: hWnd;
    property Handle: hWnd read GetHandle;
    procedure SetFont(nPointSize: Integer; FontName: PAnsiChar; AktForecolor: COLORREF;
      InAktForecolor: COLORREF; Shadow: Boolean; SOffset: Integer; ShadowColor: COLORREF);
  end;

  TSkinListBox = class(TInterfacedObject, ISkinListBox)
  private
    LStyle: DWORD;
    FHOwner: HWND;
    FHandle: HWND;
    FEnumProcInst: Pointer;
    ImgIcon: Cardinal;
    ImgIconH: Cardinal;
    ImgIconW: Cardinal;
    function MakeProcInstance(M: TMethod): Pointer;
    procedure SetCTLFont(hCtL: HWND; Font: hFont);
    procedure SubClass(WinHandle: HWND);
    procedure UnSubClass(WinHandle: HWND);
    function GetHandle: hWnd;
  public
    property Handle: HWND Read FHandle;
    procedure SetFont(nPointSize: Integer; FontName: PAnsiChar; AktForecolor: COLORREF;
      InAktForecolor: COLORREF; Shadow: Boolean; SOffset: Integer; ShadowColor: COLORREF);
    function ListBoxProc(WinHandle: HWND; Msg: UINT; wP: WParam; lP: LParam): LRESULT; stdcall;

    procedure DrawItem(WinHandle: HWND; Dc: Hdc; Index: Integer;Rect: TRect; Selected: Bool);
    procedure InitTrackbar;
    procedure ListSetTopIndex(hList: HWND; nTopIndex: Integer);
    function ListGetTopIndex(hList: HWND): Integer;
    function ListGetSel(hList: HWND; nSelected: Integer): Bool;
    function GetItemHeight(hList: HWND; ItemHeigh: Integer): Integer;
    function ListCount(hList: HWND): Integer;
    procedure ListDeleteAll(hList: HWND);
    procedure ListDelete(hList: HWND; nIndex: Integer);
    procedure ListSelectPlus(hList: HWND; nSelected: Integer);
    function ListFindString(hList: HWND; Tmp: string): Integer;
    function ListGetCurSel(hList: HWND): Integer;
    function ListAdd(hList: HWND; Tmp: string): Integer;
    function ListGetText(hList: HWND; Item: Integer): PAnsiChar;
    constructor Create(hOwner: HWND; FullpathImageName: string; x, y, xW, yH,
      ListID: integer; Visible: Boolean; ItemHeight: Integer; BackColor: COLORREF);
    destructor Destroy; override;
  end;

type
  LBTYPE = Record
    AktForecolor : COLORREF;
    InAktForecolor : COLORREF;
    Backcolor : COLORREF;
    Shadow : Boolean;
    ShadowColor : COLORREF;
    ShadowOffset : Integer;
    ForeColorSelected : COLORREF;
    BackColorSelected : COLORREF;
    PointSize : Integer;
    DrawStyle : Integer;
    BorderStyle : Integer;
    Icon : string;
    ItemHeight : Integer;
    Handle : HWND;
    Left : Integer;
    Top : Integer;
    Width : Integer;
    Height : Integer;
    Font : HFONT;
  end;
Delphi-Quellcode:
constructor TSkinListBox.Create(hOwner: HWND; FullpathImageName: string; x, y, xW, yH,
  ListID: integer; Visible: Boolean; ItemHeight: Integer; BackColor: COLORREF);

begin

  with SkinEngine do
  begin
        // LBS_NOTIFY übergeben ohne wird kein Event
        // auf LBN_DBLCLK ausgelößt
        if Visible = True then
        begin
          LStyle := LBS_HASSTRINGS or LBS_OWNERDRAWFIXED or
                    LBS_NOINTEGRALHEIGHT or LBS_NOTIFY or WS_CHILD or WS_VISIBLE;
        end else
        LStyle := LBS_HASSTRINGS or LBS_OWNERDRAWFIXED or
                  LBS_NOINTEGRALHEIGHT or LBS_NOTIFY or WS_CHILD;

        // Propertys der Listbox festlegen
        ListBoxType.Backcolor := BackColor;
        ListBoxType.ForeColorSelected := GetSysColor(COLOR_HIGHLIGHTTEXT);
        ListBoxType.BackColorSelected := GetSysColor(COLOR_HIGHLIGHT);
        ListBoxType.BorderStyle := EDGE_RAISED;
        ListBoxType.Left := x;
        ListBoxType.Top := y;
        ListBoxType.Width := xW;
        ListBoxType.Height := yH;
        ListBoxType.Icon := FullpathImageName;
        ListBoxType.ShadowColor := (RGB(0,0,0));
        ListBoxType.Shadow:= FALSE;
        ListBoxType.ShadowOffset := 3;
        ListBoxType.ItemHeight := ItemHeight;

        // ListBox erstellen
        FHandle := CreateWindowEx(WS_EX_TRANSPARENT,
          SKLISTBOX, nil, LStyle, ListBoxType.Left, ListBoxType.Top, ListBoxType.Width, ListBoxType.Height,
          hOwner, ListID, skInstance, nil);

        if FHandle <> 0 then
        begin
          ListBoxType.Handle := FHandle;
          SendMessage(Handle, LB_SETITEMHEIGHT, 0, ListBoxType.ItemHeight);

          ListBoxType.DrawStyle := CreateSolidBrush(ListBoxType.Backcolor);
          FHOwner := hOwner;
          SubClass(FHOwner);
        end;
  end;
end;

gruss
  Mit Zitat antworten Zitat