Restore legacy menu message parity#21
Open
Rick-Xu-WTG wants to merge 6 commits into
Open
Conversation
Restore WM_MENUSELECT and WM_EXITMENULOOP dispatch in Control, keep Form and Menu parity aligned, add regression coverage in the new unit test tree, and document the validation findings. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
b855d59 to
3d70e95
Compare
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
…py menus Tests prove the end-to-end message path: - WM_MENUSELECT -> Control.WmMenuSelect -> ContextMenu.ProcessMenuSelect -> MenuItem.PerformSelect -> Select event fires (Grid Colors pattern) - WM_INITMENUPOPUP -> MenuItem.Popup fires (Universal Copy pattern) - Idempotency: repeat hover on Grid Colors replaces items, no duplicates Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
The previous ProcessMenuSelect used managed MenuItems[index] to find the popup item, but hidden items (Visible = false) are skipped in the native menu. This caused a native-to-managed index mismatch: Windows reports the native index (which excludes hidden items), but the managed collection includes hidden items at earlier indices, so the wrong MenuItem was found. CargoWise's ZGrid context menu uses hidden items extensively (DeactivateMenuItem, ActivateMenuItem, CustomiseMenuItem, CopyToNewRow, etc.), which made every popup lookup return the wrong item. The fix replaces the index-based lookup with GetMenuItemFromNativeIndex(), which uses Win32 GetMenuItemID/GetSubMenu to navigate the actual native menu structure. This matches the approach used by the .NET Framework reference implementation (WinFormsLegacyControls) and is immune to index mismatches from hidden items. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
MenuItem.Selectbehavior is preserved for both command and popup items.Popuphandlers fire and dynamic menu items can be populated.LazyMenuPopulationRegressionTestsproving the full end-to-end message path for both the Grid Colors (Select-based) and Universal Copy (Popup-based) lazy-loading patterns.src/test/unit/System.Windows.Forms/System/Windows/Forms/Controls/Unsupported/ContextMenu/.Rationale
GridColourSchemeManagerandUniversalCopyManagerare not needed once this framework fix is in place.Validation
dotnet build src\test\unit\System.Windows.Forms\System.Windows.Forms.Tests.csproj --no-restore✅LazyMenuPopulationRegressionTestscommitted and covers: Grid Colors WM_MENUSELECT path, Universal Copy WM_INITMENUPOPUP path, idempotency (no duplicate items on repeat hover).ProcessMenuSelectinMenu,WmMenuSelectinControlandForm.C:\Users\Rick.Xu\OneDrive - WiseTech Global Pty Ltd\Desktop\wm-menu-select-root-fix-report.md.