Question Details

No question body available.

Tags

winapi modality trackpopupmenu

Answers (1)

Accepted Answer Available
Accepted Answer
October 14, 2025 Score: 0 Rep: 50,042 Quality: High Completeness: 30%

Answering my own question:

Q: Is there a situation where you would not want the launch of a popup menu to cancel a stateful mode?

Yes. Some CAD programs let you bring up context menus while a performing modal operation without canceling that operation. For example, KiCad will lets the user change the grid resolution from a pop-up menu while dragging a component, wire, or trace. In this case, the modal states are nested. (I believe this means KiCad doesn't actually capture the mouse for these kinds of drag operations. The modality must be handled by carefully managing the state while running in its usual message loop.)

If TrackPopupMenu had automatically sent a WMCANCELMODE first, it would break the interaction. Sure, the program could work around it, but it makes more sense to leave it up to each application than force to force even a minority of applications into awkward workarounds.

In my program, however, no such nesting of modal states is necessary, so sending WMCANCELMODE to my own window whenever it's about to call TrackPopUpMenu worked without any undesired side effects.