开发者

MFC: Best place to handle context menu message?

Using C++ with MFC. I'm using a grid control which derives from CWnd (specifically the MFC Grid control on codeproject). I want to display a context menu when the user right 开发者_如何学运维clicks on a cell. My thinking is to handle the ON_WM_CONTEXTMENU() message.

However, where is the best place to handle this, in a OnContextMenu in my (derived) grid control class or in the OnContextMenu in the dialog box class that holds the grid control? Is there a convention in MFC?


If there is a convention, I haven't noticed.

I would choose based on who has the information required to build the menu, and who will be processing the commands resulting from the menu selection.


From a usability point of view I have to say that context menu's only contain things that are in fact mere shortcuts to other UI elements. I give an example: In MS Word you have a context menu "copy" in case you right click on selected text. The "copy" menu entry is in fact just a shortcut to the main menu's Edit -> Copy. So from a usablity point of view your application requires a menu (or a button) or whatever which does the exact same thing.

Now, sine handling the main menu cannot be done in the grid itself, why should the contect menu be handled in the grid? To me that seems inconsistent.

Handling it in the dialog rather than in the control itself seems a lot more natural to me. This is not related to the environment you are using. In c# I would do the exact same thing.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜