delphi+mapinfo(ole)的小问题!(50分)

  • 主题发起人 青山侠客
  • 开始时间

青山侠客

Unregistered / Unconfirmed
GUEST, unregistred user!
我在用delphi+mapinfo(ole)编程时遇到以下问题:
我知道用
sw:string;
map:variant;
map:=createoleobject(mapinfo.application);
str(panel1.handle,sw);
map.do('set nextdo
ucument sw style 1');
语句可以将地图显示到panel1面板中,
但是如何在主窗口中创建子窗口,然后将地图显示到子窗口中呢?效果跟mapinfo里的new 或
open命令一样!
请给段源代码!不胜感谢!
 
www.mapinfo.com.cn 中的论坛很多类似鹰眼的代码,不过多是mapx的
 
我已经做出这样的效果了。代码比较长:
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:pMenuTree);
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:pMenuTree;
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:pMenuTree;
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;


 

Similar threads

S
回复
0
查看
3K
SUNSTONE的Delphi笔记
S
S
回复
0
查看
2K
SUNSTONE的Delphi笔记
S
D
回复
0
查看
2K
DelphiTeacher的专栏
D
顶部