private IntPtr MatchKeyToMenuItem(int startItem, char key, MenuItemKeyComparer comparer) { int low = -1; bool flag = false; for (int i = 0; (i < this.items.Length) && !flag; i++) { int index = (startItem + i) % this.items.Length; MenuItem mi = this.items[index]; if ((mi != null) && comparer(mi, key)) { if (low < 0) { low = mi.MenuIndex; } else { flag = true; } } } if (low < 0) { return(IntPtr.Zero); } int high = flag ? 3 : 2; return((IntPtr)System.Windows.Forms.NativeMethods.Util.MAKELONG(low, high)); }
/// <include file='doc\Menu.uex' path='docs/doc[@for="Menu.MatchKeyToMenuItem"]/*' /> /// <devdoc> /// Walks the menu item collection, using a caller-supplied delegate to find one /// with a matching access key. Walk starts at specified item index and performs one /// full pass of the entire collection, looping back to the top if necessary. /// /// Return value is intended for return from WM_MENUCHAR message. It includes both /// index of matching item, and action for OS to take (execute or select). Zero is /// used to indicate that no match was found (OS should ignore key and beep). /// </devdoc> /// <internalonly/> private IntPtr MatchKeyToMenuItem(int startItem, char key, MenuItemKeyComparer comparer) { int firstMatch = -1; bool multipleMatches = false; for (int i = 0; i < items.Length && !multipleMatches; ++i) { int itemIndex = (startItem + i) % items.Length; MenuItem mi = items[itemIndex]; if (mi != null && comparer(mi, key)) { if (firstMatch < 0) { // Using Index doesnt respect hidden items. firstMatch = mi.MenuIndex; } else { multipleMatches = true; } } } if (firstMatch < 0) { return(IntPtr.Zero); } int action = multipleMatches ? NativeMethods.MNC_SELECT : NativeMethods.MNC_EXECUTE; return((IntPtr)NativeMethods.Util.MAKELONG(firstMatch, action)); }
/// <include file='doc\Menu.uex' path='docs/doc[@for="Menu.MatchKeyToMenuItem"]/*' /> /// <devdoc> /// Walks the menu item collection, using a caller-supplied delegate to find one /// with a matching access key. Walk starts at specified item index and performs one /// full pass of the entire collection, looping back to the top if necessary. /// /// Return value is intended for return from WM_MENUCHAR message. It includes both /// index of matching item, and action for OS to take (execute or select). Zero is /// used to indicate that no match was found (OS should ignore key and beep). /// </devdoc> /// <internalonly/> private IntPtr MatchKeyToMenuItem(int startItem, char key, MenuItemKeyComparer comparer) { int firstMatch = -1; bool multipleMatches = false; for (int i = 0; i < items.Length && !multipleMatches; ++i) { int itemIndex = (startItem + i) % items.Length; MenuItem mi = items[itemIndex]; if (mi != null && comparer(mi, key)) { if (firstMatch < 0){ // VSWhidbey 218021 using Index doesnt respect hidden items. firstMatch = mi.MenuIndex; } else { multipleMatches = true; } } } if (firstMatch < 0) return IntPtr.Zero; int action = multipleMatches ? NativeMethods.MNC_SELECT : NativeMethods.MNC_EXECUTE; return (IntPtr) NativeMethods.Util.MAKELONG(firstMatch, action); }