中国开发网: 论坛: 程序员情感CBD: 贴子 668111
haitao
对于treeview的收缩、展开子节点的加减号小按钮图,关联虚线,好像delphi没有提供缺省的实现代码?
treeview是直接使用win的com组件的,所以delphi没有它的画一部分(加减号小按钮图、关联虚线)的实现代码?

要自己画,就要完全自己画?(加减号小按钮图、关联虚线本来是可以利用原来的)
如果修改DefaultDraw为false,就要完全自己画
如果修改DefaultDraw为true,加减号小按钮图、关联虚线右边的自己画的内容又会被系统的所画所覆盖——如果系统的先画,自己画的内容后覆盖,就好了

真难为borland把win的控件能包装得这么好用。。。。。。。。。

是否显示加减号小按钮图、关联虚线,都是创建时就设参数搞定的,具体画还是win来画的
procedure TCustomTreeView.CreateParams(var Params: TCreateParams);
const
BorderStyles: array[TBorderStyle] of DWORD = (0, WS_BORDER);
LineStyles: array[Boolean] of DWORD = (0, TVS_HASLINES);
RootStyles: array[Boolean] of DWORD = (0, TVS_LINESATROOT);
ButtonStyles: array[Boolean] of DWORD = (0, TVS_HASBUTTONS);
EditStyles: array[Boolean] of DWORD = (TVS_EDITLABELS, 0);
HideSelections: array[Boolean] of DWORD = (TVS_SHOWSELALWAYS, 0);
DragStyles: array[TDragMode] of DWORD = (TVS_DISABLEDRAGDROP, 0);
RTLStyles: array[Boolean] of DWORD = (0, TVS_RTLREADING);
ToolTipStyles: array[Boolean] of DWORD = (TVS_NOTOOLTIPS, 0);
AutoExpandStyles: array[Boolean] of DWORD = (0, TVS_SINGLEEXPAND);
HotTrackStyles: array[Boolean] of DWORD = (0, TVS_TRACKSELECT);
RowSelectStyles: array[Boolean] of DWORD = (0, TVS_FULLROWSELECT);
begin
InitCommonControl(ICC_TREEVIEW_CLASSES);
inherited CreateParams(Params);
CreateSubClass(Params, WC_TREEVIEW);
with Params do
begin
Style := Style or LineStyles[FShowLines] or BorderStyles[FBorderStyle] or
RootStyles[FShowRoot] or ButtonStyles[FShowButtons] or
EditStyles[FReadOnly] or HideSelections[FHideSelection] or
DragStyles[DragMode] or RTLStyles[UseRightToLeftReading] or
ToolTipStyles[FToolTips] or AutoExpandStyles[FAutoExpand] or
HotTrackStyles[FHotTrack] or RowSelectStyles[FRowSelect];
if Ctl3D and NewStyleControls and (FBorderStyle = bsSingle) then
begin
Style := Style and not WS_BORDER;
ExStyle := Params.ExStyle or WS_EX_CLIENTEDGE;
end;
WindowClass.style := WindowClass.style and not (CS_HREDRAW or CS_VREDRAW);
end;
end;

虽然事后也可以改设置,但是通过发消息让win自己改的:
procedure TCustomTreeView.SetLineStyle(Value: Boolean);
begin
if ShowLines <> Value then
begin
FShowLines := Value;
SetComCtlStyle(Self, TVS_HASLINES, Value);
end;
end;

哦,不是发消息,而是设置窗口类的附加属性
procedure SetComCtlStyle(Ctl: TWinControl; Value: Integer; UseStyle: Boolean);
var
Style: Integer;
begin
if Ctl.HandleAllocated then
begin
Style := GetWindowLong(Ctl.Handle, GWL_STYLE);
if not UseStyle then Style := Style and not Value
else Style := Style or Value;
SetWindowLong(Ctl.Handle, GWL_STYLE, Style);
end;
end;
我的blog:http://szhaitao.blog.hexun.com & http://www.hoolee.com/user/haitao
--以上均为泛泛之谈--
不尽牛人滚滚来,无边硬伤纷纷现 人在江湖(出来的),哪能不挨刀(总归是要的)
网络对话,歧义纷生;你以为明白了对方的话,其实呢?

您所在的IP暂时不能使用低版本的QQ,请到:http://im.qq.com/下载安装最新版的QQ,感谢您对QQ的支持和使用

相关信息:


欢迎光临本社区,您还没有登录,不能发贴子。请在 这里登录