This question has been asked before but the non-answer is "Well, its up to each application to support different options". Still, when you right-click a selection in notepad, a browser, whatever Something is building a context menu. How does an app do that? Why can't I add to it? How to you add to the hightlight context menu? No answer is better than a non-answer.
closed as not a real question by studiohack♦ Aug 20 '12 at 19:29
It's difficult to tell what is being asked here. This question is ambiguous, vague, incomplete, overly broad, or rhetorical and cannot be reasonably answered in its current form. For help clarifying this question so that it can be reopened, visit the help center.If this question can be reworded to fit the rules in the help center, please edit the question.
Short answer: If you added a new menu item, the program wouldn't know what to do when the item was clicked. You actually have to change the program's code to make new menu items do something. This is why "It's up to each application" is a valid answer.
Windows, like most other operating systems, provides a set of functions for building GUI programs – some are part of the system ("create a window"), others are mostly for convenience ("draw a button that can be clicked").
Most programs display their menus (normal and context) by using these functions – they basically give Windows a list of items and ask for it to be displayed on screen in the form of a menu, and to inform the program about what you picked.
Windows doesn't particularly care where the list of items comes from. Some menus are generated by the program itself (such as the "Recent files" list); you cannot change these without actually rewriting the part of the program that creates the recent file list. Other menus, such as "File" or "Edit" or "Help" menu in Notepad, are created from a "resource" stored within the
But if you used such a tool to add new menu items, they wouldn't work, because the program wouldn't know what to do. There is no magic associated with each menu item, only a single number, a "command ID". For example, "Copy", being common in many programs, has command ID 12 ("IDM_COPY") assigned, and something specific to a single program (such as "New Game") could have 1234 or 2468 or something else. When you open a context menu and click on "Copy", Windows tells Notepad only that "command ID 12 was chosen", and it's up to Notepad to actually put selected text into clipboard whenever that happens.
Side note: The above is a bit simplified. The context menu in Notepad is actually implemented by the "editable text" control, which is part of the aforementioned utility functions provided by Windows. The main menu, however, is entirely part of Notepad.
Side note: Some programs, usually those that can be skinned or themed, actually draw various controls by themselves – which isn't particularly hard, since a pop-up menu is just a window without a titlebar. While I haven't seen the code of such programs myself, I don't think the details would change much.