看HELPT中MenuItem的Items及COUNT属性
解决方案 »
- 求第三方控件
- ADO中如何调用存储过程的输出参数
- Delphi2007中Toolbar与MainMenu组合后当弹出菜单后Toolbar上的ToolButton没有了3D效果(就是有那种凹陷的效果)
- 关于edit的焦点问题,急,在线等!
- 如何通过程序实现网卡的启用和禁止功能?
- delphi的udp控件问题
- 如果这样的简单问题都不能解决那么delphi究竟好在哪里啊?
- pascal中有类似c语言中的argc,argv的命令行参数传递吗?
- 如何让table的onposterror事件发生时只显示我写的错误信息?
- 如何打开dat为扩展名的数据库文件?
- 数据库问题
- 请教-关于在缓存更新情况下不能正确更新主从表的问题
Use Items to access information about the elements in the menuTMenuItem.Items
Use Items to access to a subitem by its position in the list of subitems
Dim hMen As Long
Dim lMainCount As Long
Dim sToolName As String
Dim sToolID As String
Dim i As Integer
' This API function returns the handle of the window's menu
hMen = GetMenu(hWnd)
' This API function returns the number of menu items in the main-level menu
lMainCount = GetMenuItemCount(hMen)
' Exit if there are no menus
' Do this for each menu item in the main-level menu
For i = 0 To lMainCount - 1
' Sets the Tool's Name, which is determined by using the text string in the original menu
' (returned by the GetMenuName function), as well as removing the item's shortcut key text
sToolName = RemoveShortcut(GetMenuName(hMen, i))
' Sets the Tool's ID, which is determined by using its Name, as well as cleaning out some characters
sToolID = "id_" & CleanMenuID(sToolName)
' Adds the new main-level Menu Tool, which is used to store sub Tools
'修改此处增加到TreeView
'TreeView1.Nodes.Add ' Pass execution to the routine responsible for creating sub-menu items
Call CreateMenuSubs(sToolID, hMen, i)
Next i ' Pass execution to the routine that adds menu separators, but only if there are separators to add
If iSepCount > 0 Then Call AddSepsEnd Sub
Private Sub CreateMenuSubs(ByVal sParent As String, ByVal hParentMenu As Long, ByVal lParentPos As Long) ' This subroutine accepts the name, handle, and menu position of a main-level menu item and
' creates its sub-menu items. It is called recursively, in order to obtain any sub-menu items
' of the menu. If so, this recursive process creates cascading menus. Dim hSubMenu As Long
Dim lSubCount As Long
Dim sSubName As String
Dim sSubID As String
Dim siSepInfo As SepInfo
Dim i As Integer ' This API function returns the handle of a menu item, given its parent's position
hSubMenu = GetSubMenu(hParentMenu, lParentPos)
' This API function returns the number of menu items in a menu
lSubCount = GetMenuItemCount(hSubMenu)
' Exit if there are no menu items or if sParent is a separator
If lSubCount = 0 Or sParent = "separator" Then Exit Sub ' Do this for each menu item
For i = 0 To lSubCount - 1
' Sets the Tool's Name, which is determined by using the text string in the original sub-menu
' (returned by the GetMenuName function), as well as removing the item's shortcut key text
sSubName = RemoveShortcut(GetMenuName(hSubMenu, i))
' Sets the Tool's ID, which is determined by using its parent's ID, the Tool's Name,
' as well as cleaning out some characters
sSubID = sParent & CleanMenuID(sSubName)
' If the Tool doesn't have a name, it is probably a separator, so handle it accordingly
If sSubName = "" Then
sSubName = "separator"
sSubID = "separator"
'修改此处增加到TreeView
End If
Call CreateMenuSubs(sSubID, hSubMenu, i)
Next iEnd Sub
procedure TForm1.AddTree(ANode : TTreeNode;AItem : TMenuItem);
var
i : Integer;
Node : TTreeNode;
begin
for i:= 0 to AItem.Count-1 do
begin
Node := Tree.Items.AddChild(ANode,AItem.Items[i].Caption);
AddTree(Node,AItem.Items[i]);
end;
end;procedure TForm1.Button1Click(Sender: TObject);
var
i : Integer;
Item : TMenuItem;
Node : TTreeNode;
begin
for i := 0 to Main.Items.Count-1 do
begin
Node := Tree.Items.AddChild(nil,Main.Items[i].Caption);
Item := Main.Items[i];
AddTree(Node,Item);
end;
end;
值,然后用菜单的Items[i]属性检验其对应的Tag值即可。例如:
A B C
a1 b1 c1
a2 b2 c2
可分别赋值 A.Tag:=10 B.Tag:=20 C.Tag:=30
a1.Tag:=11 b1.Tag:=21 c1.Tag:=31
a2.Tag:=12 b2.Tag:=22 c2.Tag:=32
这样的话,您能明白后面该怎么做了吧!
[email protected]
var
i: Integer;
begin
result:=nil;
for i := 0 to myList.Count - 1 do
begin
if prm = Pobj(myList[i])^.namenode then
begin
result:=Pobj(myList[i])^.snode;
break;
end;
end;
end;
procedure setnode(mylist:tlist;prm:string;snode:ttreenode);
var
i: Integer;
pp:pobj;begin for i := 0 to myList.Count - 1 do
begin
if prm = Pobj(myList[i])^.namenode then
break
end;
new(pp);
pp^.namenode:=prm;
pp^.snode:=snode;
mylist.add(pp);end;
function getcod(prm:string):string;
var fnd:integer;
begin
fnd:=pos(';',prm);
if fnd>0 then
result:=copy(prm,1,fnd-1)
else
result:=prmend;
function getname(prm:string):string;
var fnd:integer;
begin
fnd:=pos(';',prm);
if fnd>0 then
result:=copy(prm,fnd+1,length(prm)-fnd)
else
result:=prmend;procedure TForm1.FormCreate(Sender: TObject);
var node:ttreenode;
i:integer;
menulist:tstringlist;
old,new:string;
begin
form1.Show;
list:=tlist.create;
menulist:=tstringlist.create;
menulist.LoadFromFile('menu.txt');
old:='';
setnode(list,old,nil);
for i:=0 to menulist.count -1 do
begin
if menulist.strings[i]='' then
Continue;
new:=getcod(trim(menulist.strings[i]));
if copy(new,1,length(new)-1)=copy(new,1,length(old)-1) then
node:=treeview1.Items.add(getnode(list,old),getname(trim(menulist.strings[i])))
else
node:=treeview1.Items.addchild(getnode(list,copy(new,1,length(new)-1)),getname(trim(menulist.strings[i]))); old:=getcod(trim(menulist.strings[i]));
setnode(list,old,node);
end;
treeview1.refresh;
if List <> nil then
begin
for i := 0 to List.Count - 1 do
begin
Pobj(List[i])^.snode := nil;
Dispose(Pobj(List[i]));
end;
end; list.free;
end;
procedure TForm1.TreeView1DblClick(Sender: TObject);
begin
if not TreeView1.Selected.HasChildren then
begin
form2.show;
form2.richedit1.lines.loadfromfile('help.txt');
end;
end;end.