lw549的专栏

革命尚未失败,同志仍需努力

遍历菜单项

//遍历任何窗体的MenuItem
//用了两个多小时hitwall.gif
//略做修改,就可以实现其他功能,GetMenuItemInfo提供的信息足够用了

procedure ExplorerMenuItem(MenuHandle: THandle);
var
  MenuIndex: Integer;
  MenuCaptionArray: array[1..255]  of Char;
  MenuCaptionString: String;
  ItemInfo: TMenuItemInfo;
  Buffer: array[0..20] of Char;
begin
  for MenuIndex := 0 to GetMenuItemCount(MenuHandle) - 1 do begin
    //Something todo. Here we get the caption
    GetMenuString(MenuHandle, MenuIndex, @MenuCaptionArray, 255, MF_BYPOSITION);
    MenuCaptionString := MenuCaptionArray;
    SetLength(MenuCaptionString,StrLen(PChar(MenuCaptionString)));
    ShowMessage('Menu Caption: ' + MenuCaptionString);
    //Get caption ends here.
     
    ItemInfo.cbSize := SizeOf(TMenuItemInfo);
    ItemInfo.fMask := MIIM_SUBMENU;
    ItemInfo.dwTypeData := Buffer;
    ItemInfo.cch := SizeOf(Buffer);
    GetMenuItemInfo(MenuHandle, MenuIndex, True, ItemInfo);
    //submenu, calls itself
    if ItemInfo.hSubMenu <> 0 then begin
      ExplorerMenuItem(ItemInfo.hSubMenu);
    end;
  end;
end;
阅读更多
想对作者说点什么? 我来说一句

没有更多推荐了,返回首页

加入CSDN,享受更精准的内容推荐,与500万程序员共同成长!
关闭
关闭