我已经做出这样的效果了。代码比较长:
type
PMenuTree=^TMenuTree;
TMenuTree=Record
Handle:HWND;//对应的窗体的句柄,可以唯一标认识
Caption :string[255];//标题
//……
end;
//创建子窗体函数
procedure TMainForm.CreateMDIChild(name:string);
var
Child: TMDIChild;
Ldata: PMenuTree;
begin
{ create a new MDI child window }
Child := TMDIChild.Create(Application);
Child.Caption := name;
Child.PMap.HChildForm:=Child.Handle;
Child.PMap.HMap:=Child.Map1.hWnd;
Ldata :=nil;
try
getmem(Ldata,sizeof(TMenuTree));
except
Application.MessageBox('申请内存失败','错误',MB_OKCANCEL+MB_ICONEXCLAMATION);
Child.Close;
Exit;
end;
Ldata^.handle :=Child.handle;
Ldata^.caption :=Child.caption;
MainForm.CreateMenuTree(tvSysMenu,Ldata);
end;
//创建菜单树
procedure TMainForm.CreateMenuTree(TV:TTreeView;lData
MenuTree);
var
TreeNode: TTreeNode;
begin
TreeNode :=TV.Items.AddchildObject(TV.TopItem,lData.caption,lData);
TreeNode.SelectedIndex :=1;
TreeNode.StateIndex :=0;
TreeNode.Selected :=true;
TreeNode.Focused :=true;
end;
//树TreeView的Onchange事件:
procedure TMainForm.tvSysMenuChange(Sender: TObject;
Node: TTreeNode);
var
PNode
MenuTree;
child :TMDIChild;
begin
if (tvSysMenu.Selected.Level=0) or ( tvSysMenu.Selected=nil) then
exit;
if tvSysMenu.Selected.Level=1 then
begin
//移到最前面
PNode:=PMenuTree(tvSysMenu.Selected.Data);
if IsIconic(PNode^.handle) then
ShowWindow(PNode^.handle,SW_RESTORE);
BringWindowToTop(PNode^.handle);
end;
if tvSysMenu.Selected.Level=2 then
begin
//移到最前面
PNode:=PMenuTree(tvSysMenu.Selected.Parent.Data);
if IsIconic(PNode^.handle) then
ShowWindow(PNode^.handle,SW_RESTORE);
BringWindowToTop(PNode^.handle);
child :=MainForm.ActiveMDIChild;
if child<>nil then
try
child.pSelectedLayer:=child.Map1.Layers.Item[tvSysMenu.Selected.text];
except
end;
end;
end;
//子窗体的OnActive事件:
procedure TMDIChild.FormActivate(Sender: TObject);
var
i:integer;
node:Ttreenode;
PCurrentNode
MenuTree;
begin
//菜单
for i :=0 to MainForm.tvSysMenu.Items.Count -1do
begin
node :=MainForm.tvSysMenu.Items
;
if node.Level=0 then
continue;
if node.Level=1 then
node:=node;
if node.Level=2 then
node:=node.Parent;
PCurrentNode:=PMenuTree(node.Data);
if PCurrentNode^.Handle=self.Handle then
begin
node.Selected :=true;
node.Focused :=true;
break;
end;
end;
//略图
MainForm.Delineation.Layers.RemoveAll;
if map1.Layers.count>0 then
begin
for i:=1 to map1.Layers.Countdo
begin
MainForm.Delineation.Layers.Add(map1.Layers.Item.FileSpec,EmptyParam);
end;
MainForm.RectLayer:=MainForm.Delineation.layers.CreateLayer('RectLayer', EmptyParam,EmptyParam,EmptyParam, EmptyParam);//Temp Layer
MainForm.Delineation.Zoom:=map1.zoom;
MainForm.Delineation.Refresh;
MainForm.Delineation.Hint:=Caption+'[略图]';
end;
end;