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;