昨天发帖了 今天还没回音????

esenlite_yu 2008-04-16 03:24:29
DELPHI 什么实现treeview的背景色变透明 高手请进!
哪位同仁知道实现代码帮个忙?
本人刚学D不到一周,谢谢各位!
...全文
216 26 打赏 收藏 转发到动态 举报
写回复
用AI写文章
26 条回复
切换为时间正序
请发表友善的回复…
发表回复
esenlite_yu 2008-04-21
  • 打赏
  • 举报
回复
鄙人 真的搞不定这样的程序了 各位同仁好心的帮个忙!
esenlite_yu 2008-04-18
  • 打赏
  • 举报
回复
代码写了 但有错误!请帮忙看下错误如下:
[Pascal Error] Unit10.pas(39): E2003 Undeclared identifier: 'FormDestroy'
[Pascal Error] Unit10.pas(39): E2029 ';' expected but '(' found
[Pascal Error] Unit10.pas(41): E2003 Undeclared identifier: 'TreeView1'
[Pascal Error] Unit10.pas(41): E2029 'END' expected but ',' found
[Pascal Error] Unit10.pas(42): E2029 ';' expected but 'IF' found
[Pascal Error] Unit10.pas(44): E2029 '.' expected but ';' found
[Pascal Error] Unit10.pas(45): E2003 Undeclared identifier: 'FormCreate'
[Pascal Error] Unit10.pas(47): E2003 Undeclared identifier: 'NewWndproc'
[Pascal Warning] Unit10.pas(47): W1000 Symbol 'MakeObjectInstance' is deprecated
[Pascal Error] Unit10.pas(47): E2003 Undeclared identifier: 'TreeView_WndProc'
[Pascal Error] Unit10.pas(49): E2003 Undeclared identifier: 'OldWndProc'
[Pascal Error] Unit10.pas(49): E2003 Undeclared identifier: 'TreeView1'
[Pascal Error] Unit10.pas(49): E2029 'END' expected but ',' found
[Pascal Error] Unit10.pas(56): E2003 Undeclared identifier: 'WM_ERASEB'
[Pascal Error] Unit10.pas(71): E2003 Undeclared identifier: 'CallWindoeProc'
[Pascal Error] Unit10.pas(71): E2003 Undeclared identifier: 'OldWnd_Proc'
[Pascal Error] Unit10.pas(76): E2029 Statement expected but 'VAR' found
[Pascal Warning] Unit10.pas(81): W1011 Text after final 'END.' - ignored by compiler
[Pascal Error] Unit10.pas(15): E2065 Unsatisfied forward or external declaration: 'TForm10.Image1Click'
[Pascal Error] Unit10.pas(16): E2065 Unsatisfied forward or external declaration: 'TForm10.TreeView2AdvancedCustomDrawItem'
[Pascal Error] Unit10.pas(19): E2065 Unsatisfied forward or external declaration: 'TForm10.TreeView1CustomDraw'
[Pascal Hint] Unit10.pas(22): H2219 Private symbol 'OldWndProc' declared but never used
[Pascal Hint] Unit10.pas(23): H2219 Private symbol 'TreeView_WndProc' declared but never used
[Pascal Fatal Error] Project6.dpr(5): F2063 Could not compile used unit 'Unit10.pas'


代码如下:
unit Unit10;

interface

uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, ComCtrls, ImgList, ExtCtrls;

type
TForm10 = class(TForm)
TreeView1: TTreeView;
TreeView2: TTreeView;
Image1: TImage;
ImageList1: TImageList;
procedure Image1Click(Sender: TObject);
procedure TreeView2AdvancedCustomDrawItem(Sender: TCustomTreeView;
Node: TTreeNode; State: TCustomDrawState; Stage: TCustomDrawStage;
var PaintImages, DefaultDraw: Boolean);
procedure TreeView1CustomDraw(Sender: TCustomTreeView; const ARect: TRect;
var DefaultDraw: Boolean);
private
OldWndProc,NewWndProc:TFarProc;
procedure TreeView_WndProc(var msg: TMessage);
procedure TreeView_DrawBkGnd(Sender: TTreeView);
private
{ Private declarations }
public
{ Public declarations }
end;

var
Form10: TForm10;

implementation

{$R *.dfm}


procedure TForm10.FormDestroy(Sender: TObject);
begin
SetWindowLong (TreeView1.Handle,GWL_WNDPROC,Long Int(OldWndProc));
if New WndProc<>nil then
FreeObjectInstance(NewWndProc);
end;
procedure TForm10.FormCreate(Sender: Tobject);
begin
NewWndproc :=MakeObjectInstance(TreeView_WndProc);
//保留树1原窗口过程
OldWndProc :=Pointer(GetWindowLong(TreeView1.Handle,GWL_WNDPROC));
//设置TREEVIEW1新的窗口过程
SetWindowLong(TreeView1.Handle,GWL_WNDPROC,LongInt(NewWndProc));
end;
procedure TForm10.TreeView_WndProc(var msg: TMessage);
begin
case Msg.Msg of
WM_ERASEB KGND
begin
Msg.Result :=1;
exit;
end;
WM_SIZE,WM_HSCROLL,WM_VSCROLL,WM_LBUTTONDOWN,WM_MOUSEWHEEL:
begin
InvalidateRect(TreeView1.Handle,nil,False);
end;
WM_PAINT:
begin
TreeView_DrawBKGnd(TreeView1);
end;
end;
//其他情况下,调用原窗口过程处理消息
Msg.Result :=CallWindoeProc(OldWnd_Proc,TreeView1.Handle,Msg.Msg,Msg.WParam,Msg.LParam);
end;

procedure TForm10.TreeView_DrawBkGnd(Sender: TTreeView);
begin
var
PS:TPAINTSTRUCT;
DC:HDC;
hMemDC1,hMemDC2:HDC;
hMemBmp1,hMemBmp2,hOldBmp1,hOldBmp2:HBITMAP;
end;
tvWidth,tvHeight,bmpWidth,bmpHeight: integer; i,j,k,w:integer;
Bitmap:TBitmap;
begin
Bitmap := Image1.Picture.Bitmap;
tvWidth :=Sender.ClientWidth;
tvHeight:=Sender.ClientHeight;
try
BeginPaint(Sender.Handle,PS
finally
DC:=PS.hdc; hMemDC1 := CreateCompatibleDC(DC);
hMemBmp1 := CreateCompatibleBitmap(DC,tvWidth,tvHeight);
//建立与设备兼容的位图
hOldBmp1 :=SelectObject(hMemDC1,hMemBmp1);
//调用原窗口过程处理WM-PAINT,让treeview在hmemdc1绘制:前景图:
CallWindowProc(OldWndProc,Sender.Handle,WM_PAINT,hMemDC1,0));
//创立另一临时设备场景
hMemDC2 :=CreateCompatibleDC(DC);
hMemBmp2 := CreateCompatibleBitmamp(DC,tvWidth,tvHeight);
hOldBmp3 := SelectObject(hMemDC2,hMemBmp2);
BmpWidth := Bitmap.Width;
BmpHeight :=Bitmap.Height;
//采用平铺的方法话背景图片
k := tvWidth div BmpWidth;
w := tvHeight div BmpHeight;
for i := 0 to k do
for j := 0 to w do
BitBlt(hMemDC2,i*BmpWidth,j*BmpHeight,BmpWidth,BmpHeight,Bitmap,Canvas.Handle,0,0,SRCOOPY);
StretchBlt(hMemDC2,0,0,tvWidth,tvHeight,bitmap.Canvas.Handle0,0,BmpWidth,BmpHeight,SRCCOPY);
直接借用msimg32.dll提供的函数画透明图比较方便
Transparentblt(hMemDC2,0,0,tvWidth,tvHeight,hMemDC1,0,0,tvWidth,tvHeight,ColorToRGB(Sender.Color)):
BitBlt(DC,0,0,tvWidth,tvHeight,hMemDC2,0,0,SRCCOPY);
SelectObject(hMemDC1,hOldBMP1);
DeleteObject(hMemDC1);
DeleteObject(hMemBmp1);
SelectObject(hMemDC2,hOldBMP2);
DeleteObject(hMemDC2);
DeleteObject(hMemBmp2);
finally
EndPaint(Sender.HandlePS):
end;
end;
procedure TForm10.TreeView2CustomDraw(Sender: TCustomTreeView; const ARect: TRect;
var DefaultDraw: Boolean);
begin
Sender.Canvas.StretchDraw(ARect,Image1.Picture.Bitmap);
end;
end;
esenlite_yu 2008-04-18
  • 打赏
  • 举报
回复
主要是刚学,根本看不懂代码,我也不知道什么说?
esenlite_yu 2008-04-18
  • 打赏
  • 举报
回复
有谁帮忙运行下 把错误修改了 "万分"感谢
esenlite_yu 2008-04-18
  • 打赏
  • 举报
回复
刚学一周多时间 真没办法 有点痛苦了
7年 2008-04-18
  • 打赏
  • 举报
回复
我建议你设断点,F7一步步来。
Pascal Error] Unit10.pas(39): E2003 Undeclared identifier: 'FormDestroy'
[Pascal Error] Unit10.pas(39): E2029 ';' expected but '(' found
[Pascal Error] Unit10.pas(41): E2003 Undeclared identifier: 'TreeView1'
这中错误都能出现?I服了YOU!
skylkj 2008-04-18
  • 打赏
  • 举报
回复
楼主先找本delphi入门的书看看吧.

这种错误真的很难和你解释了.....
kaikai_kk 2008-04-17
  • 打赏
  • 举报
回复
不怕他笨,就怕他懒...
米的向日葵 2008-04-17
  • 打赏
  • 举报
回复
其实六楼的已经写的很明白了,不要等着别人把现成的送给你。
esenlite_yu 2008-04-17
  • 打赏
  • 举报
回复
高手们 进来啊!分绝对给能够解决问题的朋友,但我不希望你们为了分才帮忙.谢谢!
esenlite_yu 2008-04-17
  • 打赏
  • 举报
回复
6楼给的 内容我都看了 但还是弄不明白,请大家指点下迷经!
genispan 2008-04-16
  • 打赏
  • 举报
回复
6楼的链接去看下 Delphi实现Tree View 透明背景图 应该可以满足你的要求了吧?
阿三 2008-04-16
  • 打赏
  • 举报
回复
看看6楼给的链接,试一下
esenlite_yu 2008-04-16
  • 打赏
  • 举报
回复
高手们都跑去哪里了?痛苦啊
esenlite_yu 2008-04-16
  • 打赏
  • 举报
回复
哪位高手可以帮忙实现?非常感谢
esenlite_yu 2008-04-16
  • 打赏
  • 举报
回复
对 思路就是楼上说的
skylkj 2008-04-16
  • 打赏
  • 举报
回复
大概是想把treeview和listview重叠放置,然后能透过treeview看到listview的内容吧

我的思路是,把treeview的Canvas拷贝给listview作为listview的背景.然后listview用textout显示内容,用lineto画线

不过实现起来应该很麻烦......
esenlite_yu 2008-04-16
  • 打赏
  • 举报
回复
谢谢brightyang
本人是临时用D的 能不能给我个现成的代码?非常感谢各位的支持和帮助
hongqi162 2008-04-16
  • 打赏
  • 举报
回复
你看看delphi自带的demo

C:\Program Files\Borland\Delphi7\Demos\CustomDraw
esenlite_yu 2008-04-16
  • 打赏
  • 举报
回复
背景的颜色去掉,只剩下树的连接线和节点文字.
放到FORM上,背景色就为FORM的颜色,树放到LISTVIEW上,不会盖住列表的线,
谢谢1
加载更多回复(6)

5,388

社区成员

发帖
与我相关
我的任务
社区描述
Delphi 开发及应用
社区管理员
  • VCL组件开发及应用社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧