简体   繁体   中英

C++ MFC change menu focus

I have a problem with a view/window that has a tree view on the left then a list style view on the right which displays "stuff" corresponding to the tree node selected on the right. Very similar to how windows explorer looks and works. The "stuff" can be displayed as a list, large icons or small icons or information.

The problem I have is that if one of the tree nodes selected is a 'placeholder' node, then 'select all' is run from the Edit menu, then after that the 'delete' option in the Edit menu is greyed out even though all the items in the RHS view are marked as selected and can in fact be deleted safely. This can be fixed by selecting away from the tree node to another node, selecting back to the same tree node, then selecting a different view: List, large icon, small icon, or info view than was originally selected.

Trace statements show me that in the second working, scenario, the items in the right hand view are being passed to a "can I delete" function whereas when things dont work it is the name of the tree view node that gets passed to the "can I delete" function. when the "can I delete" function returns true, the 'delete' option is enabled in the Edit menu and when false it isnt.

Is there a way I can force the 'focus' for want of a better word to the right hand list, info, etc view when 'select all' is selected from the Edit menu to make this work ok all the time?

I think the problem is that the Edit menu is different (context sensitive) depending on which view ('it' thinks) is active and somewhere wires are crossed and the Edit menu is being displayed for the tree view when it should be for the RHS node list view. It is figuring out how to fix this i am struggling with.

Thanks

You have problems with the MFC command routing.

Check where you placed the handler for the commands.

A command handler is searched in this sequence:

  1. Active view
  2. Document
  3. Document template
  4. Frame window
  5. Application.

I suppose you have handler in the views, and the focus (active view ) changes

You can change the command routing iE in the frame and ask all views attached to the document to handle a command... you have to overwrite OnCmdMsg for this.

See more details here

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM