Function SelectMenu(winname,item,subitem:string):boolean;
// winname - имя окна, item - имя пункта меню, subitem - имя подпункта
var winhandle,menuhandle,submenuhandle,i,j,res:integer;
itemname,subitemname:pchar;
begin
res:=-1;
winhandle:=FindWindow(nil,pchar(winname));
menuhandle:=getmenu(winhandle);
getmem(itemname,255);
getmem(subitemname,255);
for i:=0 to getmenuitemcount(menuhandle)-1 do
begin
getmenustring(menuhandle,i,itemname,255,MF_BYPOSITION);
if string(itemname)=item then begin
submenuhandle:=getsubmenu(menuhandle,i);
for j:=0 to getmenuitemcount(submenuhandle)-1 do
begin
getmenustring(submenuhandle,j,subitemname,255,MF_BYPOSITION);
if string(subitemname)=subitem then
res:=SendMessage(winhandle,WM_COMMAND,makelong(getmenuitemid(submenuhandle,j),0
),0);
end;
end;
end;
freemem(itemname);
freemem(subitemname);
if res=0 then result:=true else result:=false;
end;
|