求 带背景的 LISTVIEW 例子 (100分)

  • 主题发起人 主题发起人 lgc_70
  • 开始时间 开始时间
L

lgc_70

Unregistered / Unconfirmed
GUEST, unregistred user!
1:LISTVIEW带背景 不闪烁
2:报表或 ICON 为透明
3:背景不随滚动条移动
从原码空间下的 在赤火上修改的"EXTLISTVIEW"在D6上安装后总是提示地址错误有谁
能解决150分送 急用!!!!!!!!!!
 
把错误贴上来!
 
这是控件的代码
我装在D6上只要想窗体放控件提示"access violation at address 039cbff5 .write of address ae400b43" 地址点以下变换另一个地址. 帮忙解决一下
unit ExtListView;

interface

uses
// 太多无用的,不想繁啦,都加上吧!
Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
StdCtrls, ComCtrls, ExtCtrls, CommCtrl;

type
TExtListView = class(TCustomListView)
private

FBitMap: TPicture;
FInterDrawing: boolean;
FFlag: Boolean;
FHOffer:Integer;


procedure PaintBei;
procedure SetBitMap(Value: TPicture);


procedure WMPaint(var Message: TWMPaint); message WM_PAINT;
procedure WMEraseBkgnd(var Message:TMessage);message WM_ERASEBKGND;
procedure WMNotify(var Message: TMessage);message WM_NOTIFY;
procedure WMHscroll(var Message:TMessage);message WM_HSCROLL;

protected
// 消息响应,可根据自己的情况进行增加!
// 增加的越多,系统资源占用越多!
// 增加数据时,最好使用BeginUpdate.......EndUpdate

procedure WndProc(var Message: TMessage); override;
public
constructor Create(AOwner: TComponent); override;
destructor Destroy; override;
published

// property Background: TPicture read FBitmap write SetBitMap;
// property IsGrid:Boolean read FIsGrid write SetIsGridLine;


property Action;
property Align;
property AllocBy;
property Anchors;
property Background: TPicture read FBitmap write SetBitMap;
property BevelEdges;
property BevelInner;
property BevelOuter;
property BevelKind default bkNone;
property BevelWidth;
property BiDiMode;
property BorderStyle;
property BorderWidth;
property Checkboxes;
property Color;
property Columns;
property ColumnClick;
property Constraints;
property Ctl3D;
property DragCursor;
property DragKind;
property DragMode;
property Enabled;
property Font;
property FlatScrollBars;
property FullDrag;
property GridLines;
property HideSelection;
property HotTrack;
property HotTrackStyles;
property HoverTime;
property IconOptions;
property Items;
property LargeImages;
property MultiSelect;
property OwnerData;
property OwnerDraw;
property ReadOnly default False;
property RowSelect;
property ParentBiDiMode;
property ParentColor default False;
property ParentFont;
property ParentShowHint;
property PopupMenu;
property ShowColumnHeaders;
property ShowWorkAreas;
property ShowHint;
property SmallImages;
property SortType;
property StateImages;
property TabOrder;
property TabStop default True;
property ViewStyle;
property Visible;
property OnAdvancedCustomDraw;
property OnAdvancedCustomDrawItem;
property OnAdvancedCustomDrawSubItem;
property OnChange;
property OnChanging;
property OnClick;
property OnColumnClick;
property OnColumnDragged;
property OnColumnRightClick;
property OnCompare;
property OnContextPopup;
property OnCustomDraw;
property OnCustomDrawItem;
property OnCustomDrawSubItem;
property OnData;
property OnDataFind;
property OnDataHint;
property OnDataStateChange;
property OnDblClick;
property OnDeletion;
property OnDrawItem;
property OnEdited;
property OnEditing;
property OnEndDock;
property OnEndDrag;
property OnEnter;
property OnExit;
property OnGetImageIndex;
property OnGetSubItemImage;
property OnDragDrop;
property OnDragOver;
property OnInfoTip;
property OnInsert;
property OnKeyDown;
property OnKeyPress;
property OnKeyUp;
property OnMouseDown;
property OnMouseMove;
property OnMouseUp;
property OnResize;
property OnSelectItem;
property OnStartDock;
property OnStartDrag;

end;

procedure Register;

implementation

procedure Register;
begin
RegisterComponents('Samples', [TExtListView]);
end;


constructor TExtListView.Create(AOwner: TComponent);
begin
inherited;
FBitmap:=TPicture.Create;
FHOffer:=0;
FFlag:=False;
end;

destructor TExtListView.Destroy;
begin
FBitmap.Free;
inherited;
end;

procedure TExtListView.PaintBei;
var
ps: PAINTSTRUCT;
Rect:TRect;
DC, drawDC1, drawDC2: HDC;
drawBMP1, drawBMP2, oldBMP1, oldBMP2: HBitmap;
iWidth, iHeight, ibmpWidth, ibmpHeight, I, J, K, W: integer;
ACanvas:TCanvas;
begin
// 避免

if Assigned(BackGround) then begin
FInterDrawing := True;
// 加个try!
try

BeginPaint(Handle, Ps);
// 再加一个try,嘿嘿!
try
DC := Ps.hdc;
iWidth := ClientWidth;
iHeight := ClientHeight;

drawDC1 := CreateCompatibleDC(DC);
drawBMP1 := CreateCompatibleBitmap(DC, iWidth, iHeight);
oldBMP1 := SelectObject(drawDC1, drawBMP1);
ACanvas:=TCanvas.Create;
ACanvas.Handle:=drawDC1;
ACanvas.Brush.Color:=clWindow;
Rect.Left:=0;
Rect.Top:=0;
Rect.Right:=iWidth;
Rect.Bottom:=iHeight;
ACanvas.FillRect(Rect);
SendMessage(Handle, WM_PAINT, drawDC1, 0);

drawDC2 := CreateCompatibleDC(DC);
drawBMP2 := CreateCompatibleBitmap(DC, iWidth, iHeight);
oldBMP2 := SelectObject(drawDC2, drawBMP2);



iBmpWidth := Background.Width;
iBmpHeight := Background.Height;




if (iBmpWidth<>0) and (iBmpHeight<>0) then begin

K := ClientWidth div iBmpWidth;
W := ClientHeight div iBmpHeight;
for I := 0 to K do
for J := 0 to W do
BitBlt(drawDC2, I * iBmpWidth, J * iBmpHeight, iBmpWidth, iBmpHeight, FBitmap.Bitmap.Canvas.Handle, 0, 0, SRCCOPY);
end else
begin
ACanvas.Handle:=drawDC2;
ACanvas.FillRect(Rect);
end;


if Items.Count>0 then

TransparentBlt(drawDC2, 0, 0, iWidth, iHeight, drawDC1, 0, 0, iWidth, iHeight, ColorToRGB(clWindow));





// if GetClipBox(DC,Rect)= NULLREGION then
BitBlt(DC, 0, 0, CLientWidth, ClientHeight, drawDC2, 0, 0, SRCCOPY);
// else
// BitBlt(DC, Rect.Left, Rect.Top, Rect.Right-Rect.Left, Rect.Bottom-Rect.Top, drawDC2, Rect.Left, Rect.Top, SRCCOPY);

SelectObject(drawDC1, oldBMP1);
DeleteObject(drawDC1);
DeleteObject(drawBMP1);
SelectObject(drawDC2, oldBMP2);
DeleteObject(drawDC2);
DeleteObject(drawBMP2);
ACanvas.Free;

finally

EndPaint(Handle, Ps);

end;


finally
FInterDrawing := False;
end;
end else
inherited;
end;

procedure TExtListView.SetBitMap(Value: TPicture);
begin

FBitMap.Assign(Value);
if HandleAllocated then Invalidate;

end;

procedure TExtListView.WMEraseBkgnd(var Message: TMessage);
begin

if not Assigned(BackGround) then inherited;
end;


procedure TExtListView.WMHscroll(var Message: TMessage);
begin
if FFlag=True then
FFlag:=False
else
inherited;

end;

procedure TExtListView.WMNotify(var Message: TMessage);
var HdNotify:PHDNOTIFY;
begin
inherited;
if Assigned(BackGround) then begin
HdNotify:=PHDNOTIFY(message.LParam);
if (HdNotify^.Hdr.code=HDN_ITEMCHANGED) or (HdNotify^.Hdr.code=HDN_ITEMCHANGING) then begin

Columns.Items[HdNotify^.Item].Width:=HdNotify^.PItem^.cxy;
FFlag:=True;

end;
end;
end;

procedure TExtListView.WMPaint(var Message: TWMPaint);
begin
// 条件
if (FBitMap = nil) or FInterDrawing then
begin
inherited

end
else
PaintBei;
end;

procedure TExtListView.WndProc(var Message: TMessage);
var
pDS :PDrawItemStruct;
phd :PHDNotify;
begin
case Message.Msg of
// WM_ERASEBKGND:
// begin

// Message.Result := 1;
// Exit;
// end;
WM_HSCROLL,
WM_VSCROLL,
WM_MOUSEWHEEL,
WM_LBUTTONDOWN,
WM_LBUTTONDBLCLK,
WM_MBUTTONDOWN,
WM_MBUTTONDBLCLK,
WM_KEYUP:
InvalidateRect(Handle, nil, False);
end;
inherited;
end;

end.
 
把其中的构造函数改成如下
constructor TExtListView.Create(AOwner: TComponent);
begin
FBitmap:=TPicture.Create;
inherited;
// FBitmap:=TPicture.Create;
FHOffer:=0;
FFlag:=False;
end;
 
是DFW们不会还是分少 如果分不够可以倾家荡产[:D]
 
Coolcontrcols控件组中的TCoolListView也可以达到这些功能呀??
 
to zhongs
修改后重新安装还是出同样的错误?
原码地址 http://www.playicq.com/dispdocnew.php?id=9910
 
这是给treeview 加背景的,看明白了的话,可以给任何东西加背景

unit MycustomtreeView2;

interface

uses
Windows, Messages, SysUtils, Classes, Controls, ComCtrls,
CommCtrl,Graphics;

type
TMycustomtreeView = class(TTreeView)
private
FInterDrawing: boolean;
FBitMap: TBitMap;
procedure PaintWithBackground;
procedure WMPaint(var Message: TWMPaint); message WM_PAINT;
procedure SetBitMap(const Value: TBitmap);
protected
procedure WndProc(var Message: TMessage); override;
public
property Background: TBitmap read FBitMap write SetBitMap;
end;
type
TMyTreeView = class(TMycustomtreeView)
published
property Align;
property Anchors;
property AutoExpand;
property BevelEdges;
property BevelInner;
property BevelOuter;
property BevelKind default bkNone;
property BevelWidth;
property BiDiMode;
property BorderStyle;
property BorderWidth;
property ChangeDelay;
property Color;
property Ctl3D;
property Constraints;
property DragKind;
property DragCursor;
property DragMode;
property Enabled;
property Font;
property HideSelection;
property HotTrack;
property Images;
property Indent;
property MultiSelect;
property MultiSelectStyle;
property ParentBiDiMode;
property ParentColor default False;
property ParentCtl3D;
property ParentFont;
property ParentShowHint;
property PopupMenu;
property ReadOnly;
property RightClickSelect;
property RowSelect;
property ShowButtons;
property ShowHint;
property ShowLines;
property ShowRoot;
property SortType;
property StateImages;
property TabOrder;
property TabStop default True;
property ToolTips;
property Visible;
property OnAddition;
property OnAdvancedCustomDraw;
property OnAdvancedCustomDrawItem;
property OnChange;
property OnChanging;
property OnClick;
property OnCollapsed;
property OnCollapsing;
property OnCompare;
property OnContextPopup;
property OnCreateNodeClass;
property OnCustomDraw;
property OnCustomDrawItem;
property OnDblClick;
property OnDeletion;
property OnDragDrop;
property OnDragOver;
property OnEdited;
property OnEditing;
property OnEndDock;
property OnEndDrag;
property OnEnter;
property OnExit;
property OnExpanding;
property OnExpanded;
property OnGetImageIndex;
property OnGetSelectedIndex;
property OnKeyDown;
property OnKeyPress;
property OnKeyUp;
property OnMouseDown;
property OnMouseMove;
property OnMouseUp;
property OnStartDock;
property OnStartDrag;
{ Items must be published after OnGetImageIndex and OnGetSelectedIndex }
property Items;

end;

procedure Register;

implementation

procedure Register;
begin
RegisterComponents('Samples', [TMyTreeView]);
end;

//使用了 屏幕上快速显示图象的双缓冲技术.
procedure tMycustomtreeView.PaintWithBackground;
var
ps: PAINTSTRUCT;
DC: HDC;
drawDC1, drawDC2: HDC;
drawBMP1, drawBMP2, oldBMP1, oldBMP2: HBitmap;
iWidth, iHeight, ibmpWidth, ibmpHeight, I, J, K, W: integer;
begin
FInterDrawing := True;
try
BeginPaint(Handle, Ps);
try
DC := Ps.hdc;
iWidth := ClientWidth;
iHeight := ClientHeight;
drawDC1 := CreateCompatibleDC(DC);//创建这个DC的内存映像
drawBMP1 := CreateCompatibleBitmap(DC, iWidth, iHeight);
oldBMP1 := SelectObject(drawDC1, drawBMP1);
SendMessage(Handle, WM_PAINT, drawDC1, 0);//发送WM_PAINT,此时在drawDC1里画了树的节点
drawDC2 := CreateCompatibleDC(DC);//创建这个DC的内存映像
drawBMP2 := CreateCompatibleBitmap(DC, iWidth, iHeight);
oldBMP2 := SelectObject(drawDC2, drawBMP2);
iBmpWidth := Background.Width;
iBmpHeight := Background.Height;
K := ClientWidth div iBmpWidth;
W := ClientHeight div iBmpHeight;
//将画面平铺
for I := 0 to K do
for J := 0 to W do
BitBlt(drawDC2, I * iBmpWidth, J * iBmpHeight, iBmpWidth, iBmpHeight, Background.Canvas.Handle, 0, 0, SRCCOPY);
//将 clwindow 颜色作为透明色复制,因为树里默认为白色,所以把白色作为透明色。
//把 drawDC1 里的节点图象复制到 drawDC2 里
TransparentBlt(drawDC2, 0, 0, iWidth, iHeight, drawDC1, 0, 0, iWidth, iHeight, ColorToRGB(clWindow));
//将“缓冲”drawDC2 里的内容复制给DC
BitBlt(DC, 0, 0, iWidth, iHeight, drawDC2, 0, 0, SRCCOPY);
SelectObject(drawDC1, oldBMP1);
DeleteObject(drawDC1);
DeleteObject(drawBMP1);
SelectObject(drawDC2, oldBMP2);
DeleteObject(drawDC2);
DeleteObject(drawBMP2);
finally
EndPaint(Handle, Ps);
end;
finally
FInterDrawing := False;
end;
end;

procedure tMycustomtreeView.SetBitMap(const Value: TBitmap);
begin
if FBitMap <> Value then
begin
FBitMap := Value;
if HandleAllocated then Invalidate;
end;
end;

procedure tMycustomtreeView.WMPaint(var Message: TWMPaint);
begin
if (FBitMap = nil) or FInterDrawing then
inherited
else
PaintWithBackground;
end;

procedure tMycustomtreeView.WndProc(var Message: TMessage);
begin
case Message.Msg of
WM_ERASEBKGND:
begin
Message.Result := 1;
Exit;
end;
WM_HSCROLL, WM_VSCROLL, WM_MOUSEWHEEL,
WM_LBUTTONDOWN,WM_LBUTTONUP,WM_LBUTTONDBLCLK:
//Force a repaint to keep the bitmap tiles lined up
InvalidateRect(Handle, nil, False);//整个客户区重画
end;
inherited;
end;




end.
 
帮你提提前还是可以的!
 
我就是赤火喔,这个控件化费我太多的时间了,将它放到网上只是让大家看看,我有个API的支持WIN98及2000及,修正后的用到现在好像都没有问题!
需要的话上QQ 73398 吧,我传给你!

过了今天,不候喔!

 
传给你的朋友,请不要在网上传播!
 
最简单、方便的办法就是用 TListView 的 Canvas.Draw 了,完全可以实现你的要求,而且不需要第三方控件!
 
那样的效果一个字"烂"
 
随缘:是吗?我一直用,效果都不错,重要的是一条语句就搞定,简单!
 
to app2001
从那下
 
http://www.aidelphi.com/6to23/docu/coolcontrol.zip
 
哈。。。我收藏它呀。
 
问题解决特别感谢 '随缘'散分
 
不知到怎么加分值 其他的兄弟对不住了,谢谢你的参与
建议大富翁能跟该问题分值[:D]
 

Similar threads

D
回复
0
查看
2K
DelphiTeacher的专栏
D
D
回复
0
查看
2K
DelphiTeacher的专栏
D
D
回复
0
查看
1K
DelphiTeacher的专栏
D
D
回复
0
查看
1K
DelphiTeacher的专栏
D
D
回复
0
查看
1K
DelphiTeacher的专栏
D
后退
顶部