Y
yeaphi
Unregistered / Unconfirmed
GUEST, unregistred user!
我的程序主form里使用的菜单是toolbar + popupmenu,而不是使用mainmenu,我想用api函数来获得这个popupmenu,并且把菜单组成一棵树保存到数据库里,下面FindMenu就是我用来获取popupmenu的,为什么这里的SendNotifyMessage(self.Handle, WM_COMMAND, ChildId, 0)模拟点击某个按钮不能成功呢?如果换成了mainmenu就可以了,我怀疑这和popupmenu有关,于是我用popupmenu.popup(0, 0)先弹出菜单,再sendmessage,可以依然无效,请朋友们帮我看看。<br>function TmainFrm.FindMenu(MenuHnd:integer):boolean;<br>var<br> MenuNum, MenuId, ChildHnd, ChildNum, ChildId : integer ;<br> i, j, ErrCode : integer;<br> MenuStr, ChildStr : String;<br> Res : boolean;<br> MenuInfo : MENUITEMINFO;<br> TypeData : Array [0..50] of char;<br> BtnHnd : HWND;<br> lpPoint:TPoint;<br>begin<br> MenuNum := GetMenuItemCount(MenuHnd);<br> for i:=0 to MenuNum-1 do<br> begin<br> MenuStr := StringOfChar(' ', 255);<br> ChildHnd := GetSubMenu(MenuHnd, i);<br> ChildNum := GetMenuItemCount(ChildHnd);<br> GetMenuString(MenuHnd, i, PChar(MenuStr), 255, MF_BYPOSITION);<br> Memo1.Lines.Add(MenuStr);<br> if ChildHnd <> 0 then<br> begin<br> for j:=0 to ChildNum-1 do<br> begin<br> ChildStr := StringOfChar(' ', 255);<br> GetMenuString(ChildHnd, j, PChar(ChildStr), 20, MF_BYPOSITION);<br> ChildId := GetMenuItemId(ChildHnd, j);<br> SendNotifyMessage(self.Handle, WM_COMMAND, ChildId, 0);<br> end;<br> end;<br> end;<br>end;