在过程创建控件创建完后为什么不能用它的句柄来操纵它?(100分)

  • 主题发起人 主题发起人 guest8188
  • 开始时间 开始时间
G

guest8188

Unregistered / Unconfirmed
GUEST, unregistred user!
我在一个过程中动态的在窗口中创建一个控件,设置它的属性可以,但是如果要用到
Handle句柄来操作的话所做操作就会无效。
比如说我在过程中创建一个TreeView,完成后设置属性OK。但我想取消横向滚动条就
代码:

ShowScrollBar(TmpTreeView.Handle, SB_HORZ, False);
这个时候操作无效,我用过其它的用Handle的函数,都是一样的,无效!
请问怎么回事,,程序如下

procedure TFormMyFriendList.AddGroup(GroupCaption: String);
var
TreeTmp :TTreeView;
begin
{ 创建树 }
TreeTmp := TTreeView.Create(Nil);

TreeTmp.Parent := Self;
TreeTmp.Align := alClient;
TreeTmp.BorderStyle := bsNone;
TreeTmp.Ctl3D := False;
TreeTmp.Font.Name := 'Arial';
TreeTmp.Font.Size := 9;
TreeTmp.Images := ImageList1;
TreeTmp.Name := 'Group_'+ IntToStr(OutlookBar.OutlookItems.Count - 1);
TreeTmp.RightClickSelect := True;
TreeTmp.BorderColor := clWhite;
TreeTmp.ShowHint := False;
TreeTmp.ShowLines := False;
TreeTmp.ShowRoot := False;
TreeTmp.ReadOnly := True;
TreeTmp.OnClick := suiTreeView1Click;
TreeTmp.OnMouseDown := suiTreeView1MouseDown;
上面操作都可以,
ShowScrollBar(TreeTmp.Handle, SB_HORZ, False); //取消横向滚动条
这句就不行了

TreeView_SetItemHeight(TreeTmp.Handle,130); //设置项目高度
这句也不能。
反正只在有Handle的就不行。

end;
 
procedure tform1.AddGroup(GroupCaption: String);
var
TreeTmp :TTreeView;
begin
{ ?建? }
TreeTmp := TTreeView.Create(Nil);

TreeTmp.Parent := Self;
TreeTmp.Width := 20;
TreeTmp.Left := random(form1.Width);
TreeTmp.Align := alNone;
TreeTmp.BorderStyle := bsNone;
TreeTmp.Ctl3D := False;
TreeTmp.Font.Name := 'Arial';
TreeTmp.Font.Size := 9;
// TreeTmp.Images := ImageList1;
// TreeTmp.Name := 'Group_'+ IntToStr(OutlookBar.OutlookItems.Count - 1);
TreeTmp.RightClickSelect := True;
// TreeTmp.BorderColor := clWhite;
TreeTmp.ShowHint := False;
TreeTmp.ShowLines := False;
TreeTmp.ShowRoot := False;
TreeTmp.ReadOnly := True;
// TreeTmp.OnClick := suiTreeView1Click;
// TreeTmp.OnMouseDown := suiTreeView1MouseDown;
//上面操作都可以,
TreeTmp.Items.Add(TreeTmp.Items.Add(nil, timetostr(now)), 'ok');
ShowScrollBar(TreeTmp.Handle, SB_HORZ, False); //取消?向????句就不行了

// TreeView_SetItemHeight(TreeTmp.Handle,130); //?置?目高度?句也不能。反正只在有Handle的就不行。

end;

// D7 + win2000 pro
可以不顯示scroll bar
 
Handle property (public) Provides access to the underlying Windows screen object for the control.

Description
The Handle property returns the window handle for the underlying Microsoft Windows screen object. Use the Handle property to bypass the VCL API and directly access the underlying window.

Do not refer to the Handle property during component creation or streaming. The underlying window does not exist until the first time the Handle property is referenced. When this occurs, the HandleNeeded method is called automatically.
 
把TreeTmp:= TTreeView.Create(Nil);改为
TreeTmp := TTreeView.Create(Self);
不能使用nil的
 
改成Self也不行啊。
 
ShowScrollBar(TmpTreeView.Handle, SB_HORZ, False); 可以的,D7+XPsp2
 
你看一下TTreeView的Create事件,它的继承。
constructor TCustomTreeView.Create(AOwner: TComponent);
begin
inherited Create(AOwner);
ControlStyle := ControlStyle - [csCaptureMouse] + [csDisplayDragImage, csReflector];
Width := 121;
Height := 97;
TabStop := True;
ParentColor := False;
FCanvas := TControlCanvas.Create;
TControlCanvas(FCanvas).Control := Self;
FTreeNodes := CreateNodes;
FBorderStyle := bsSingle;
FShowButtons := True;
FShowRoot := True;
FShowLines := True;
FHideSelection := True;
FDragImage := TDragImageList.CreateSize(32, 32);
FSaveIndent := -1;
FSelections := TList.Create;
FMultiSelect := False;
FMultiSelectStyle := [msControlSelect];
FChangeTimer := TTimer.Create(Self);
FChangeTimer.Enabled := False;
FChangeTimer.Interval := 0;
FChangeTimer.OnTimer := OnChangeTimer;
FCreateWndRestores := True;
FToolTips := True;
FEditInstance := MakeObjectInstance(EditWndProc);
FImageChangeLink := TChangeLink.Create;
FImageChangeLink.OnChange := ImageListChange;
FStateChangeLink := TChangeLink.Create;
FStateChangeLink.OnChange := ImageListChange;
end;

如果你的AOwner为nil是不能就不能继承一些Create(AOwner);

以下是我的可以执行的代码
var
TreeTmp :TTreeView;
begin
{ 创建树 }
TreeTmp := TTreeView.Create(TreeTmp);

TreeTmp.Parent := Self;
TreeTmp.Align := alClient;
TreeTmp.BorderStyle := bsNone;
TreeTmp.Ctl3D := False;
TreeTmp.Font.Name := 'Arial';
TreeTmp.Font.Size := 9;
//TreeTmp.Images := ImageList1;
//TreeTmp.Name := 'Group_'+ IntToStr(OutlookBar.OutlookItems.Count - 1);
TreeTmp.RightClickSelect := True;
//TreeTmp.BorderColor := clWhite;
TreeTmp.ShowHint := False;
TreeTmp.ShowLines := False;
TreeTmp.ShowRoot := False;
TreeTmp.ReadOnly := True;
//TreeTmp.OnClick := suiTreeView1Click;
//TreeTmp.OnMouseDown := suiTreeView1MouseDown;
ShowScrollBar(TreeTmp.Handle, SB_HORZ, False); //取消横向滚动条
//TreeView_SetItemHeight(TreeTmp.Handle,130); //设置项目高度

end;
 
procedure TFormMyFriendList.AddGroup(GroupCaption: String);
var
Panel_OutLook :TfcOutlookPage;
Btn_Image :TfcImageBtn;
TreeTmp :TsuiTreeView;
ScrollTmp :TsuiScrollBar;
i : integer;
begin
Panel_OutLook := OutlookBar.OutlookItems.Add;

Btn_Image := TfcImageBtn.Create(Panel_OutLook.Panel);
Btn_Image.Image.LoadFromFile(ExtractFilePath(Application.ExeName) +'img/好友分组.bmp');
Btn_Image.ImageDown.LoadFromFile(ExtractFilePath(Application.ExeName) +'img/好友分组.bmp');
Panel_OutLook.Button.Assign(Btn_Image);
Panel_OutLook.Button.Caption :=GroupCaption;


ScrollTmp := TsuiScrollBar.Create(Panel_OutLook.Panel);
ScrollTmp.UIStyle := FromThemeFile;
ScrollTmp.FileTheme := suiFileTheme1;
ScrollTmp.Parent := Panel_OutLook.Panel;
ScrollTmp.Name := 'GroupScroll_' + IntToStr(OutlookBar.OutlookItems.Count - 1);
ScrollTmp.Color := $00F9FFFE;

ScrollTmp.Orientation := suiVertical;

{ 创建树 }
TreeTmp := TsuiTreeView.Create(Self);

TreeTmp.Parent := Panel_OutLook.Panel;
TreeTmp.Align := alClient;
TreeTmp.BorderStyle := bsNone;
TreeTmp.Ctl3D := False;
TreeTmp.Font.Name := 'Arial';
TreeTmp.Font.Size := 9;
TreeTmp.Images := ImageList1;
TreeTmp.Name := 'Group_'+ IntToStr(OutlookBar.OutlookItems.Count - 1);
TreeTmp.RightClickSelect := True;
TreeTmp.BorderColor := clWhite;
TreeTmp.ShowHint := False;
TreeTmp.ShowLines := False;
TreeTmp.ShowRoot := False;
TreeTmp.ReadOnly := True;
TreeTmp.OnClick := suiTreeView1Click;
TreeTmp.OnMouseDown := suiTreeView1MouseDown;
TreeTmp.VScrollBar := ScrollTmp;

for i := 0 to 50 do
begin
TreeTmp.Items.Add(Nil,IntToStr(i)+'用户');
end;


ShowScrollBar(TreeTmp.Handle, SB_HORZ, False); //取消横向滚动条

TreeView_SetItemHeight(TreeTmp.Handle,50); //设置项目高度
end;
以上是我的全部代码。
Panel_OutLook :TfcOutlookPage;
Btn_Image :TfcImageBtn;
TreeTmp :TsuiTreeView;
ScrollTmp :TsuiScrollBar;
上面全是三方控件!如果用过应该看得懂上面的例子。请大家留意
 
后退
顶部