龙
龙之天涯
Unregistered / Unconfirmed
GUEST, unregistred user!
unit Lbtab;
interface
uses
SysUtils,Windows,Messages,Classes,Controls,StdCtrls;
type
EddgTabListboxError = class(Exception);
TddgTabListBox = class(TListBox)
private
FlongestString: Word;
FNumTabStops: Word;
FTabStops: PWORD;
FSizeAfterDel: Boolean;
function GetLBStringLength(S: string): Word;
procedure FindLongestString;
procedure SetScrollLength(s: String);
procedure LBAddString(var Msg: TMessage); message lb_AddString;
procedure LBInsertString(var Msg: TMessage); message lb_InsertString;
procedure LBDeleteString(var Msg: TMessage); message lb_DeleteString;
protected
procedure CreateParams(var Params: TCreateParams); override;
public
constructor Create(AOwner: TComponent); override;
destructor Destroy;override;
procedure SetTabStops(A:array of Word);
published
property SizeAfterDel: Boolean read FSizeAfterDel write FSizeAfterDel default True;
end;
procedure Register;
implementation
uses PixDlg;
procedure Register;
begin
RegisterComponents('DY', [TddgTabListBox]);
end;
constructor TddgTabListBox.Create(AOwner: TComponent );
begin
inherited Create(AOwner);
FSizeAfterDel := True;
GetMem(FTabStops,SizeOf(word) * FNumTabStops);
FTabStops^ := DialogUnitsToPixelsX(32);
end;
destructor TddgTabListBox.Destroy;
begin
inherited Destroy;
end;
procedure TddgTabListBox.SetTabStops(A: array of Word);
var
i: Word;
TempTab: Word;
TempBuf: PWORD;
begin
TempTab := High(A) + 1;
GetMem(TempBuf,SizeOf(A));
Move(A,TempBuf^,SizeOf(A));
for i := 0 to TempTab - 1 do
A := PixelsToDialogUnitsX(A);
if Perform(LB_SETTABSTOPS,TempTab,LongInt(@A)) = 0 then
begin
FreeMem(TempBuf,SizeOf(Word) * TempTab);
raise EddgTabListboxError.Create('设置TAB失败');
end
else begin
FreeMem(FTabStops,SizeOf(Word) * FNumTabStops);
FNumTabStops := TempTab;
FTabStops := TempBuf;
FindLongestString ;
Invalidate;
end;
end;
procedure TddgTabListBox.CreateParams(var Params: TCreateParams);
begin
inherited CreateParams(Params);
Params.Style := Params.Style or LBS_USETABSTOPS or WS_HSCROLL ;
end;
function TddgTabListBox.GetLBStringLength(S: String): Word;
var
Size: Integer;
begin
Canvas.Font := Font;
Result := loWord(GetTabbedTextExtent(Canvas.Handle,PChar(S),StrLen(PChar(S)),FNumTabStops,FTabStops^));
Size := Canvas.TextWidth('X');
Inc(Result,Size);
end;
procedure TddgTabListBox.SetScrollLength(S: String);
var
Extent: Word;
begin
Extent := GetLBStringLength(S);
if Extent> FlongestString then
begin
FlongestString := Extent;
Perform(LB_SETHORIZONTALEXTENT,Extent,0);
end;
end;
procedure TddgTabListBox.LBInsertString(var Msg: TMessage);
begin
inherited;
SetScrollLength(PChar(Msg.LParam));
end;
procedure TddgTabListBox.LBAddString(var Msg: TMessage);
begin
inherited;
SetScrollLength(Pchar(Msg.LParam));
end;
procedure TddgTabListBox.FindLongestString;
var
i: Word;
strg: string;
begin
FlongestString := 0;
for i := 0 to Items.Count - 1 do
begin
strg := Items;
SetScrollLength(strg);
end;
end;
procedure TddgTabListBox.LBDeleteString(var Msg: TMessage);
var
Str: string;
begin
if FSizeAfterDel then
begin
Str := Items[Msg.wParam];
inherited ;
if GetLBStringLength(Str) = FlongestString then
FindLongestString;
end
else
inherited ;
end;
end.
unit Pixdlg;
interface
function DialogUnitsToPixelsX(DlgUnits: Word): Word;
function DialogUnitsToPixelsY(DlgUnits: Word): Word;
function PixelsToDialogUnitsX(PixUnits: Word): Word;
function PixelsToDialogUnitsY(PixUnits: Word): Word;
implementation
uses WinProcs;
function DialogUnitsToPixelsX(DlgUnits: Word): Word;
begin
Result := (DlgUnits * LoWord(GetDialogBaseUnits)) div 4;
end;
function DialogUnitsToPixelsY(DlgUnits: Word): Word;
begin
Result := (DlgUnits * HiWord(GetDialogBaseUnits)) div 8;
end;
function PixelsToDialogUnitsX(PixUnits: Word): Word;
begin
Result := PixUnits * 4 div LoWord(GetDialogBaseUnits);
end;
function PixelsToDialogUnitsY(PixUnits: Word): Word;
begin
Result := PixUnits * 8 div LoWord(GetDialogBaseUnits);
end;
end.
构造函数到底什么情况使用??
interface
uses
SysUtils,Windows,Messages,Classes,Controls,StdCtrls;
type
EddgTabListboxError = class(Exception);
TddgTabListBox = class(TListBox)
private
FlongestString: Word;
FNumTabStops: Word;
FTabStops: PWORD;
FSizeAfterDel: Boolean;
function GetLBStringLength(S: string): Word;
procedure FindLongestString;
procedure SetScrollLength(s: String);
procedure LBAddString(var Msg: TMessage); message lb_AddString;
procedure LBInsertString(var Msg: TMessage); message lb_InsertString;
procedure LBDeleteString(var Msg: TMessage); message lb_DeleteString;
protected
procedure CreateParams(var Params: TCreateParams); override;
public
constructor Create(AOwner: TComponent); override;
destructor Destroy;override;
procedure SetTabStops(A:array of Word);
published
property SizeAfterDel: Boolean read FSizeAfterDel write FSizeAfterDel default True;
end;
procedure Register;
implementation
uses PixDlg;
procedure Register;
begin
RegisterComponents('DY', [TddgTabListBox]);
end;
constructor TddgTabListBox.Create(AOwner: TComponent );
begin
inherited Create(AOwner);
FSizeAfterDel := True;
GetMem(FTabStops,SizeOf(word) * FNumTabStops);
FTabStops^ := DialogUnitsToPixelsX(32);
end;
destructor TddgTabListBox.Destroy;
begin
inherited Destroy;
end;
procedure TddgTabListBox.SetTabStops(A: array of Word);
var
i: Word;
TempTab: Word;
TempBuf: PWORD;
begin
TempTab := High(A) + 1;
GetMem(TempBuf,SizeOf(A));
Move(A,TempBuf^,SizeOf(A));
for i := 0 to TempTab - 1 do
A := PixelsToDialogUnitsX(A);
if Perform(LB_SETTABSTOPS,TempTab,LongInt(@A)) = 0 then
begin
FreeMem(TempBuf,SizeOf(Word) * TempTab);
raise EddgTabListboxError.Create('设置TAB失败');
end
else begin
FreeMem(FTabStops,SizeOf(Word) * FNumTabStops);
FNumTabStops := TempTab;
FTabStops := TempBuf;
FindLongestString ;
Invalidate;
end;
end;
procedure TddgTabListBox.CreateParams(var Params: TCreateParams);
begin
inherited CreateParams(Params);
Params.Style := Params.Style or LBS_USETABSTOPS or WS_HSCROLL ;
end;
function TddgTabListBox.GetLBStringLength(S: String): Word;
var
Size: Integer;
begin
Canvas.Font := Font;
Result := loWord(GetTabbedTextExtent(Canvas.Handle,PChar(S),StrLen(PChar(S)),FNumTabStops,FTabStops^));
Size := Canvas.TextWidth('X');
Inc(Result,Size);
end;
procedure TddgTabListBox.SetScrollLength(S: String);
var
Extent: Word;
begin
Extent := GetLBStringLength(S);
if Extent> FlongestString then
begin
FlongestString := Extent;
Perform(LB_SETHORIZONTALEXTENT,Extent,0);
end;
end;
procedure TddgTabListBox.LBInsertString(var Msg: TMessage);
begin
inherited;
SetScrollLength(PChar(Msg.LParam));
end;
procedure TddgTabListBox.LBAddString(var Msg: TMessage);
begin
inherited;
SetScrollLength(Pchar(Msg.LParam));
end;
procedure TddgTabListBox.FindLongestString;
var
i: Word;
strg: string;
begin
FlongestString := 0;
for i := 0 to Items.Count - 1 do
begin
strg := Items;
SetScrollLength(strg);
end;
end;
procedure TddgTabListBox.LBDeleteString(var Msg: TMessage);
var
Str: string;
begin
if FSizeAfterDel then
begin
Str := Items[Msg.wParam];
inherited ;
if GetLBStringLength(Str) = FlongestString then
FindLongestString;
end
else
inherited ;
end;
end.
unit Pixdlg;
interface
function DialogUnitsToPixelsX(DlgUnits: Word): Word;
function DialogUnitsToPixelsY(DlgUnits: Word): Word;
function PixelsToDialogUnitsX(PixUnits: Word): Word;
function PixelsToDialogUnitsY(PixUnits: Word): Word;
implementation
uses WinProcs;
function DialogUnitsToPixelsX(DlgUnits: Word): Word;
begin
Result := (DlgUnits * LoWord(GetDialogBaseUnits)) div 4;
end;
function DialogUnitsToPixelsY(DlgUnits: Word): Word;
begin
Result := (DlgUnits * HiWord(GetDialogBaseUnits)) div 8;
end;
function PixelsToDialogUnitsX(PixUnits: Word): Word;
begin
Result := PixUnits * 4 div LoWord(GetDialogBaseUnits);
end;
function PixelsToDialogUnitsY(PixUnits: Word): Word;
begin
Result := PixUnits * 8 div LoWord(GetDialogBaseUnits);
end;
end.
构造函数到底什么情况使用??